Skip to content

Commit b93f956

Browse files
committed
lib/dist
1 parent 0b075f5 commit b93f956

File tree

6 files changed

+185
-106
lines changed

6 files changed

+185
-106
lines changed

dist/web/pubnub.js

Lines changed: 107 additions & 80 deletions
Large diffs are not rendered by default.

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/utils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
"use strict";
2+
var __read = (this && this.__read) || function (o, n) {
3+
var m = typeof Symbol === "function" && o[Symbol.iterator];
4+
if (!m) return o;
5+
var i = m.call(o), r, ar = [], e;
6+
try {
7+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8+
}
9+
catch (error) { e = { error: error }; }
10+
finally {
11+
try {
12+
if (r && !r.done && (m = i["return"])) m.call(i);
13+
}
14+
finally { if (e) throw e.error; }
15+
}
16+
return ar;
17+
};
18+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20+
if (ar || !(i in from)) {
21+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22+
ar[i] = from[i];
23+
}
24+
}
25+
return to.concat(ar || Array.prototype.slice.call(from));
26+
};
227
function objectToList(o) {
328
var l = [];
429
Object.keys(o).forEach(function (key) { return l.push(key); });
@@ -34,10 +59,27 @@ function stringToArrayBuffer(str) {
3459
}
3560
return buf;
3661
}
62+
function removeSingleOccurance(source, elementsToRemove) {
63+
var removed = Object.fromEntries(elementsToRemove.map(function (prop) { return [prop, false]; }));
64+
return source.filter(function (e) {
65+
if (elementsToRemove.includes(e) && !removed[e]) {
66+
removed[e] = true;
67+
return false;
68+
}
69+
return true;
70+
});
71+
}
72+
function findUniqueCommonElements(a, b) {
73+
return __spreadArray([], __read(a), false).filter(function (value) {
74+
return b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value);
75+
});
76+
}
3777
module.exports = {
3878
signPamFromParams: signPamFromParams,
3979
endsWith: endsWith,
4080
createPromise: createPromise,
4181
encodeString: encodeString,
4282
stringToArrayBuffer: stringToArrayBuffer,
83+
removeSingleOccurance: removeSingleOccurance,
84+
findUniqueCommonElements: findUniqueCommonElements,
4385
};

lib/entities/Subscription.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ var Subscription = /** @class */ (function () {
5454
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 })));
5555
};
5656
Subscription.prototype.unsubscribe = function () {
57-
this.pubnub.unsubscribe({ channels: this.channelNames, channelGroups: this.groupNames });
57+
this.pubnub.unsubscribe({
58+
channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }),
59+
channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }),
60+
});
5861
};
5962
Subscription.prototype.addListener = function (listener) {
6063
this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));

lib/entities/SubscriptionSet.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ var SubscriptionSet = /** @class */ (function () {
6363
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 })));
6464
};
6565
SubscriptionSet.prototype.unsubscribe = function () {
66-
this.pubnub.unsubscribe({ channels: this.channelNames, channelGroups: this.groupNames });
66+
this.pubnub.unsubscribe({
67+
channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }),
68+
channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }),
69+
});
6770
};
6871
SubscriptionSet.prototype.addListener = function (listener) {
6972
this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }));

