KEY TAKEWAYSIn this guide, we discuss the importance of including user presence features, and their key role in making real-time technology an interactive experience.
What is user presence?
User presence is an important feature to include 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 also 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, but 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 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.
User presence plays a key role in making real-time technology an interactive experience. It gives members within the community an indication that someone is online and available to communicate. By incorporating real-time data like an online status to provide relevant notifications, you can engage your users, make them feel like they’re connecting and participating, and build a sense of camaraderie within your Virtual Space, going above and beyond a basic, stagnant application.
Why should you include user presence in your app?
Presence has a very important role in any application that requires real-time connectivity—whether that be between people or between devices. User presence offers that real-time activity that reflects or resembles the instant feel of an in-person experience, and allows for an authentic experience between users.
By informing users when their friends or other community members are online, presence status and notifications provide your users with compelling reasons to engage in your Virtual Space. You can also build on user presence and online statuses to implement other immersive, real-time updates and chat features, like typing indicators, live audience counts, and real-time alerts. These features are highly customizable to your specific needs.
Presence has enormous value in a wide range of use cases—like in a telemedicine application, where it can enable virtual waiting rooms and let doctors know that a patient is online, or in a gaming environment, where it lets players see which of their friends are online and ready to enter a match. And in an IoT use case like fleet management or logistics, device presence status can keep locations accurate to the second, and ensure that scheduling is efficient.
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 PubNub 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 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 presence and 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.
If you are interested in working with PubNub to build your own Virtual Space or real-time application, contact our sales team and talk to an expert here.