Skip to content

Commit a73bc58

Browse files
feat: new listener interface (#359)
* added `Channel`, `ChannelGroup`, `ChannelMetadata`, `UserMetadata`, `Subscription`, `SubscriptionSet` entities definitions * added factory function at PubNub and implementation at EventEmitter to support new listener interface * lib/dist * * test: adding channel, channelGroup, subscription, SubscriptionSet listenr tests * fix: unique channel and groups for subscription, no telemetry for event engine, avoid duplicate listener registration * dist/lib * refactored listeners tests with callback style * take-1: commented new tests * Update run-tests.yml * fix: telemetry condition to add query param * lib/dist * fix: lint * reverted workflow file changes * restore all previous changes of telemetry * dist/lib * *remove unncessary subscriptionOptions prop. * added support for subscriptionSet operations * lib/dist * refactor: naming convention in subscriptionSet class * no presence subscription for channel metadata * fix channles and groups initialisation in constructor * refactor: subscriptionSet will get constructed in form of set of subscriptions when channels/groups set is provided * handling overlapping or unique channels/groups subscribe/unsubscribe with new listener/entity interface * tests and utils * lib/dist * test/ cleanup after test * refactor/fix: new listeners backward compatible to old subscription loop * dist/lib * fix typo in argument * dist/lib * attemp to address Codacy reported warnings * lint! * Codacy warnings fix * Codacy warning fix * added support for event specific listener registration. * refactor subscription/subscriptionSet class definition through common abstract class. * dist/lib * fix: test flakiness * PubNub SDK v7.6.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent f0bd4e5 commit a73bc58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2128
-807
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ jobs:
5353
needs: [tests]
5454
steps:
5555
- name: Tests summary
56-
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
56+
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"

.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-02-21
4+
version: v7.6.0
5+
changes:
6+
- type: feature
7+
text: "Adding channel, channelGroup, channelMetadata and userMetadata entities to be first-class citizens to access APIs related to them. Currently, access is provided only for subscription API."
38
- date: 2024-01-16
49
version: v7.5.0
510
changes:
@@ -938,7 +943,7 @@ supported-platforms:
938943
- 'Ubuntu 14.04 and up'
939944
- 'Windows 7 and up'
940945
version: 'Pubnub Javascript for Node'
941-
version: '7.5.0'
946+
version: '7.6.0'
942947
sdks:
943948
- full-name: PubNub Javascript SDK
944949
short-name: Javascript
@@ -954,7 +959,7 @@ sdks:
954959
- distribution-type: source
955960
distribution-repository: GitHub release
956961
package-name: pubnub.js
957-
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.5.0.zip
962+
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.0.zip
958963
requires:
959964
- name: 'agentkeepalive'
960965
min-version: '3.5.2'
@@ -1625,7 +1630,7 @@ sdks:
16251630
- distribution-type: library
16261631
distribution-repository: GitHub release
16271632
package-name: pubnub.js
1628-
location: https://github.com/pubnub/javascript/releases/download/v7.5.0/pubnub.7.5.0.js
1633+
location: https://github.com/pubnub/javascript/releases/download/v7.6.0/pubnub.7.6.0.js
16291634
requires:
16301635
- name: 'agentkeepalive'
16311636
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+
## v7.6.0
2+
February 21 2024
3+
4+
#### Added
5+
- Adding channel, channelGroup, channelMetadata and userMetadata entities to be first-class citizens to access APIs related to them. Currently, access is provided only for subscription API.
6+
17
## v7.5.0
28
January 16 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.7.5.0.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.5.0.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 477 additions & 301 deletions
Large diffs are not rendered by default.

dist/web/pubnub.min.js

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

lib/core/components/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () {
180180
return this;
181181
};
182182
default_1.prototype.getVersion = function () {
183-
return '7.5.0';
183+
return '7.6.0';
184184
};
185185
default_1.prototype._setRetryConfiguration = function (configuration) {
186186
if (configuration.minimumdelay < 2) {

lib/core/components/eventEmitter.js

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var EventEmitter = /** @class */ (function () {
2828
this.modules = modules;
2929
this.listenerManager = listenerManager;
3030
this.getFileUrl = getFileUrl;
31+
this._channelListenerMap = new Map();
32+
this._groupListenerMap = new Map();
3133
if (modules.cryptoModule)
3234
this._decoder = new TextDecoder();
3335
}
@@ -62,7 +64,12 @@ var EventEmitter = /** @class */ (function () {
6264
if (e.payload.timeout) {
6365
announce.timeout = e.payload.timeout;
6466
}
67+
// deprecated -->
68+
announce.actualChannel = subscriptionMatch != null ? channel : null;
69+
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
70+
// <-- deprecated
6571
this.listenerManager.announcePresence(announce);
72+
this._announce('presence', announce, announce.channel, announce.subscription);
6673
}
6774
else if (e.messageType === 1) {
6875
var announce = {};
@@ -77,6 +84,7 @@ var EventEmitter = /** @class */ (function () {
7784
}
7885
announce.message = e.payload;
7986
this.listenerManager.announceSignal(announce);
87+
this._announce('signal', announce, announce.channel, announce.subscription);
8088
}
8189
else if (e.messageType === 2) {
8290
var announce = {};
@@ -95,20 +103,27 @@ var EventEmitter = /** @class */ (function () {
95103
data: e.payload.data,
96104
};
97105
this.listenerManager.announceObjects(announce);
106+
this._announce('objects', announce, announce.channel, announce.subscription);
98107
if (e.payload.type === 'uuid') {
99108
var eventData = this._renameChannelField(announce);
100-
this.listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }));
109+
var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) });
110+
this.listenerManager.announceUser(userEvent);
111+
this._announce('user', userEvent, announce.channel, announce.subscription);
101112
}
102113
else if (message.payload.type === 'channel') {
103114
var eventData = this._renameChannelField(announce);
104-
this.listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }));
115+
var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) });
116+
this.listenerManager.announceSpace(spaceEvent);
117+
this._announce('space', spaceEvent, announce.channel, announce.subscription);
105118
}
106119
else if (message.payload.type === 'membership') {
107120
var eventData = this._renameChannelField(announce);
108121
var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]);
109122
membershipData.user = user;
110123
membershipData.space = space;
111-
this.listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }));
124+
var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) });
125+
this.listenerManager.announceMembership(membershipEvent);
126+
this._announce('membership', membershipEvent, announce.channel, announce.subscription);
112127
}
113128
}
114129
else if (e.messageType === 3) {
@@ -126,6 +141,7 @@ var EventEmitter = /** @class */ (function () {
126141
};
127142
announce.event = e.payload.event;
128143
this.listenerManager.announceMessageAction(announce);
144+
this._announce('messageAction', announce, announce.channel, announce.subscription);
129145
}
130146
else if (e.messageType === 4) {
131147
var announce = {};
@@ -163,6 +179,7 @@ var EventEmitter = /** @class */ (function () {
163179
}),
164180
};
165181
this.listenerManager.announceFile(announce);
182+
this._announce('file', announce, announce.channel, announce.subscription);
166183
}
167184
else {
168185
var announce = {};
@@ -196,9 +213,59 @@ var EventEmitter = /** @class */ (function () {
196213
else {
197214
announce.message = e.payload;
198215
}
216+
// deprecated -->
217+
announce.actualChannel = subscriptionMatch != null ? channel : null;
218+
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
219+
// <-- deprecated
199220
this.listenerManager.announceMessage(announce);
221+
this._announce('message', announce, announce.channel, announce.subscription);
200222
}
201223
};
224+
EventEmitter.prototype.addListener = function (l, channels, groups) {
225+
var _this = this;
226+
if (!(channels && groups)) {
227+
this.listenerManager.addListener(l);
228+
}
229+
else {
230+
channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) {
231+
if (_this._channelListenerMap[c]) {
232+
if (!_this._channelListenerMap[c].includes(l))
233+
_this._channelListenerMap[c].push(l);
234+
}
235+
else {
236+
_this._channelListenerMap[c] = [l];
237+
}
238+
});
239+
groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) {
240+
if (_this._groupListenerMap[g]) {
241+
if (!_this._groupListenerMap[g].includes(l))
242+
_this._groupListenerMap[g].push(l);
243+
}
244+
else {
245+
_this._groupListenerMap[g] = [l];
246+
}
247+
});
248+
}
249+
};
250+
EventEmitter.prototype.removeListener = function (listener, channels, groups) {
251+
var _this = this;
252+
if (!(channels && groups)) {
253+
this.listenerManager.removeListener(listener);
254+
}
255+
else {
256+
channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) {
257+
var _a;
258+
_this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; });
259+
});
260+
groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) {
261+
var _a;
262+
_this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; });
263+
});
264+
}
265+
};
266+
EventEmitter.prototype.removeAllListeners = function () {
267+
this.listenerManager.removeAllListeners();
268+
};
202269
EventEmitter.prototype._renameEvent = function (e) {
203270
return e === 'set' ? 'updated' : 'removed';
204271
};
@@ -207,6 +274,11 @@ var EventEmitter = /** @class */ (function () {
207274
eventData.spaceId = channel;
208275
return eventData;
209276
};
277+
EventEmitter.prototype._announce = function (type, event, channel, group) {
278+
var _a, _b;
279+
(_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); });
280+
(_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); });
281+
};
210282
return EventEmitter;
211283
}());
212284
exports.default = EventEmitter;

0 commit comments

Comments
 (0)