Interface RealtimeChannel

Enables messages to be published and subscribed to. Also enables historic messages to be retrieved and provides access to the RealtimePresence object of a channel.

Hierarchy

Properties

annotations: RealtimeAnnotations
errorReason: ErrorInfo

An ErrorInfo object describing the last error which occurred on the channel, if any. This is null until an error occurs, for example a transition in channel state to failed or suspended. Guard against null despite the declared type.

An array of ResolvedChannelMode objects reflecting the modes the server granted on the most recent attach. The server grants only the modes the key or token capability permits, so this may be a subset of the modes requested via modes.

It is undefined before the channel attaches for the first time. When the server grants no modes, it is also undefined, not an empty array. Guard against undefined despite the declared type.

name: string

The channel name.

params: ChannelParams

Optional channel parameters that configure the behavior of the channel. After the channel attaches this reflects the parameters the server confirmed on the most recent attach.

It is undefined before the channel attaches for the first time, so guard against undefined despite the declared type.

presence: RealtimePresence

A RealtimePresence object.

push: PushChannel

A PushChannel object that manages device push notification subscriptions for this channel. Accessing this property requires the Push plugin to be registered via plugins. The default and modular builds do not bundle the Push plugin. If the plugin is absent, the getter throws an ErrorInfo rather than returning a PushChannel.

state: ChannelState

The current ChannelState of the channel.

Methods

  • Appends data to an existing message. The supplied data field is appended to the previous message's data, while all other fields (name, extras) replace the previous values if provided.

    The channel must be configured to allow message appends, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • message: Message

      A Message object containing a populated serial field and the data to append.

    • Optional operation: MessageOperation

      An optional MessageOperation object containing metadata about the append operation.

    • Optional options: PublishOptions

      Optional parameters to modify how the publish is made.

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const result = await channel.appendMessage({ ...message, data: ' more text' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#append-message

  • Marks a message as deleted by publishing an update with an action of MESSAGE_DELETE. This does not remove the message from the server, and the full message history remains accessible.

    Uses patch semantics: non-null name, data, and extras fields in the provided message replace the corresponding fields in the existing message, while null fields are left unchanged. A deleted message keeps its previous data unless the delete explicitly sets data to an empty value.

    The channel must be configured to allow message deletes, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const result = await channel.deleteMessage(message);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#delete-message

  • Detach from this channel. Any resulting channel state change is emitted to listeners registered with on() or once().

    Detaching stops the server sending this channel's messages and any other channel traffic to the client. Locally registered listeners remain registered.

    Once all clients globally have detached from the channel, the channel is released in the Ably service within two minutes.

    Detaching from a channel in the suspended or detached state resolves without further action. Calling detach() on a channel in the detaching state does not start a second detach, and the returned promise resolves once the channel transitions to the detached state. Detaching from a channel in the failed state rejects with an ErrorInfo. Release the channel with release() and get it again with get() to start afresh.

    Returns Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

  • Retrieves the latest version of a specific message by its serial identifier.

    The channel must be configured to allow message updates, enabled by a rule.

    The supplied serial or Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • serialOrMessage: string | Message

      Either the serial identifier string of the message to retrieve, or a Message object containing a populated serial field.

    Returns Promise<Message>

    A promise which, upon success, will be fulfilled with a Message object representing the latest version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const message = await channel.getMessage(serial);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#get-message

  • Retrieves all historical versions of a specific message, ordered by version. This includes the original message and all subsequent update, delete, or append operations.

    The supplied serial or Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Message versions exist only when the channel is configured to allow updating, deleting, or appending messages, enabled by a rule.

    Parameters

    • serialOrMessage: string | Message

      Either the serial identifier string of the message whose versions are to be retrieved, or a Message object containing a populated serial field.

    • Optional params: Record<string, any>

      Optional parameters sent as part of the query string.

    Returns Promise<PaginatedResult<Message>>

    A promise which, upon success, will be fulfilled with a PaginatedResult object containing an array of Message objects representing all versions of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const versions = await channel.getMessageVersions(message);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#get-message-versions

  • Removes all registrations that match both the specified listener and the specified event.

    Parameters

    Returns void

  • Deregisters the specified listener. Removes all registrations matching the given listener, regardless of whether they are associated with an event or not.

    Parameters

    Returns void

  • Deregisters all registrations, for all events and listeners.

    Returns void

  • Registers the provided listener for the specified event. If on() is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using on(), and an event is emitted once, the listener would be invoked twice.

    Parameters

    Returns void

  • Registers the provided listener for the specified events. If on() is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using on(), and an event is emitted once, the listener would be invoked twice.

    Parameters

    Returns void

  • Registers the provided listener all events. If on() is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using on(), and an event is emitted once, the listener would be invoked twice.

    Parameters

    Returns void

  • Registers the provided listener for the first occurrence of a single named event specified as the Event argument. If once is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using once, and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener as once ensures that each registration is only invoked once.

    Parameters

    Returns void

  • Registers the provided listener for the first event that is emitted. If once() is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using once(), and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener as once() ensures that each registration is only invoked once.

    Parameters

    Returns void

  • Returns a promise which resolves upon the first occurrence of a single named event specified as the Event argument.

    Parameters

    Returns Promise<ChannelStateChange>

    A promise which resolves upon the first occurrence of the named event.

  • Returns a promise which resolves upon the first occurrence of an event.

    Returns Promise<ChannelStateChange>

    A promise which resolves upon the first occurrence of an event.

  • Sets the ChannelOptions for the channel.

    Changing modes or params while the channel is attached or attaching re-attaches it to apply them, and the promise resolves only once the server confirms the new options. It rejects with an ErrorInfo if the channel transitions to detached or failed instead. If the channel is not attached or attaching, changed modes or params are stored and applied on the next attach. Other options, such as a cipher, take effect immediately.

    The promise also rejects with an ErrorInfo when the supplied options are invalid.

    Parameters

    Returns Promise<void>

    A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.

    Example

    await channel.setOptions({ params: { rewind: '1' } });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#set-options

  • Publishes an update to an existing message with patch semantics. Non-null name, data, and extras fields in the provided message replace the corresponding fields in the existing message, while null fields are left unchanged.

    The channel must be configured to allow message updates, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • message: Message

      A Message object containing a populated serial field and the fields to update.

    • Optional operation: MessageOperation

      An optional MessageOperation object containing metadata about the update operation.

    • Optional options: PublishOptions

      Optional parameters to modify how the publish is made.

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    await channel.updateMessage({ ...message, data: 'edited text' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-channel#update-message

Generated using TypeDoc