Implement real-time presence tracking with PubNub
79
Quality
67%
Does it follow best practices?
Impact
98%
1.07xAverage score across 5 eval scenarios
You are building a browser-based chat application where users see who is online in their chat room. A common complaint from users is that when someone closes their browser tab, they remain shown as "online" for several minutes before disappearing. You need the online list to update as quickly as possible when users leave.
Additionally, users who refresh the page or return after a brief network outage should not lose track of who is in the room.
The application will be used for real-time team communication with moderate activity (teams of 10-50 people).
Write the PubNub initialization and presence setup code for a browser-based chat application that:
A single JavaScript file chat-presence-setup.js containing the PubNub initialization, presence subscription, connection lifecycle handling, and cleanup logic.