What is Presence?
Presence enables you to track the online and offline status of users and devices in real time. PubNub triggers Presence events to monitor channel occupancy, when a user has joined or left a channel, typing, mood, or status indicators, current location, and profile information. Enabling Presence on your keyset in the Admin Portal will automatically create additional presence equivalents of all channels to track these presence events about users.
When presence events are triggered for a channel, there are two different modes the channel will be in: Announce and Interval. The mode is determined by occupancy count (total actively subscribed clients on that channel). Announce is the default mode and the join, leave, timeout and state-change events are sent to subscribed clients when they’re triggered. Once the channel has reached the announced max number (handled in the portal setting discussed below), the channel goes into interval mode. This mode will replace sending join, leave and timeout events with interval events and are sent every few seconds based on the Interval setting (set in the Presence setting discussed below). If the user enables the “Presence Deltas” setting, interval events will also include who has joined, left or timed out in that interval.
Use webhooks (callbacks) to have PubNub notify your server whenever presence events occur on any channel for your keys, especially if you have a large number of channels or where the actual channel names may be dynamic and continuously changing. Provide a REST POST endpoint for the Presence webhook settings if you wish to receive these callbacks on your server. It is recommended to have at least two different REST POST endpoints: one for Channel Active/Inactive Webhooks, and then another for the rest of the Presence webhooks, due to differences in payload structures.
Watch the video below or follow the step-by-step instructions to learn how to enable Presence in your PubNub keyset. Need extra information? Check out PubNub’s official documentation on Presence to learn more about how to implement Presence in your own application.
Login to the Admin Portal.
Click on the apps tab on the left hand side of the portal.
Click on an application. You will be brought to the keysets page for this application.
Click on a keyset. You will be brought to the configuration page for this keyset.
Enable Presence by clicking on the slider to turn it on. A pop-up will require that you enter in “ENABLE”. Enter in “ENABLE” in all caps and then press the “Enable” button.
Presence Event Settings. You can leave the default settings for presence functionality to work in your application, but the following Presence Event settings allow you customize and control events:
Announce Max: Specify the maximum number of occupants in the Announce channel mode before switching to the Interval channel mode.
Interval: Specifies the number of seconds between each interval event in the Interval channel mode.
Presence Deltas: If enabled, will have interval events in the Interval channel mode include information about who has joined, left, or timed out (list of UUIDs).
Generate Leave on TCP FIN or RST: If enabled, PubNub will generate a leave event if the client closes the browser rather than sending the leave event when the user timeouts.
Stream Filtering: If enabled, ensures Presence metadata is included in events published to the presence channels. The Subscription Stream Feature can then be used to ensure that Presence events are not filtered out when using filters on a channel.
Presence Webhook Settings. These are not required for basic presence functionality to work in your application, but are necessary to receive events on your server.
Active Notice Channel: Specify the PubNub channel where active and inactive channel notifications are published.
Channel Active Webhook: Triggers the HTTP(s) endpoint when channel occupancy changes from 0 to 1.
Channel Inactive Webhook: Triggers the HTTP(s) endpoint when channel occupancy changes from 1 to 0.
Presence Join Webhook: Triggers the HTTP(s) endpoint when a user subscribes to a channel.
Presence Leave Webhook: Triggers the HTTP(s) endpoint when a user unsubscribes from a channel.
Presence Timeout Webhook: Triggers the HTTP(s) endpoint when a user timeout from a channel.
Presence State Change Webhook: Triggers the HTTP(s) endpoint when presence state changes for a user.
Presence Interval Webhook: Triggers the HTTP(s) endpoint for interval events.
Debounce: The amount of time in seconds to wait before allowing implicit “joins” after an explicit “leave”.
Click on Save Changes to save these updated changes.