lib/event-engine/index.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var core_1 = require("./core");
5353
var dispatcher_1 = require("./dispatcher");
5454
var events = __importStar(require("./events"));
5555
var unsubscribed_1 = require("./states/unsubscribed");
56+
var utils = __importStar(require("../core/utils"));
5657
var EventEngine = /** @class */ (function () {
5758
function EventEngine(dependencies) {
5859
var _this = this;
@@ -78,44 +79,47 @@ var EventEngine = /** @class */ (function () {
7879
EventEngine.prototype.subscribe = function (_a) {
7980
var _this = this;
8081
var channels = _a.channels, channelGroups = _a.channelGroups, timetoken = _a.timetoken, withPresence = _a.withPresence;
81-
this.channels = Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false)));
82-
this.groups = Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false)));
82+
this.channels = __spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false);
83+
this.groups = __spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false);
8384
if (withPresence) {
8485
this.channels.map(function (c) { return _this.channels.push("".concat(c, "-pnpres")); });
8586
this.groups.map(function (g) { return _this.groups.push("".concat(g, "-pnpres")); });
8687
}
8788
if (timetoken) {
88-
this.engine.transition(events.restore(this.channels, this.groups, timetoken));
89+
this.engine.transition(events.restore(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))), timetoken));
8990
}
9091
else {
91-
this.engine.transition(events.subscriptionChange(this.channels, this.groups));
92+
this.engine.transition(events.subscriptionChange(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false)))));
9293
}
9394
if (this.dependencies.join) {
9495
this.dependencies.join({
95-
channels: this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }),
96-
groups: this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }),
96+
channels: Array.from(new Set(this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }))),
97+
groups: Array.from(new Set(this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }))),
9798
});
9899
}
99100
};
100101
EventEngine.prototype.unsubscribe = function (_a) {
101102
var _this = this;
102-
var channels = _a.channels, groups = _a.groups;
103-
var channlesWithPres = channels === null || channels === void 0 ? void 0 : channels.slice(0);
104-
channels === null || channels === void 0 ? void 0 : channels.map(function (c) { return channlesWithPres.push("".concat(c, "-pnpres")); });
105-
this.channels = this.channels.filter(function (channel) { return !(channlesWithPres === null || channlesWithPres === void 0 ? void 0 : channlesWithPres.includes(channel)); });
106-
var groupsWithPres = groups === null || groups === void 0 ? void 0 : groups.slice(0);
107-
groups === null || groups === void 0 ? void 0 : groups.map(function (g) { return groupsWithPres.push("".concat(g, "-pnpres")); });
108-
this.groups = this.groups.filter(function (group) { return !(groupsWithPres === null || groupsWithPres === void 0 ? void 0 : groupsWithPres.includes(group)); });
109-
if (this.dependencies.presenceState) {
110-
channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { return delete _this.dependencies.presenceState[c]; });
111-
groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { return delete _this.dependencies.presenceState[g]; });
112-
}
113-
this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0)));
114-
if (this.dependencies.leave) {
115-
this.dependencies.leave({
116-
channels: channels,
117-
groups: groups,
118-
});
103+
var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c;
104+
var filteredChannels = utils.removeSingleOccurance(this.channels, __spreadArray(__spreadArray([], __read(channels), false), __read(channels.map(function (c) { return "".concat(c, "-pnpres"); })), false));
105+
var filteredGroups = utils.removeSingleOccurance(this.groups, __spreadArray(__spreadArray([], __read(channelGroups), false), __read(channelGroups.map(function (c) { return "".concat(c, "-pnpres"); })), false));
106+
if (new Set(this.channels).size !== new Set(filteredChannels).size ||
107+
new Set(this.groups).size !== new Set(filteredGroups).size) {
108+
var channelsToLeave = utils.findUniqueCommonElements(this.channels, channels);
109+
var groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups);
110+
if (this.dependencies.presenceState) {
111+
channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach(function (c) { return delete _this.dependencies.presenceState[c]; });
112+
groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach(function (g) { return delete _this.dependencies.presenceState[g]; });
113+
}
114+
this.channels = filteredChannels;
115+
this.groups = filteredGroups;
116+
this.engine.transition(events.subscriptionChange(Array.from(new Set(this.channels.slice(0))), Array.from(new Set(this.groups.slice(0)))));
117+
if (this.dependencies.leave) {
118+
this.dependencies.leave({
119+
channels: channelsToLeave.slice(0),
120+
groups: groupstoLeave.slice(0),
121+
});
122+
}
119123
}
120124
};
121125
EventEngine.prototype.unsubscribeAll = function () {

0 commit comments

Comments
 (0)