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

fix: add-remove-subscription-listener-to-set #368

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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-04-18
version: v7.6.3
changes:
- type: bug
text: "Fixes issue of add or remove listener of subscription to/from subscriptionSet."
- date: 2024-03-28
version: v7.6.2
changes:
Expand Down Expand Up @@ -953,7 +958,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '7.6.2'
version: '7.6.3'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -969,7 +974,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.2.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.3.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1640,7 +1645,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v7.6.2/pubnub.7.6.2.js
location: https://github.com/pubnub/javascript/releases/download/v7.6.3/pubnub.7.6.3.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.3
April 18 2024

#### Fixed
- Fixes issue of add or remove listener of subscription to/from subscriptionSet.

## v7.6.2
March 28 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.6.2.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.2.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.min.js

2. Configure your keys:

Expand Down
14 changes: 11 additions & 3 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
return this;
};
default_1.prototype.getVersion = function () {
return '7.6.2';
return '7.6.3';
};
default_1.prototype._setRetryConfiguration = function (configuration) {
if (configuration.minimumdelay < 2) {
Expand Down 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.

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.6.2';
return '7.6.3';
};
default_1.prototype._setRetryConfiguration = function (configuration) {
if (configuration.minimumdelay < 2) {
Expand Down
12 changes: 10 additions & 2 deletions lib/entities/SubscriptionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ var SubscriptionSet = /** @class */ (function (_super) {
_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(__spreadArray([], __read(_this.channelNames), false), __read(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(__spreadArray([], __read(_this.groupNames), false), __read(subscription.channelGroups), false);
_this.subscriptionList.push(subscription);
Expand All @@ -71,25 +75,29 @@ var SubscriptionSet = /** @class */ (function (_super) {
this.subscriptionList.push(subscription);
this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false);
this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(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(__spreadArray([], __read(this.subscriptionList), false), __read(subscriptionSet.subscriptions), false);
this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscriptionSet.channels), false);
this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "7.6.2",
"version": "7.6.3",
"author": "PubNub <[email protected]>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export default class {
}

getVersion() {
return '7.6.2';
return '7.6.3';
}

_setRetryConfiguration(configuration) {
Expand Down
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
Loading