Skip to content

Commit cf5aa71

Browse files
authored
Fix missing presence events on subscription (pubnub#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.

0 commit comments

Comments
 (0)