How can I retrieve a list of join, leave, and timeout events for a channel when the PubNub presence delta payload size exceeds 32kb?

111 Views Asked by At

I'm using PubNub presence events to get the presence list for a channel, and I'm using Announce & Interval mode to detect presence changes. However, I've run into a problem where the delta payload size exceeds 32kb and PubNub sends a "here-now-refresh" flag.

When this happens, I need to retrieve the list of join, leave, and timeout events for the channel, but the hereNow() API method only returns the current list of subscribed UUIDs for the channel.

How can I retrieve a list of join, leave, and timeout events for the channel in this situation? Is there a way to retrieve this information using the PubNub API or another method?

2

There are 2 best solutions below

0
Stephen Blum On

Retrieve a List of Join/Leave/Timeout Events

Use the pubnub.fetchMessages() API method. Enable Persistence on your API key in admin.pubnub.com control panel. The pubnub.fetchMessages() takes a channel name. Use your channel name and append -pnpres to the name. This will allow you to pull a list of Join/Leave/Timeout events in the order they occurred. You'll also want to increase your limit.

(async () => {

console.log("Initialize PubNub SDK");
const pubnub = new PubNub({
    subscribeKey: "demo",
    publishKey: "demo",
    userId: "myUniqueUserId",
});

console.log("Call Message Persistence History API");
const response = await pubnub.fetchMessages({
    channels: ['mychannel-pnpres'], // <--- append '-pnpres' to your channel name
    start: "15343325214676133",
    end: "15343325004275466",
    count: 25,
});

console.log(response);

})()
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.2.min.js"></script>

0
Stephen Blum On

Realtime List of Join/Leave/Timeout Events Increase Limit

PubNub allows you to increase the presence tracking events for users. The PubNub account dashboard has a default low limit. However you can contact [email protected] in set this value as high as you need. We can set this value over +1 million. However you'll likely want to control this value lower to prevent loading the client's network.

PubNub Presence Increase Limit