Interface Presence

This interface is used to interact with presence in a chat room: subscribing to presence events, fetching presence members, or sending presence events (join,update,leave).

Get an instance via Room.presence.

interface Presence {
    get channel(): RealtimeChannel;
    enter(data?: unknown): Promise<void>;
    get(params?: RealtimePresenceParams): Promise<PresenceMember[]>;
    isUserPresent(clientId: string): Promise<boolean>;
    leave(data?: unknown): Promise<void>;
    onDiscontinuity(listener: DiscontinuityListener): OnDiscontinuitySubscriptionResponse;
    subscribe(eventOrEvents: PresenceEvents | PresenceEvents[], listener?: PresenceListener): PresenceSubscriptionResponse;
    subscribe(listener?: PresenceListener): PresenceSubscriptionResponse;
    unsubscribeAll(): void;
    update(data?: unknown): Promise<void>;
}

Hierarchy

  • EmitsDiscontinuities
    • Presence

Accessors

Methods

  • Method to join room presence, will emit an enter event to all subscribers. Repeat calls will trigger more enter events.

    Parameters

    • Optionaldata: unknown

      The users data, a JSON serializable object that will be sent to all subscribers.

    Returns Promise<void>

    or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.

  • Method to check if user with supplied clientId is online

    Parameters

    • clientId: string

      The client ID to check if it is present in the room.

    Returns Promise<boolean>

    or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.

  • Method to leave room presence, will emit a leave event to all subscribers. If the user is not present, it will be treated as a no-op.

    Parameters

    • Optionaldata: unknown

      The users data, a JSON serializable object that will be sent to all subscribers.

    Returns Promise<void>

    or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.

  • Unsubscribe all listeners from all presence events.

    Returns void

  • Method to update room presence, will emit an update event to all subscribers. If the user is not present, it will be treated as a join event.

    Parameters

    • Optionaldata: unknown

      The users data, a JSON serializable object that will be sent to all subscribers.

    Returns Promise<void>

    or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.