Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new listener interface #359

Merged
merged 36 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
459441a
added `Channel`, `ChannelGroup`, `ChannelMetadata`, `UserMetadata`, `…
mohitpubnub Feb 2, 2024
5302aa8
added factory function at PubNub and implementation at EventEmitter t…
mohitpubnub Feb 2, 2024
06d61dc
lib/dist
mohitpubnub Feb 2, 2024
7a7d1e7
* test: adding channel, channelGroup, subscription, SubscriptionSet l…
mohitpubnub Feb 5, 2024
f735cf2
dist/lib
mohitpubnub Feb 5, 2024
ca3817a
refactored listeners tests with callback style
mohitpubnub Feb 5, 2024
1ce7df6
take-1: commented new tests
mohitpubnub Feb 5, 2024
9c6462f
Update run-tests.yml
mohitpubnub Feb 5, 2024
2fd360e
fix: telemetry condition to add query param
mohitpubnub Feb 5, 2024
5ac554e
lib/dist
mohitpubnub Feb 5, 2024
6900f7b
fix: lint
mohitpubnub Feb 5, 2024
dfff6b6
reverted workflow file changes
mohitpubnub Feb 5, 2024
528fab0
restore all previous changes of telemetry
mohitpubnub Feb 5, 2024
f3cab86
dist/lib
mohitpubnub Feb 5, 2024
018cccb
*remove unncessary subscriptionOptions prop. * added support for subs…
mohitpubnub Feb 5, 2024
419bdb5
lib/dist
mohitpubnub Feb 5, 2024
2704e97
refactor: naming convention in subscriptionSet class
mohitpubnub Feb 5, 2024
6d95a3a
no presence subscription for channel metadata
mohitpubnub Feb 5, 2024
2f3147f
fix channles and groups initialisation in constructor
mohitpubnub Feb 5, 2024
7881ca7
refactor: subscriptionSet will get constructed in form of set of subs…
mohitpubnub Feb 12, 2024
c2eba9e
handling overlapping or unique channels/groups subscribe/unsubscribe …
mohitpubnub Feb 12, 2024
0b075f5
tests and utils
mohitpubnub Feb 12, 2024
b93f956
lib/dist
mohitpubnub Feb 12, 2024
6f22576
test/ cleanup after test
mohitpubnub Feb 12, 2024
ba806b5
refactor/fix: new listeners backward compatible to old subscription loop
mohitpubnub Feb 14, 2024
84df509
dist/lib
mohitpubnub Feb 14, 2024
01ab430
fix typo in argument
mohitpubnub Feb 14, 2024
ae8ab37
dist/lib
mohitpubnub Feb 14, 2024
3022d55
attemp to address Codacy reported warnings
mohitpubnub Feb 14, 2024
f1e266d
lint!
mohitpubnub Feb 14, 2024
6739d5c
Codacy warnings fix
mohitpubnub Feb 14, 2024
c4aa459
Codacy warning fix
mohitpubnub Feb 14, 2024
50dd6dd
added support for event specific listener registration.
mohitpubnub Feb 19, 2024
84eb2d9
dist/lib
mohitpubnub Feb 19, 2024
19daad6
fix: test flakiness
mohitpubnub Feb 19, 2024
9b5dee8
PubNub SDK v7.6.0 release.
pubnub-release-bot Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
needs: [tests]
steps:
- name: Tests summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
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-02-21
version: v7.6.0
changes:
- type: feature
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."
- date: 2024-01-16
version: v7.5.0
changes:
Expand Down Expand Up @@ -938,7 +943,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '7.5.0'
version: '7.6.0'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -954,7 +959,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.5.0.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.0.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1625,7 +1630,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v7.5.0/pubnub.7.5.0.js
location: https://github.com/pubnub/javascript/releases/download/v7.6.0/pubnub.7.6.0.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 @@
## v7.6.0
February 21 2024

#### Added
- 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.

## v7.5.0
January 16 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.7.5.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.5.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.min.js

2. Configure your keys:

Expand Down
778 changes: 477 additions & 301 deletions dist/web/pubnub.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () {
return this;
};
default_1.prototype.getVersion = function () {
return '7.5.0';
return '7.6.0';
};
default_1.prototype._setRetryConfiguration = function (configuration) {
if (configuration.minimumdelay < 2) {
Expand Down
78 changes: 75 additions & 3 deletions lib/core/components/eventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var EventEmitter = /** @class */ (function () {
this.modules = modules;
this.listenerManager = listenerManager;
this.getFileUrl = getFileUrl;
this._channelListenerMap = new Map();
this._groupListenerMap = new Map();
if (modules.cryptoModule)
this._decoder = new TextDecoder();
}
Expand Down Expand Up @@ -62,7 +64,12 @@ var EventEmitter = /** @class */ (function () {
if (e.payload.timeout) {
announce.timeout = e.payload.timeout;
}
// deprecated -->
announce.actualChannel = subscriptionMatch != null ? channel : null;
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
// <-- deprecated
this.listenerManager.announcePresence(announce);
this._announce('presence', announce, announce.channel, announce.subscription);
}
else if (e.messageType === 1) {
var announce = {};
Expand All @@ -77,6 +84,7 @@ var EventEmitter = /** @class */ (function () {
}
announce.message = e.payload;
this.listenerManager.announceSignal(announce);
this._announce('signal', announce, announce.channel, announce.subscription);
}
else if (e.messageType === 2) {
var announce = {};
Expand All @@ -95,20 +103,27 @@ var EventEmitter = /** @class */ (function () {
data: e.payload.data,
};
this.listenerManager.announceObjects(announce);
this._announce('objects', announce, announce.channel, announce.subscription);
if (e.payload.type === 'uuid') {
var eventData = this._renameChannelField(announce);
this.listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }));
var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) });
this.listenerManager.announceUser(userEvent);
this._announce('user', userEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'channel') {
var eventData = this._renameChannelField(announce);
this.listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }));
var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) });
this.listenerManager.announceSpace(spaceEvent);
this._announce('space', spaceEvent, announce.channel, announce.subscription);
}
else if (message.payload.type === 'membership') {
var eventData = this._renameChannelField(announce);
var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]);
membershipData.user = user;
membershipData.space = space;
this.listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }));
var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) });
this.listenerManager.announceMembership(membershipEvent);
this._announce('membership', membershipEvent, announce.channel, announce.subscription);
}
}
else if (e.messageType === 3) {
Expand All @@ -126,6 +141,7 @@ var EventEmitter = /** @class */ (function () {
};
announce.event = e.payload.event;
this.listenerManager.announceMessageAction(announce);
this._announce('messageAction', announce, announce.channel, announce.subscription);
}
else if (e.messageType === 4) {
var announce = {};
Expand Down Expand Up @@ -163,6 +179,7 @@ var EventEmitter = /** @class */ (function () {
}),
};
this.listenerManager.announceFile(announce);
this._announce('file', announce, announce.channel, announce.subscription);
}
else {
var announce = {};
Expand Down Expand Up @@ -196,9 +213,59 @@ var EventEmitter = /** @class */ (function () {
else {
announce.message = e.payload;
}
// deprecated -->
announce.actualChannel = subscriptionMatch != null ? channel : null;
announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel;
// <-- deprecated
this.listenerManager.announceMessage(announce);
this._announce('message', announce, announce.channel, announce.subscription);
}
};
EventEmitter.prototype.addListener = function (l, channels, groups) {
var _this = this;
if (!(channels && groups)) {
this.listenerManager.addListener(l);
}
else {
channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) {
if (_this._channelListenerMap[c]) {
if (!_this._channelListenerMap[c].includes(l))
_this._channelListenerMap[c].push(l);
}
else {
_this._channelListenerMap[c] = [l];
}
});
groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) {
if (_this._groupListenerMap[g]) {
if (!_this._groupListenerMap[g].includes(l))
_this._groupListenerMap[g].push(l);
}
else {
_this._groupListenerMap[g] = [l];
}
});
}
};
EventEmitter.prototype.removeListener = function (listener, channels, groups) {
var _this = this;
if (!(channels && groups)) {
this.listenerManager.removeListener(listener);
}
else {
channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) {
var _a;
_this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; });
});
groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) {
var _a;
_this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; });
});
}
};
EventEmitter.prototype.removeAllListeners = function () {
this.listenerManager.removeAllListeners();
};
EventEmitter.prototype._renameEvent = function (e) {
return e === 'set' ? 'updated' : 'removed';
};
Expand All @@ -207,6 +274,11 @@ var EventEmitter = /** @class */ (function () {
eventData.spaceId = channel;
return eventData;
};
EventEmitter.prototype._announce = function (type, event, channel, group) {
var _a, _b;
(_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); });
(_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); });
};
return EventEmitter;
}());
exports.default = EventEmitter;
Loading
Loading