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

syncComplete
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.
data
any
Optional data to associate with this member. Supported types: string, JSON object, binary data.
callback
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.
data
any
New data to associate with this member.

leave

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

get

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

subscribe

subscribe(action?, listener): Promise<void> Subscribe to presence events.
action
string | string[]
Optional action(s) to filter events: enter, leave, update, or present.
listener
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.
start
integer
Start time in milliseconds since epoch.
end
integer
End time in milliseconds since epoch.
limit
integer
default:"100"
Maximum number of events to return (max 1000).
direction
string
default:"backwards"
Query direction: forwards or backwards.

PresenceMessage

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

Presence Actions

enter
action
Member entered the presence set.
leave
action
Member left the presence set.
update
action
Member updated their data.
present
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:

Build docs developers (and LLMs) love