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 7 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
183 changes: 105 additions & 78 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8338,43 +8338,109 @@
return EventEmitter;
}());

var SubscriptionSet = /** @class */ (function () {
function SubscriptionSet(_a) {
var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub;
var _this = this;
this.channelNames = [];
this.groupNames = [];
this.subscriptionList = [];
this.options = subscriptionOptions;
this.eventEmitter = eventEmitter;
this.pubnub = pubnub;
channels.forEach(function (c) {
var subscription = _this.pubnub.channel(c).subscription(_this.options);
_this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.channelNames), false), __read$1(subscription.channels), false);
_this.subscriptionList.push(subscription);
});
channelGroups.forEach(function (cg) {
var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options);
_this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.groupNames), false), __read$1(subscription.channelGroups), false);
_this.subscriptionList.push(subscription);
});
var SubscribeCapable = /** @class */ (function () {
function SubscribeCapable() {
}
SubscriptionSet.prototype.subscribe = function () {
SubscribeCapable.prototype.subscribe = function () {
var _a, _b;
this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken })));
};
SubscriptionSet.prototype.unsubscribe = function () {
SubscribeCapable.prototype.unsubscribe = function () {
this.pubnub.unsubscribe({
channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }),
channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }),
});
};
SubscriptionSet.prototype.addListener = function (listener) {
Object.defineProperty(SubscribeCapable.prototype, "onMessage", {
set: function (onMessagelistener) {
this.listener.message = onMessagelistener;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "onPresence", {
set: function (onPresencelistener) {
this.listener.presence = onPresencelistener;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "onSignal", {
set: function (onSignalListener) {
this.listener.signal = onSignalListener;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "onObjects", {
set: function (onObjectsListener) {
this.listener.objects = onObjectsListener;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "onMessageAction", {
set: function (messageActionEventListener) {
this.listener.messageAction = messageActionEventListener;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "onFile", {
set: function (fileEventListener) {
this.listener.file = fileEventListener;
},
enumerable: false,
configurable: true
});
SubscribeCapable.prototype.addListener = function (listener) {
this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));
};
SubscriptionSet.prototype.removeListener = function (listener) {
SubscribeCapable.prototype.removeListener = function (listener) {
this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames);
};
Object.defineProperty(SubscribeCapable.prototype, "channels", {
get: function () {
return this.channelNames.slice(0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscribeCapable.prototype, "channelGroups", {
get: function () {
return this.groupNames.slice(0);
},
enumerable: false,
configurable: true
});
return SubscribeCapable;
}());

var SubscriptionSet = /** @class */ (function (_super) {
__extends(SubscriptionSet, _super);
function SubscriptionSet(_a) {
var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub;
var _this = _super.call(this) || this;
_this.channelNames = [];
_this.groupNames = [];
_this.subscriptionList = [];
_this.options = subscriptionOptions;
_this.eventEmitter = eventEmitter;
_this.pubnub = pubnub;
channels.forEach(function (c) {
var subscription = _this.pubnub.channel(c).subscription(_this.options);
_this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.channelNames), false), __read$1(subscription.channels), false);
_this.subscriptionList.push(subscription);
});
channelGroups.forEach(function (cg) {
var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options);
_this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.groupNames), false), __read$1(subscription.channelGroups), false);
_this.subscriptionList.push(subscription);
});
_this.listener = {};
eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));
return _this;
}
SubscriptionSet.prototype.addSubscription = function (subscription) {
this.subscriptionList.push(subscription);
this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false);
Expand All @@ -8399,20 +8465,6 @@
this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); });
this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); });
};
Object.defineProperty(SubscriptionSet.prototype, "channels", {
get: function () {
return this.channelNames.slice(0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscriptionSet.prototype, "channelGroups", {
get: function () {
return this.groupNames.slice(0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SubscriptionSet.prototype, "subscriptions", {
get: function () {
return this.subscriptionList.slice(0);
Expand All @@ -8421,35 +8473,24 @@
configurable: true
});
return SubscriptionSet;
}());
}(SubscribeCapable));

var Subscription = /** @class */ (function () {
var Subscription = /** @class */ (function (_super) {
__extends(Subscription, _super);
function Subscription(_a) {
var channels = _a.channels, channelGroups = _a.channelGroups, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub;
this.channelNames = [];
this.groupNames = [];
this.channelNames = channels;
this.groupNames = channelGroups;
this.options = subscriptionOptions;
this.pubnub = pubnub;
this.eventEmitter = eventEmitter;
var _this = _super.call(this) || this;
_this.channelNames = [];
_this.groupNames = [];
_this.channelNames = channels;
_this.groupNames = channelGroups;
_this.options = subscriptionOptions;
_this.pubnub = pubnub;
_this.eventEmitter = eventEmitter;
_this.listener = {};
eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));
return _this;
}
Subscription.prototype.subscribe = function () {
var _a, _b;
this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken })));
};
Subscription.prototype.unsubscribe = function () {
this.pubnub.unsubscribe({
channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }),
channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }),
});
};
Subscription.prototype.addListener = function (listener) {
this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));
};
Subscription.prototype.removeListener = function (listener) {
this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames);
};
Subscription.prototype.addSubscription = function (subscription) {
return new SubscriptionSet({
channels: __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false),
Expand All @@ -8459,22 +8500,8 @@
pubnub: this.pubnub,
});
};
Object.defineProperty(Subscription.prototype, "channels", {
get: function () {
return this.channelNames.slice(0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Subscription.prototype, "channelGroups", {
get: function () {
return this.groupNames.slice(0);
},
enumerable: false,
configurable: true
});
return Subscription;
}());
}(SubscribeCapable));

var Channel = /** @class */ (function () {
function Channel(channelName, eventEmitter, pubnub) {
Expand Down
Loading
Loading