简体   繁体   中英

PubNub unsubscribe isn't firing presence event

I'm using the latest JavaScript API for PubNub, with presence switched on in the admin interface. I'm running two clients on a channel, initialized and subscribed like this:

pubnub = PUBNUB.init({
                publish_key   : 'xxx',
                subscribe_key : 'xxx',
                origin        : 'pubsub.pubnub.com',
                cipher_key    : 'xxx',
                ssl           : 'true',
                uuid          : uuid
            });

pubnub.subscribe({
                channel : CHANNEL,
                callback : function (message) {
                    $("#box").val($("#box").val() + message + "\r\n");
                },
                connect:    function () { console.log("Connected"); users(); },
                disconnect: function () { console.log("Disconnected"); },
                reconnect:  function () { console.log("Reconnected"); },
                error:      function () { console.log("Network Error"); },
                presence:   function (m) { console.log("Presence: " + m); }
            });

I unsubscribe from the channel like this:

function unsubscribe() {
    pubnub.unsubscribe({
        channel:    CHANNEL
    });
    console.log("Unsubscribed");
};

When clients join the channel, I see join presence actions in all clients that are subscribed. When clients timeout, I see those actions too.

When I call unsubscribe() the log line prints, and that client does not receive any more messages published on the channel, but there is no leave presence action received by other clients who are still subscribed. What am I doing wrong?

Strangely enough, when I tried to subscribe this morning I got a 400 Invalid error. When I investigated, the PubNub admin screen told me that there were no keys associated with my project.

When I had regenerated the keys I could subscribe - and the join and leave events worked as expected too. I now get the response I expect from here-now as well.

Odd, but fixed!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM