Skip to content

Commit cf5aa71

Browse files
authored
Fix missing presence events on subscription (#419)
fix(event-engine): fix missing presence events on subscription Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners).
1 parent 2b523b2 commit cf5aa71

23 files changed

+83
-58
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-11-18
4+
version: v8.3.1
5+
changes:
6+
- type: bug
7+
text: "Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners)."
38
- date: 2024-11-14
49
version: v8.3.0
510
changes:
@@ -1067,7 +1072,7 @@ supported-platforms:
10671072
- 'Ubuntu 14.04 and up'
10681073
- 'Windows 7 and up'
10691074
version: 'Pubnub Javascript for Node'
1070-
version: '8.3.0'
1075+
version: '8.3.1'
10711076
sdks:
10721077
- full-name: PubNub Javascript SDK
10731078
short-name: Javascript
@@ -1083,7 +1088,7 @@ sdks:
10831088
- distribution-type: source
10841089
distribution-repository: GitHub release
10851090
package-name: pubnub.js
1086-
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.0.zip
1091+
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.1.zip
10871092
requires:
10881093
- name: 'agentkeepalive'
10891094
min-version: '3.5.2'
@@ -1754,7 +1759,7 @@ sdks:
17541759
- distribution-type: library
17551760
distribution-repository: GitHub release
17561761
package-name: pubnub.js
1757-
location: https://github.com/pubnub/javascript/releases/download/v8.3.0/pubnub.8.3.0.js
1762+
location: https://github.com/pubnub/javascript/releases/download/v8.3.1/pubnub.8.3.1.js
17581763
requires:
17591764
- name: 'agentkeepalive'
17601765
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.3.1
2+
November 18 2024
3+
4+
#### Fixed
5+
- Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners).
6+
17
## v8.3.0
28
November 14 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.3.0.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@
39483948
return base.PubNubFile;
39493949
},
39503950
get version() {
3951-
return '8.3.0';
3951+
return '8.3.1';
39523952
},
39533953
getVersion() {
39543954
return this.version;
@@ -6403,6 +6403,7 @@
64036403
* @param event - Received real-time event.
64046404
*/
64056405
emitEvent(event) {
6406+
var _a;
64066407
if (event.type === PubNubEventType.Message) {
64076408
this.listenerManager.announceMessage(event.data);
64086409
this.announce('message', event.data, event.data.channel, event.data.subscription);
@@ -6413,7 +6414,7 @@
64136414
}
64146415
else if (event.type === PubNubEventType.Presence) {
64156416
this.listenerManager.announcePresence(event.data);
6416-
this.announce('presence', event.data, event.data.channel, event.data.subscription);
6417+
this.announce('presence', event.data, (_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel, event.data.subscription);
64176418
}
64186419
else if (event.type === PubNubEventType.AppContext) {
64196420
const { data: objectEvent } = event;
@@ -9963,7 +9964,7 @@
99639964
* types of events.
99649965
*/
99659966
addListener(listener) {
9966-
this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
9967+
this.eventEmitter.addListener(listener, this.channelNames, this.groupNames);
99679968
}
99689969
/**
99699970
* Remove events handler.
@@ -10065,7 +10066,7 @@
1006510066
this.subscriptionList.push(subscription);
1006610067
});
1006710068
this.listener = {};
10068-
eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
10069+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
1006910070
}
1007010071
/**
1007110072
* Add additional entity's subscription to the subscription set.
@@ -10187,7 +10188,7 @@
1018710188
this.pubnub = pubnub;
1018810189
this.eventEmitter = eventEmitter;
1018910190
this.listener = {};
10190-
eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
10191+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
1019110192
}
1019210193
/**
1019310194
* Merge entities' subscription objects into subscription set.
@@ -10283,9 +10284,12 @@
1028310284
*/
1028410285
subscription(subscriptionOptions) {
1028510286
{
10287+
const channelGroups = [this.name];
10288+
if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres'))
10289+
channelGroups.push(`${this.name}-pnpres`);
1028610290
return new Subscription({
1028710291
channels: [],
10288-
channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name],
10292+
channelGroups,
1028910293
subscriptionOptions: subscriptionOptions,
1029010294
eventEmitter: this.eventEmitter,
1029110295
pubnub: this.pubnub,
@@ -10370,8 +10374,11 @@
1037010374
*/
1037110375
subscription(subscriptionOptions) {
1037210376
{
10377+
const channels = [this.name];
10378+
if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres'))
10379+
channels.push(`${this.name}-pnpres`);
1037310380
return new Subscription({
10374-
channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name],
10381+
channels,
1037510382
channelGroups: [],
1037610383
subscriptionOptions: subscriptionOptions,
1037710384
eventEmitter: this.eventEmitter,

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
@@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
112112
return base.PubNubFile;
113113
},
114114
get version() {
115-
return '8.3.0';
115+
return '8.3.1';
116116
},
117117
getVersion() {
118118
return this.version;

lib/core/components/eventEmitter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EventEmitter {
4545
* @param event - Received real-time event.
4646
*/
4747
emitEvent(event) {
48+
var _a;
4849
if (event.type === subscribe_1.PubNubEventType.Message) {
4950
this.listenerManager.announceMessage(event.data);
5051
this.announce('message', event.data, event.data.channel, event.data.subscription);
@@ -55,7 +56,7 @@ class EventEmitter {
5556
}
5657
else if (event.type === subscribe_1.PubNubEventType.Presence) {
5758
this.listenerManager.announcePresence(event.data);
58-
this.announce('presence', event.data, event.data.channel, event.data.subscription);
59+
this.announce('presence', event.data, (_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel, event.data.subscription);
5960
}
6061
else if (event.type === subscribe_1.PubNubEventType.AppContext) {
6162
const { data: objectEvent } = event;

lib/entities/Channel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ class Channel {
3434
*/
3535
subscription(subscriptionOptions) {
3636
if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') {
37+
const channels = [this.name];
38+
if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres'))
39+
channels.push(`${this.name}-pnpres`);
3740
return new Subscription_1.Subscription({
38-
channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name],
41+
channels,
3942
channelGroups: [],
4043
subscriptionOptions: subscriptionOptions,
4144
eventEmitter: this.eventEmitter,

lib/entities/ChannelGroup.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ class ChannelGroup {
3535
*/
3636
subscription(subscriptionOptions) {
3737
if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') {
38+
const channelGroups = [this.name];
39+
if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres'))
40+
channelGroups.push(`${this.name}-pnpres`);
3841
return new Subscription_1.Subscription({
3942
channels: [],
40-
channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name],
43+
channelGroups,
4144
subscriptionOptions: subscriptionOptions,
4245
eventEmitter: this.eventEmitter,
4346
pubnub: this.pubnub,

lib/entities/SubscribeCapable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SubscribeCapable {
8282
* types of events.
8383
*/
8484
addListener(listener) {
85-
this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
85+
this.eventEmitter.addListener(listener, this.channelNames, this.groupNames);
8686
}
8787
/**
8888
* Remove events handler.

lib/entities/Subscription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable {
5353
this.pubnub = pubnub;
5454
this.eventEmitter = eventEmitter;
5555
this.listener = {};
56-
eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
56+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
5757
}
5858
/**
5959
* Merge entities' subscription objects into subscription set.

lib/entities/SubscriptionSet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable {
7474
this.subscriptionList.push(subscription);
7575
});
7676
this.listener = {};
77-
eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres')));
77+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
7878
}
7979
/**
8080
* Add additional entity's subscription to the subscription set.

package-lock.json

Lines changed: 3 additions & 3 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.3.0",
3+
"version": "8.3.1",
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
@@ -171,7 +171,7 @@ export const makeConfiguration = (
171171
return base.PubNubFile;
172172
},
173173
get version(): string {
174-
return '8.3.0';
174+
return '8.3.1';
175175
},
176176
getVersion(): string {
177177
return this.version;

src/core/components/eventEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class EventEmitter {
4545
this.announce('signal', event.data, event.data.channel, event.data.subscription);
4646
} else if (event.type === PubNubEventType.Presence) {
4747
this.listenerManager.announcePresence(event.data);
48-
this.announce('presence', event.data, event.data.channel, event.data.subscription);
48+
this.announce('presence', event.data, event.data.subscription ?? event.data.channel, event.data.subscription);
4949
} else if (event.type === PubNubEventType.AppContext) {
5050
const { data: objectEvent } = event;
5151
const { message: object } = objectEvent;

src/entities/Channel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ export class Channel {
5757
*/
5858
subscription(subscriptionOptions?: SubscriptionOptions) {
5959
if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') {
60+
const channels = [this.name];
61+
if (subscriptionOptions?.receivePresenceEvents && !this.name.endsWith('-pnpres'))
62+
channels.push(`${this.name}-pnpres`);
63+
6064
return new Subscription({
61-
channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name],
65+
channels,
6266
channelGroups: [],
6367
subscriptionOptions: subscriptionOptions,
6468
eventEmitter: this.eventEmitter,

src/entities/ChannelGroup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ export class ChannelGroup {
5959
*/
6060
subscription(subscriptionOptions?: SubscriptionOptions) {
6161
if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') {
62+
const channelGroups = [this.name];
63+
if (subscriptionOptions?.receivePresenceEvents && !this.name.endsWith('-pnpres'))
64+
channelGroups.push(`${this.name}-pnpres`);
65+
6266
return new Subscription({
6367
channels: [],
64-
channelGroups: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name],
68+
channelGroups,
6569
subscriptionOptions: subscriptionOptions,
6670
eventEmitter: this.eventEmitter,
6771
pubnub: this.pubnub,

src/entities/SubscribeCapable.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ export abstract class SubscribeCapable {
141141
* types of events.
142142
*/
143143
addListener(listener: Listener) {
144-
this.eventEmitter.addListener(
145-
listener,
146-
this.channelNames.filter((c) => !c.endsWith('-pnpres')),
147-
this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
148-
);
144+
this.eventEmitter.addListener(listener, this.channelNames, this.groupNames);
149145
}
150146

151147
/**

src/entities/Subscription.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ export class Subscription extends SubscribeCapable {
9999
this.pubnub = pubnub;
100100
this.eventEmitter = eventEmitter;
101101
this.listener = {};
102-
eventEmitter.addListener(
103-
this.listener,
104-
this.channelNames.filter((c) => !c.endsWith('-pnpres')),
105-
this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
106-
);
102+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
107103
}
108104

109105
/**

src/entities/SubscriptionSet.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ export class SubscriptionSet extends SubscribeCapable {
123123
this.subscriptionList.push(subscription);
124124
});
125125
this.listener = {};
126-
eventEmitter.addListener(
127-
this.listener,
128-
this.channelNames.filter((c) => !c.endsWith('-pnpres')),
129-
this.groupNames.filter((cg) => !cg.endsWith('-pnpres')),
130-
);
126+
eventEmitter.addListener(this.listener, this.channelNames, this.groupNames);
131127
}
132128

133129
/**

test/integration/endpoints/fetch_messages.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,16 @@ describe('fetch messages endpoints', () => {
355355
assert(errorCatched);
356356
});
357357

358-
it.only('supports custom message type', (done) => {
358+
it('supports custom message type', (done) => {
359359
const channel = PubNub.generateUUID();
360360
const expectedMessagesCount = 2;
361361

362362
publishMessagesToChannel(pubnub, expectedMessagesCount, channel, 'test-message-type', (messages) => {
363363
const messageTimetokens = messages.map((message) => message.timetoken);
364364

365365
pubnub.fetchMessages({ channels: [channel], includeCustomMessageType: true }, (status, response) => {
366+
assert.equal(status.error, false, `Fetch messages error: ${JSON.stringify(status.errorData)}`);
367+
366368
try {
367369
assert.equal(status.error, false);
368370
assert(response !== null);

test/integration/endpoints/publish.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('publish endpoints', () => {
210210
});
211211
});
212212

213-
it('supports customMessageType', (done) => {
213+
it.only('supports customMessageType', (done) => {
214214
const scope = utils
215215
.createNock()
216216
.get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D')
@@ -219,22 +219,24 @@ describe('publish endpoints', () => {
219219
uuid: 'myUUID',
220220
auth: 'myAuthKey',
221221
store: '0',
222+
custom_message_type: 'test-message-type',
222223
})
223224
.reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' });
224225

225-
pubnub.setCipherKey('myCipherKey');
226-
227-
pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, (status, response) => {
228-
try {
229-
assert.equal(status.error, false);
230-
assert(response !== null);
231-
assert.deepEqual(response.timetoken, '14647523059145592');
232-
assert.equal(scope.isDone(), true);
233-
done();
234-
} catch (error) {
235-
done(error);
236-
}
237-
});
226+
pubnub.publish(
227+
{ message: { such: 'object' }, channel: 'ch1', storeInHistory: false, customMessageType: 'test-message-type' },
228+
(status, response) => {
229+
try {
230+
assert.equal(status.error, false, `Message publish error: ${JSON.stringify(status.errorData)}`);
231+
assert(response !== null);
232+
assert.deepEqual(response.timetoken, '14647523059145592');
233+
assert.equal(scope.isDone(), true);
234+
done();
235+
} catch (error) {
236+
done(error);
237+
}
238+
},
239+
);
238240
});
239241

240242
it('publishes a complex object via POST', (done) => {

0 commit comments

Comments
 (0)