What is Presence?
What is presence?
User presence (status indicator) is important when building an engaging, real-time virtual experience. At its most simple, presence is the representation of a user’s online or offline status. It can apply to specific users (accounts) or specific devices. Think of the little green dot that you often see displayed next to someone on your contacts list. That’s user presence at work: letting you know they are online and active on the same application.
When someone logs into an application from their device, the default presence status will be set to online. Still, it is a common feature to let users customize their status or set themselves as “Away,” “Out of Office,” or “Do Not Disturb.” You are likely familiar with seeing a user’s status from Messaging Apps & Collaboration Tools like Slack, Microsoft Teams, or any of the PubNub-driven apps that include chat messages as a social feature, like JUNO—an educational hybrid events platform.
The user status indicator is crucial for enhancing real-time interaction in apps. It shows when someone is online and available, enabling live engagement and fostering a sense of connection and community within your virtual space, making the experience more dynamic and interactive.
Why should you include user presence in your app?
User presence is vital for real-time connectivity, offering the instant, authentic interaction that mirrors in-person experiences.
By showing when friends or community members are online, presence status and notifications give users compelling reasons to engage in your Virtual Space. You can build on user presence to add immersive features like typing indicators, live audience counts, and real-time alerts, all customizable to your needs.
User presence is valuable across various use cases—enabling virtual waiting rooms in telemedicine, showing which friends are online in gaming, and ensuring accurate, real-time location tracking in IoT scenarios like fleet management.
PubNub’s device and user presence features
At PubNub, we offer multiple APIs and SDKs with device and user presence as part of our platform. Presence helps contribute to creating a scalable, event-driven app that operates in real time, improving a user’s virtual experience within your application.
With Presence features, you can track the online/offline status of users and devices in real time, and create custom state to drive insights and actions across your application. Custom state examples include geolocation, game scores, and other items that frequently need to update.
Some of our feature-rich APIs and options involving user presence include:
User State: Deliver instantaneous status updates whenever user state changes for any number of connected users across related apps.
Audience Count and Location: Detect, update, and keep track of user counts and locations.
Typing Indicators: Show when a user is typing a chat message.
Webhooks: Configure PubNub to notify your server whenever a presence event or user state changes.
PubNub Functions: Trigger low-latency, serverless functions when an event such as a user connecting or disconnecting occurs.
These features allow you to see who is active and online with to-the-millisecond status updates, and you can use the real-time data to improve the interactivity of your application and keep users invested in your app instead of external messaging platforms.
Beyond simply reading who is online and offline and providing a list of users, PubNub Presence is flexible, enabling the streaming of real-time updates as device statuses update—perfect for building typing indicators, determining whether a door is open or closed, and other important real-time information.
[Explore our Presence Docs here.]
How does PubNub User Presence work?
Built on the pub/sub model that PubNub knows best, PubNub’s Presence API makes it easy to implement features that rely on user counts. It lets you keep track of the number of users and devices connected to your app, and triggers logic based on them coming online or going offline.
Presence lets you track the online and offline status of your users, and share user states. When you have Presence enabled, PubNub automatically creates a sister presence channel for each of your channels. Clients can subscribe to the presence channel to receive presence events, which show a green dot that indicates that the user is online.
PubNub Presence uses automatic, real-time detection of user state to identify who is connected to your application. Presence lets you update your active user roster the moment status changes occur. To do this, PubNub triggers events whenever a user’s occupancy state changes. Presence events and state changes can be either synchronous or asynchronous within the platform, and can call your servers in real time using webhook callbacks.
At a high-level, four important events are tracked using Presence:
Join: Issued whenever a device subscribes to a channel. This means a user is “coming online.”
Leave: Issued when a device unsubscribes from a channel. This means a user is “going offline.”
Timeout: Issued when a subscriber is not seen on a channel for 320 seconds, or just over five minutes. This interval can be adjusted manually.
State-change: Fires anytime a user's state is modified.
Presence also lets you share dynamic custom state for users, like their profile info, current location, game scoreboards, and more. This custom state persists on a channel as long as the user stays subscribed to that channel. State is transient data, which means it's not persisted anywhere. When a client disconnects, the state data will be lost. If you require a client's state to be restored on reconnect, be sure to cache that data locally to the client.
Clients receive real-time updates when they are subscribed to the relevant presence channels. When any of these events are triggered, Presence events issue JSON payloads that contain all the information needed to make use of those events. This is a brief list of what’s included in each payload.
Action: What happened.
UUID: The identifier for the device triggering the event.
Timestamp: The time, in milliseconds, that the event occurred. You can use this to display “last seen” statuses in your app.
Occupancy: The current occupancy of a channel.
Sub_key: Your subkey for this application.
Channel: The name of the channel for which the event is issued.
For more detailed information on how to use PubNub Presence, check out this blog post that provides an introduction to presence using webhooks, or this post about building user presence features with PubNub and React Native.
Interested in building a real-time, scalable app with features like user presence and real-time notifications?
PubNub helps you create scalable, feature-rich apps that enable real-time interactions, without ever worrying about infrastructure. Our platform solution gives customers the flexibility to build exactly what they envision. Many of our customers have been able to build customizable, engaging Virtual Spaces with unique features they know their users will want. Like Moment House, who uses real-time updates and presence status to connect creators with their fans.
PubNub provides developers with a scalable, secure, and feature-rich platform for building real-time applications. By leveraging our infrastructure, SDKs, and extensive library of tutorials, developers can focus on creating innovative and engaging user experiences. At the same time, PubNub takes care of the underlying complexities of real-time communication so you can focus on building sticky apps that engage users.
Check out our Github or sign up for a free trial where you’ll get up to 200 MAUs or 1M total transactions per month for free.