Skip to main content
Presence enables you to track which clients are present on a channel, including their state and custom data. Each channel has a presence set containing all currently present members.

Presence Object

Access presence through a channel’s presence property:

Properties

boolean
Indicates whether the presence set is synchronized with the server. Returns true when sync is complete.

Methods

enter

enter(data?, callback?): Promise<void> Enter the presence set with optional data.
any
Optional data to associate with this member. Supported types: string, JSON object, binary data.
function
Optional callback called on completion.
Requirements:
  • Client must have a clientId configured
  • Client must have presence capability on the channel
  • Channel will be implicitly attached if not already

update

update(data?, callback?): Promise<void> Update the data for this member without leaving and re-entering.
any
New data to associate with this member.

leave

leave(data?, callback?): Promise<void> Leave the presence set.
any
Optional data emitted with the leave event.

get

get(options?): Promise<PresenceMessage[]> Get the current presence set.
string
Filter by specific client ID.
string
Filter by specific connection ID.
boolean
default:"true"
Wait for presence sync to complete before returning.

subscribe

subscribe(action?, listener): Promise<void> Subscribe to presence events.
string | string[]
Optional action(s) to filter events: enter, leave, update, or present.
function
required
Callback function called for each presence event.

unsubscribe

unsubscribe(action?, listener?): void Unsubscribe from presence events.

history

history(options?): Promise<PaginatedResult<PresenceMessage>> Retrieve presence event history.
integer
Start time in milliseconds since epoch.
integer
End time in milliseconds since epoch.
integer
default:"100"
Maximum number of events to return (max 1000).
string
default:"backwards"
Query direction: forwards or backwards.

PresenceMessage

Presence messages contain:
string
Presence action: enter, leave, update, or present.
string
Client ID of the member.
string
Connection ID of the member.
any
Data associated with this member.
integer
Timestamp of the presence event.
string
Unique event ID.

Presence Actions

action
Member entered the presence set.
action
Member left the presence set.
action
Member updated their data.
action
Member was already present (sent during sync).

Examples

User Status

Track user online status:

Display Active Users

Show list of active users:

Typing Indicators

Implement typing indicators: