pubnub / javascript

PubNub JavaScript SDK docs https://www.pubnub.com/docs/sdks/javascript
Other
553 stars 401 forks source link

[BUG] Sets doesn't unsubscribe from channels with -pnpres suffix #390

Closed roman-rr closed 4 months ago

roman-rr commented 4 months ago

Please correct me, if not the bag.

// Let's define a subscription set and add some channels with `-pnpres` for presence listening. 
let regularSubscriptionSet = pubnub.subscriptionSet({
  channels: ['channel-1-pnpres', 'channel-2-pnpres', 'channel-3', 'channel-4'],
});

// Subscribe to set
regularSubscriptionSet.subscribe();

// Check subscriptions
console.log('Subscribed channels', pubnub.getSubscribedChannels());
// Returned ['channel-1-pnpres', 'channel-2-pnpres', 'channel-3', 'channel-4']

// Unsubscribe from set 
regularSubscriptionSet.unsubscribe();

console.log('Subscribed channels', pubnub.getSubscribedChannels());
// Returned ['channel-1-pnpres', 'channel-2-pnpres']

// Call depreciated method
pubnub.unsubscribe({channels: ['channel-1-pnpres', 'channel-2-pnpres']})

console.log('Subscribed channels', pubnub.getSubscribedChannels());
// Returned []

In other words, new SubscriptionSet functionality doesn't unsubscribe from channels with -pnpres, even it's bootstrapped to pubnub.channel(). Old style pubnub.unsubscribe() works as expected.

Did I miss something?

parfeon commented 4 months ago

@roman-rr thank you for reporting back about the issue.

I can see in the code special -pnpres channels treatment, but need to consult the team about why this decision has been made. It should list of channels and groups as-is, but maybe some factors need to be considered.

pubnub-release-bot commented 4 months ago

@roman-rr this issue is addressed in v8.2.6

parfeon commented 4 months ago

Release is rolling out as a temporarily backward-compatible solution.

The idea behind the original implementation was to use the receivePresenceEvents subscription configuration option to instruct the subscription object to provide -pnpres - this way all works as expected. When they have passed manually, you will get into trouble.