Skip to content

Commit

Permalink
Support for subscription with presence channels (#393)
Browse files Browse the repository at this point in the history
fix: fix issue with unsubscribe call when presence channels included manually.

Resolves the issue of manually included presence channels not being unsubscribed from the subscription set.
  • Loading branch information
mohitpubnub authored Jul 23, 2024
1 parent cac7bc7 commit 44f9d6c
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 45 deletions.
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2024-07-23
version: v8.2.6
changes:
- type: bug
text: "Resolves the issue of manually included presence channels not being unsubscribed from the subscription set."
- date: 2024-07-18
version: v8.2.5
changes:
Expand Down Expand Up @@ -1013,7 +1018,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '8.2.5'
version: '8.2.6'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1029,7 +1034,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.5.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.6.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1700,7 +1705,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v8.2.5/pubnub.8.2.5.js
location: https://github.com/pubnub/javascript/releases/download/v8.2.6/pubnub.8.2.6.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v8.2.6
July 23 2024

#### Fixed
- Resolves the issue of manually included presence channels not being unsubscribed from the subscription set. Fixed the following issues reported by [@roman-rr](https://github.com/roman-rr): [#390](https://github.com/pubnub/javascript/issues/390).

## v8.2.5
July 18 2024

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.min.js
2. Configure your keys:
Expand Down
14 changes: 5 additions & 9 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3813,7 +3813,7 @@
return base.PubNubFile;
},
get version() {
return '8.2.5';
return '8.2.6';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -8969,8 +8969,8 @@
}
unsubscribe() {
this.pubnub.unsubscribe({
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
channels: this.channelNames,
channelGroups: this.groupNames,
});
}
set onMessage(onMessageListener) {
Expand Down Expand Up @@ -9014,16 +9014,12 @@
this.options = subscriptionOptions;
this.eventEmitter = eventEmitter;
this.pubnub = pubnub;
channels
.filter((c) => !c.endsWith('-pnpres'))
.forEach((c) => {
channels.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups
.filter((cg) => !cg.endsWith('-pnpres'))
.forEach((cg) => {
channelGroups.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
return base.PubNubFile;
},
get version() {
return '8.2.5';
return '8.2.6';
},
getVersion() {
return this.version;
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/SubscribeCapable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class SubscribeCapable {
}
unsubscribe() {
this.pubnub.unsubscribe({
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
channels: this.channelNames,
channelGroups: this.groupNames,
});
}
set onMessage(onMessageListener) {
Expand Down
8 changes: 2 additions & 6 deletions lib/entities/SubscriptionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable {
this.options = subscriptionOptions;
this.eventEmitter = eventEmitter;
this.pubnub = pubnub;
channels
.filter((c) => !c.endsWith('-pnpres'))
.forEach((c) => {
channels.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups
.filter((cg) => !cg.endsWith('-pnpres'))
.forEach((cg) => {
channelGroups.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "8.2.5",
"version": "8.2.6",
"author": "PubNub <support@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const makeConfiguration = (
return base.PubNubFile;
},
get version(): string {
return '8.2.5';
return '8.2.6';
},
getVersion(): string {
return this.version;
Expand Down
4 changes: 2 additions & 2 deletions src/entities/SubscribeCapable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export abstract class SubscribeCapable {
}
unsubscribe() {
this.pubnub.unsubscribe({
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
channels: this.channelNames,
channelGroups: this.groupNames,
});
}

Expand Down
24 changes: 10 additions & 14 deletions src/entities/SubscriptionSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ export class SubscriptionSet extends SubscribeCapable {
this.options = subscriptionOptions;
this.eventEmitter = eventEmitter;
this.pubnub = pubnub;
channels
.filter((c) => !c.endsWith('-pnpres'))
.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups
.filter((cg) => !cg.endsWith('-pnpres'))
.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
});
channels.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
});
this.listener = {};
eventEmitter.addListener(
this.listener,
Expand Down
45 changes: 44 additions & 1 deletion test/integration/endpoints/subscribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('subscribe endpoints', () => {
subscription.subscribe({ timetoken: '1234567890' });
});

it.only('signal listener called for string signal', (done) => {
it('signal listener called for string signal', (done) => {
utils
.createNock()
.get('/v2/subscribe/mySubKey/c1/0')
Expand Down Expand Up @@ -290,4 +290,47 @@ describe('subscribe endpoints', () => {
const subscription = channel.subscription();
subscription.subscribe();
});

it('supports subscribe() with presence channelnames', () => {
const scope0 = utils
.createNock()
.get('/v2/subscribe/mySubKey/c1,c2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
ee: '',
tt: 0,
})
.reply(
200,
'{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}',
{ 'content-type': 'text/javascript' },
);
const scope = utils
.createNock()
.get('/v2/subscribe/mySubKey/c1,c2-pnpres/0')
.query({
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
uuid: 'myUUID',
ee: '',
tt: '1234567890',
tr: 1,
})
.reply(
200,
'{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}',
{ 'content-type': 'text/javascript' },
);

const subsripptionSetWithPresenceChannels = pubnubWithEE.subscriptionSet({
channels: ['c1', 'c2-pnpres'],
});

subsripptionSetWithPresenceChannels.subscribe();

assert.deepEqual(pubnubWithEE.getSubscribedChannels(), ['c1', 'c2-pnpres']);

subsripptionSetWithPresenceChannels.unsubscribe();
assert.deepEqual(pubnubWithEE.getSubscribedChannels(), []);
});
});

0 comments on commit 44f9d6c

Please sign in to comment.