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 that uses PubNub Access Manager to control who can read and write to channels. The application has both chat channels (where users need to see who is online) and notification channels (where presence tracking is unnecessary).
Users have reported that after enabling Access Manager, the online user list stopped working -- no presence events are being received even though the presence feature is enabled in the Admin Portal.
Your task is to fix the access control setup so presence works correctly alongside security, while keeping the permission scope minimal.
Write a server-side JavaScript function that grants a user the appropriate PubNub permissions for:
Also write the corresponding client-side subscription code that subscribes to both channels but only enables presence where it is needed.
grant-permissions.js -- the server-side function to grant accesssubscribe-with-presence.js -- the client-side subscription code