Skip to content

Commit 44f9d6c

Browse files
authored
Support for subscription with presence channels (#393)
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.
1 parent cac7bc7 commit 44f9d6c

File tree

14 files changed

+87
-45
lines changed

14 files changed

+87
-45
lines changed

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2024-07-23
4+
version: v8.2.6
5+
changes:
6+
- type: bug
7+
text: "Resolves the issue of manually included presence channels not being unsubscribed from the subscription set."
38
- date: 2024-07-18
49
version: v8.2.5
510
changes:
@@ -1013,7 +1018,7 @@ supported-platforms:
10131018
- 'Ubuntu 14.04 and up'
10141019
- 'Windows 7 and up'
10151020
version: 'Pubnub Javascript for Node'
1016-
version: '8.2.5'
1021+
version: '8.2.6'
10171022
sdks:
10181023
- full-name: PubNub Javascript SDK
10191024
short-name: Javascript
@@ -1029,7 +1034,7 @@ sdks:
10291034
- distribution-type: source
10301035
distribution-repository: GitHub release
10311036
package-name: pubnub.js
1032-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.5.zip
1037+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.6.zip
10331038
requires:
10341039
- name: 'agentkeepalive'
10351040
min-version: '3.5.2'
@@ -1700,7 +1705,7 @@ sdks:
17001705
- distribution-type: library
17011706
distribution-repository: GitHub release
17021707
package-name: pubnub.js
1703-
location: https://github.com/pubnub/javascript/releases/download/v8.2.5/pubnub.8.2.5.js
1708+
location: https://github.com/pubnub/javascript/releases/download/v8.2.6/pubnub.8.2.6.js
17041709
requires:
17051710
- name: 'agentkeepalive'
17061711
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v8.2.6
2+
July 23 2024
3+
4+
#### Fixed
5+
- 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).
6+
17
## v8.2.5
28
July 18 2024
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2828
npm install pubnub
2929
```
3030
* or download one of our builds from our CDN:
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,7 +3813,7 @@
38133813
return base.PubNubFile;
38143814
},
38153815
get version() {
3816-
return '8.2.5';
3816+
return '8.2.6';
38173817
},
38183818
getVersion() {
38193819
return this.version;
@@ -8969,8 +8969,8 @@
89698969
}
89708970
unsubscribe() {
89718971
this.pubnub.unsubscribe({
8972-
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
8973-
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
8972+
channels: this.channelNames,
8973+
channelGroups: this.groupNames,
89748974
});
89758975
}
89768976
set onMessage(onMessageListener) {
@@ -9014,16 +9014,12 @@
90149014
this.options = subscriptionOptions;
90159015
this.eventEmitter = eventEmitter;
90169016
this.pubnub = pubnub;
9017-
channels
9018-
.filter((c) => !c.endsWith('-pnpres'))
9019-
.forEach((c) => {
9017+
channels.forEach((c) => {
90209018
const subscription = this.pubnub.channel(c).subscription(this.options);
90219019
this.channelNames = [...this.channelNames, ...subscription.channels];
90229020
this.subscriptionList.push(subscription);
90239021
});
9024-
channelGroups
9025-
.filter((cg) => !cg.endsWith('-pnpres'))
9026-
.forEach((cg) => {
9022+
channelGroups.forEach((cg) => {
90279023
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
90289024
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
90299025
this.subscriptionList.push(subscription);

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/configuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
110110
return base.PubNubFile;
111111
},
112112
get version() {
113-
return '8.2.5';
113+
return '8.2.6';
114114
},
115115
getVersion() {
116116
return this.version;

lib/entities/SubscribeCapable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class SubscribeCapable {
88
}
99
unsubscribe() {
1010
this.pubnub.unsubscribe({
11-
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
12-
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
11+
channels: this.channelNames,
12+
channelGroups: this.groupNames,
1313
});
1414
}
1515
set onMessage(onMessageListener) {

lib/entities/SubscriptionSet.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable {
1111
this.options = subscriptionOptions;
1212
this.eventEmitter = eventEmitter;
1313
this.pubnub = pubnub;
14-
channels
15-
.filter((c) => !c.endsWith('-pnpres'))
16-
.forEach((c) => {
14+
channels.forEach((c) => {
1715
const subscription = this.pubnub.channel(c).subscription(this.options);
1816
this.channelNames = [...this.channelNames, ...subscription.channels];
1917
this.subscriptionList.push(subscription);
2018
});
21-
channelGroups
22-
.filter((cg) => !cg.endsWith('-pnpres'))
23-
.forEach((cg) => {
19+
channelGroups.forEach((cg) => {
2420
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
2521
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
2622
this.subscriptionList.push(subscription);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "8.2.5",
3+
"version": "8.2.6",
44
"author": "PubNub <[email protected]>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"scripts": {

src/core/components/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const makeConfiguration = (
169169
return base.PubNubFile;
170170
},
171171
get version(): string {
172-
return '8.2.5';
172+
return '8.2.6';
173173
},
174174
getVersion(): string {
175175
return this.version;

src/entities/SubscribeCapable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export abstract class SubscribeCapable {
2222
}
2323
unsubscribe() {
2424
this.pubnub.unsubscribe({
25-
channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')),
26-
channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
25+
channels: this.channelNames,
26+
channelGroups: this.groupNames,
2727
});
2828
}
2929

src/entities/SubscriptionSet.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,16 @@ export class SubscriptionSet extends SubscribeCapable {
3131
this.options = subscriptionOptions;
3232
this.eventEmitter = eventEmitter;
3333
this.pubnub = pubnub;
34-
channels
35-
.filter((c) => !c.endsWith('-pnpres'))
36-
.forEach((c) => {
37-
const subscription = this.pubnub.channel(c).subscription(this.options);
38-
this.channelNames = [...this.channelNames, ...subscription.channels];
39-
this.subscriptionList.push(subscription);
40-
});
41-
channelGroups
42-
.filter((cg) => !cg.endsWith('-pnpres'))
43-
.forEach((cg) => {
44-
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
45-
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
46-
this.subscriptionList.push(subscription);
47-
});
34+
channels.forEach((c) => {
35+
const subscription = this.pubnub.channel(c).subscription(this.options);
36+
this.channelNames = [...this.channelNames, ...subscription.channels];
37+
this.subscriptionList.push(subscription);
38+
});
39+
channelGroups.forEach((cg) => {
40+
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
41+
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
42+
this.subscriptionList.push(subscription);
43+
});
4844
this.listener = {};
4945
eventEmitter.addListener(
5046
this.listener,

test/integration/endpoints/subscribe.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('subscribe endpoints', () => {
249249
subscription.subscribe({ timetoken: '1234567890' });
250250
});
251251

252-
it.only('signal listener called for string signal', (done) => {
252+
it('signal listener called for string signal', (done) => {
253253
utils
254254
.createNock()
255255
.get('/v2/subscribe/mySubKey/c1/0')
@@ -290,4 +290,47 @@ describe('subscribe endpoints', () => {
290290
const subscription = channel.subscription();
291291
subscription.subscribe();
292292
});
293+
294+
it('supports subscribe() with presence channelnames', () => {
295+
const scope0 = utils
296+
.createNock()
297+
.get('/v2/subscribe/mySubKey/c1,c2-pnpres/0')
298+
.query({
299+
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
300+
uuid: 'myUUID',
301+
ee: '',
302+
tt: 0,
303+
})
304+
.reply(
305+
200,
306+
'{"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"}]}',
307+
{ 'content-type': 'text/javascript' },
308+
);
309+
const scope = utils
310+
.createNock()
311+
.get('/v2/subscribe/mySubKey/c1,c2-pnpres/0')
312+
.query({
313+
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
314+
uuid: 'myUUID',
315+
ee: '',
316+
tt: '1234567890',
317+
tr: 1,
318+
})
319+
.reply(
320+
200,
321+
'{"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"}]}',
322+
{ 'content-type': 'text/javascript' },
323+
);
324+
325+
const subsripptionSetWithPresenceChannels = pubnubWithEE.subscriptionSet({
326+
channels: ['c1', 'c2-pnpres'],
327+
});
328+
329+
subsripptionSetWithPresenceChannels.subscribe();
330+
331+
assert.deepEqual(pubnubWithEE.getSubscribedChannels(), ['c1', 'c2-pnpres']);
332+
333+
subsripptionSetWithPresenceChannels.unsubscribe();
334+
assert.deepEqual(pubnubWithEE.getSubscribedChannels(), []);
335+
});
293336
});

0 commit comments

Comments
 (0)