Skip to content

Commit

Permalink
* add/remove listener from subscription to subscriptionSet.
Browse files Browse the repository at this point in the history
* fixed additional entity name with pnpres being added while creating subscriptionSet
  • Loading branch information
mohitpubnub committed Apr 17, 2024
1 parent 8d9d8c2 commit 8dfc09d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
12 changes: 10 additions & 2 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8432,12 +8432,16 @@
_this.options = subscriptionOptions;
_this.eventEmitter = eventEmitter;
_this.pubnub = pubnub;
channels.forEach(function (c) {
channels
.filter(function (c) { return !c.endsWith('-pnpres'); })
.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) {
channelGroups
.filter(function (cg) { return !cg.endsWith('-pnpres'); })
.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);
Expand All @@ -8450,25 +8454,29 @@
this.subscriptionList.push(subscription);
this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false);
this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false);
this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups);
};
SubscriptionSet.prototype.removeSubscription = function (subscription) {
var channelsToRemove = subscription.channels;
var groupsToRemove = subscription.channelGroups;
this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); });
this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); });
this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; });
this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove);
};
SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) {
this.subscriptionList = __spreadArray$1(__spreadArray$1([], __read$1(this.subscriptionList), false), __read$1(subscriptionSet.subscriptions), false);
this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscriptionSet.channels), false);
this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscriptionSet.channelGroups), false);
this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups);
};
SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) {
var channelsToRemove = subscriptionSet.channels;
var groupsToRemove = subscriptionSet.channelGroups;
this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); });
this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); });
this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); });
this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove);
};
Object.defineProperty(SubscriptionSet.prototype, "subscriptions", {
get: function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/entities/SubscriptionSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ export class SubscriptionSet extends SubscribeCapable {
this.options = subscriptionOptions;
this.eventEmitter = eventEmitter;
this.pubnub = pubnub;
channels.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
});
channels
.filter((c) => !c.endsWith('-pnpres'))
.forEach((c) => {
const subscription = this.pubnub.channel(c).subscription(this.options);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.subscriptionList.push(subscription);
});
channelGroups
.filter((cg) => !cg.endsWith('-pnpres'))
.forEach((cg) => {
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.subscriptionList.push(subscription);
});
this.listener = {};
eventEmitter.addListener(
this.listener,
Expand All @@ -51,6 +55,7 @@ export class SubscriptionSet extends SubscribeCapable {
this.subscriptionList.push(subscription);
this.channelNames = [...this.channelNames, ...subscription.channels];
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups);
}

removeSubscription(subscription: Subscription) {
Expand All @@ -59,12 +64,14 @@ export class SubscriptionSet extends SubscribeCapable {
this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c));
this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg));
this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription);
this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove);
}

addSubscriptionSet(subscriptionSet: SubscriptionSet) {
this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions];
this.channelNames = [...this.channelNames, ...subscriptionSet.channels];
this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups];
this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups);
}

removeSubscriptionSet(subscriptionSet: SubscriptionSet) {
Expand All @@ -73,6 +80,7 @@ export class SubscriptionSet extends SubscribeCapable {
this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c));
this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg));
this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s));
this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove);
}

get subscriptions(): Subscription[] {
Expand Down

0 comments on commit 8dfc09d

Please sign in to comment.