Presence

Automatic real-time detection of device and user online state

Enhance user experience with easy-to-use APIs for online/offline tracking, real-time user count, and more.

What can you do with Presence?

User Online state

Deliver instantaneous status updates whenever user state changes for any number of connected users across related apps.

Audience count and location

Detect and update connected user counts and locations.

Battery State Notifications

Monitor device battery state, and trigger events when thresholds are met.

Functions

Trigger powerful serverless functions to run business logic whenever a user connects or disconnects.

Webhooks

Configure PubNub to callback to your server (or any REST API) whenever a user state changes.

Presence Management

Track specific Presence events such as: Join, Leave, TimeOut, State-Change, and Intervals. Add Channel Patterns or Channel Groups, specify the events to track for each group, and more

Where is Presence Used?

User Lists - Create live-updating lists of online and offline users, like chat contact lists.

IoT Device Management - Allow users to receive device status and control devices such as light bulbs, door locks, temperature sensors, and security cameras. 

Frequently Asked Questions

expand_less

How do I turn Presence on in Portal?

Once you have created your app and keyset in Portal, you will be able to see presence under the Configuration Tab. You will have to toggle the option to enable presence for all the channels under that keyset.

Once you have created your app and keyset in Portal, you will be able to see presence under the Configuration Tab. You will have to toggle the option to enable presence for all the channels under that keyset.

expand_more

I just turned Presence on my portal now what?

Presence will start tracking users and publish events for uuids that join/leave/timeout of channels. Presence by default, is globally enabled for all channels in the subkey. You will also need to update your app or server to start listening to the -pnpres channel so you can do something with the events generated.

expand_more

What are the queries API available for Presence?

- hereNow - current list of users in channels

- whereNow - current list of channels specified user is present in for subkey

- getState - state for specific user in channel

expand_more

What are the events generated when Presence is enabled?

- Join: user joining a channel

- Leave: user leaving a channel

- Time Out: user not sending signal 

- Active: first person joining channel

- Inactive: last person leaving channel

expand_more

What is the purpose of the PNPRESS channel?

The purpose of PNPRSS is to separate the presence channel from the main channel to lower the noise of events.

The PNPRESS Channel is the “side” channel where notifications are sent. For instance in a chat app there could be a channel named lobby:

- lobby - this is the chat messages.

- lobby-pnpres - this is where presence sends events such as join, leave etc. are been sent.

expand_more

How do I get a client event for Presence?

By listening to the events generated in the  “pnpress” channel.

expand_more

How do I track if users are online or not?

There are several ways to see if a user is online or not:

Option 1: Call “here_now” on the channel you want to track to get list of active users.

Option 2: Listen to the “pnpres” channels and keep track of users that joined or left that channel.

expand_more

What are the limits of Presence api calls?

To view the limits of Presence API calls, please visit our docs on Presence limits here.

Ready to get started?