How do I send Presence update after my phone goes back from sleep with PubNub?

140 Views Asked by At

My main task is to update Active Chat Member count on UI. I am calling pubnub.HereNow() when PresenceEventResult happens. Everything works fine, except case when my phone goes sleep and wake up again.

When my phone goes sleep, leave presence event is fired, I see it when I check console on my second client (this is probably due the checkbox "Generate Leave on TCP FIN or RST" is checked in Admin panel of PubNub). But when I turn on my phone, I still able to retrieve messages from other users, but if I check HereNow I see only that other user is presented. I tried to call subscribe one more time in Unity like this (I thought maybe it will fire event again, but it doesn't):

private void OnApplicationPause(bool pause)
{
    Debug.Log("OnApplicationPause(): " + pause);
    if (!pause)
    {
        pubnub.Subscribe()
            .Channels(new List<string>() {
            channel
            })
            .WithPresence()
            .Execute();
    }
}

Do you have any ideas, how can I notify pubnub servers that I am back?

1

There are 1 best solutions below

0
On

I am not sure if this 100% correct from PubNum side, but it's working for me:

private void OnApplicationPause(bool pause)
{
    if (!pause)
    {
        pubnub.Reconnect();
    }
}