Reputation: 169
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?
Upvotes: 2
Views: 821
Reputation: 169
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!
Upvotes: 1