Interface RealtimePresence

Enables the presence set to be entered and subscribed to, and the historic presence set to be retrieved for a channel.

Hierarchy

  • RealtimePresence

Properties

syncComplete: boolean

Indicates whether the presence set synchronization between Ably and the clients on the channel has been completed.

A true value means only that no sync is in progress. It does not mean the presence set is populated, since the flag is also true once the local set is cleared, and it returns to false whenever a new sync starts.

To wait for an in-progress sync, call get(), which by default resolves only once the sync completes.

Methods

  • Enters the presence set for the channel, optionally passing a data payload. Implicitly attaches the channel if it is not already attached.

    Requires an identified client. If the clientId is unset, or is the wildcard *, the call rejects with an ErrorInfo. Set a clientId in ClientOptions or in the token, or use enterClient() to enter on behalf of another identity.

    The member is automatically re-entered when the channel re-attaches after a disconnection. If that fails, the ErrorInfo arrives as a channel update event rather than as a rejection.

    Parameters

    • Optional data: any

      The payload associated with the presence member.

    Returns Promise<void>

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

    Example

    await channel.presence.enter({ status: 'online' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-presence#enter

  • Parameters

    • data: any

      The payload associated with the presence member.

    • callback: ErrorCallback

      v1 Node-style callback (no longer supported).

    Returns void

    Deprecated

    v1 callback signature — no longer supported. Use channel.presence.enter(data) and await the returned promise. See the v2 migration guide.

    Example

    // v1 (no longer supported — IDE shows this with strikethrough):
    channel.presence.enter(data, (err) => {});

    // v2:
    await channel.presence.enter(data);
  • Enters the presence set of the channel for a given clientId. Enables a single client to update presence on behalf of any number of clients using a single connection. Implicitly attaches the channel if it is not already attached.

    Requires an API key or token bound to a wildcard clientId. Without one the call rejects with an ErrorInfo from the server.

    The member is automatically re-entered when the channel re-attaches after a disconnection. If that fails, the ErrorInfo arrives as a channel update event rather than as a rejection.

    Parameters

    • clientId: string

      The ID of the client to enter into the presence set.

    • Optional data: any

      The payload associated with the presence member.

    Returns Promise<void>

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

    Example

    await channel.presence.enterClient('bob', { status: 'online' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-presence#enter-client

  • Leaves the presence set for the channel. Use leaveClient() to leave on behalf of another identity.

    Leaving does not implicitly attach the channel. It requires a channel in the attached state. On an attaching channel the call is queued until the channel attaches, unless queueMessages is disabled. In any other channel state, or when the connection is unusable, it rejects with an ErrorInfo.

    Parameters

    • Optional data: any

      The payload associated with the presence member.

    Returns Promise<void>

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

  • Parameters

    • data: any

      The payload associated with the presence member.

    • callback: ErrorCallback

      v1 Node-style callback (no longer supported).

    Returns void

    Deprecated

    v1 callback signature — no longer supported. Use channel.presence.leave(data) and await the returned promise. See the v2 migration guide.

    Example

    // v1 (no longer supported — IDE shows this with strikethrough):
    channel.presence.leave(data, (err) => {});

    // v2:
    await channel.presence.leave(data);
  • Leaves the presence set of the channel for a given clientId. Enables a single client to update presence on behalf of any number of clients using a single connection.

    Requires an API key or token bound to a wildcard clientId. Without one the call rejects with an ErrorInfo from the server.

    Leaving does not implicitly attach the channel. It requires a channel in the attached state. On an attaching channel the call is queued until the channel attaches, unless queueMessages is disabled. In any other channel state, or when the connection is unusable, it rejects with an ErrorInfo.

    Parameters

    • clientId: string

      The ID of the client to leave the presence set for.

    • Optional data: any

      The payload associated with the presence member.

    Returns Promise<void>

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

    Example

    await channel.presence.leaveClient('bob');
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-presence#leave-client

  • Updates the data payload for a presence member. If called before entering the presence set, this is treated as an ENTER event. Implicitly attaches the channel if it is not already attached.

    Requires an identified client. If the clientId is unset, or is the wildcard *, the call rejects with an ErrorInfo. Use updateClient() to update on behalf of another identity.

    Parameters

    • Optional data: any

      The payload to update for the presence member.

    Returns Promise<void>

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

    Example

    await channel.presence.update({ status: 'busy' });
    

    See

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

  • Parameters

    • data: any

      The payload to update for the presence member.

    • callback: ErrorCallback

      v1 Node-style callback (no longer supported).

    Returns void

    Deprecated

    v1 callback signature — no longer supported. Use channel.presence.update(data) and await the returned promise. See the v2 migration guide.

    Example

    // v1 (no longer supported — IDE shows this with strikethrough):
    channel.presence.update(data, (err) => {});

    // v2:
    await channel.presence.update(data);
  • Updates the data payload for a presence member using a given clientId. Enables a single client to update presence on behalf of any number of clients using a single connection. Implicitly attaches the channel if it is not already attached.

    Requires an API key or token bound to a wildcard clientId. Without one the call rejects with an ErrorInfo from the server.

    Parameters

    • clientId: string

      The ID of the client to update in the presence set.

    • Optional data: any

      The payload to update for the presence member.

    Returns Promise<void>

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

    Example

    await channel.presence.updateClient('bob', { status: 'busy' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-presence#update-client

Generated using TypeDoc