Occupancy

Occupancy enables you to view the number of users currently online in a room. This feature can be used to display user counts to highlight popular, or trending chat rooms.

Subscribe to room occupancy

Subscribe to a room's occupancy by registering a listener. Occupancy events are emitted whenever the number of online users within a room changes. Use the occupancy.subscribe() method in a room to receive updates:

Occupancy event structure

The following is the structure of an occupancy event:

JSON

The following are the properties of an occupancy event:

PropertyDescriptionType
connectionsThe number of connections in the room.Number
presenceMembersThe number of users entered into the presence set of the room.Number

Unsubscribe from room occupancy

Use the unsubscribe() function returned in the subscribe() response to remove a room occupancy listener:

Use the occupancy.unsubscribeAll() method to remove all room occupancy listeners in a room:

JavaScript

Retrieve room occupancy

The occupancy of a room can be retrieved in one-off calls instead of subscribing to updates.

Use the occupancy.get() method to retrieve the occupancy of a room:

The following is the structure of an occupancy event:

JSON

The following are the properties of an occupancy event:

PropertyDescriptionType
connectionsThe number of connections in the room.Number
presenceMembersThe number of users entered into the presence set of the room.Number
Select...