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 chat application using PubNub. Users join and leave chat rooms, and the application needs to display an accurate list of who is currently online in a given room. The system must handle all edge cases: users who disconnect cleanly, users whose connections drop unexpectedly, users who update their status metadata, and rooms with very large numbers of participants where PubNub changes how it reports presence.
When the application first loads or reconnects, it needs to know who is already in the room -- it cannot rely solely on real-time events since it may have missed past events.
Implement a JavaScript class called PresenceManager that:
initialize() method that fetches the current state of the channel on startupgetUsers(), getOccupancy(), isUserOnline(uuid)A single JavaScript file presence-manager.js containing the PresenceManager class.