Skip to content

Commit 9b11d07

Browse files
areClient Engineering Bot
and
Client Engineering Bot
authored
feat: add core event engine state machine (pubnub#265)
* chore: remove flow types * chore: clean the repository * chore: add eslint and prettier configs * chore: fix eslint rules * build: add node and web builds * test: fix tests and ci * chore: update CODEOWNERS * feat: add core event engine state machine * feat: bind EventEngine to PubNub instance * feat: initial reconnection state description * feat: added stopped states * chore: run build * fix: fix tests and ignore aborts in subscription manager * PubNub SDK v6.0.0 release. Co-authored-by: Client Engineering Bot <60980775+Client Engineering [email protected]>
1 parent c40e431 commit 9b11d07

File tree

92 files changed

+6258
-1253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+6258
-1253
lines changed

.mocharc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spec: test/**/*.test.js
1+
spec: test/**/*.test.{ts,js}
22
require: test/setup.js
33
exclude:
44
- test/dist/*.js

.pubnub.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22
changelog:
3+
- date: 2022-04-14
4+
version: v6.0.0
5+
changes:
6+
- type: feature
7+
text: "Added a TypeScript build chain and moved from webpack to rollup."
8+
- type: feature
9+
text: "Added an initial implementation of Event Engine."
310
- date: 2022-03-02
411
version: v5.0.1
512
changes:
@@ -1101,7 +1108,7 @@ supported-platforms:
11011108
- "Ubuntu 14.04 and up"
11021109
- "Windows 7 and up"
11031110
version: "Pubnub Javascript for Node"
1104-
version: "5.0.1"
1111+
version: "6.0.0"
11051112
sdks:
11061113
-
11071114
full-name: PubNub Javascript SDK
@@ -1120,7 +1127,7 @@ sdks:
11201127
distribution-type: source
11211128
distribution-repository: GitHub release
11221129
package-name: pubnub.js
1123-
location: https://github.com/pubnub/javascript/archive/refs/tags/v5.0.1.zip
1130+
location: https://github.com/pubnub/javascript/archive/refs/tags/v6.0.0.zip
11241131
requires:
11251132
-
11261133
name: "agentkeepalive"
@@ -1884,7 +1891,7 @@ sdks:
18841891
distribution-type: library
18851892
distribution-repository: GitHub release
18861893
package-name: pubnub.js
1887-
location: https://github.com/pubnub/javascript/releases/download/v5.0.1/pubnub.5.0.1.js
1894+
location: https://github.com/pubnub/javascript/releases/download/v6.0.0/pubnub.6.0.0.js
18881895
requires:
18891896
-
18901897
name: "agentkeepalive"

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v6.0.0
2+
April 14 2022
3+
4+
#### Added
5+
- Added a TypeScript build chain and moved from webpack to rollup.
6+
- Added an initial implementation of Event Engine.
7+
18
## v5.0.1
29
March 02 2022
310

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2222
npm install pubnub
2323
```
2424
* or download one of our builds from our CDN:
25-
* https://cdn.pubnub.com/sdk/javascript/pubnub.5.0.1.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.5.0.1.min.js
25+
* https://cdn.pubnub.com/sdk/javascript/pubnub.6.0.0.js
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.6.0.0.min.js
2727
2828
2. Configure your keys:
2929

dist/web/pubnub.js

+1,644-776
Large diffs are not rendered by default.

dist/web/pubnub.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/abort_signal.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || (function () {
3+
var extendStatics = function (d, b) {
4+
extendStatics = Object.setPrototypeOf ||
5+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7+
return extendStatics(d, b);
8+
};
9+
return function (d, b) {
10+
if (typeof b !== "function" && b !== null)
11+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12+
extendStatics(d, b);
13+
function __() { this.constructor = d; }
14+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15+
};
16+
})();
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.AbortSignal = exports.AbortError = void 0;
19+
var subject_1 = require("./subject");
20+
var AbortError = /** @class */ (function (_super) {
21+
__extends(AbortError, _super);
22+
function AbortError() {
23+
var _newTarget = this.constructor;
24+
var _this = _super.call(this, 'The operation was aborted.') || this;
25+
_this.name = 'AbortError';
26+
Object.setPrototypeOf(_this, _newTarget.prototype);
27+
return _this;
28+
}
29+
return AbortError;
30+
}(Error));
31+
exports.AbortError = AbortError;
32+
var AbortSignal = /** @class */ (function (_super) {
33+
__extends(AbortSignal, _super);
34+
function AbortSignal() {
35+
var _this = _super !== null && _super.apply(this, arguments) || this;
36+
_this._aborted = false;
37+
return _this;
38+
}
39+
Object.defineProperty(AbortSignal.prototype, "aborted", {
40+
get: function () {
41+
return this._aborted;
42+
},
43+
enumerable: false,
44+
configurable: true
45+
});
46+
AbortSignal.prototype.throwIfAborted = function () {
47+
if (this._aborted) {
48+
throw new AbortError();
49+
}
50+
};
51+
AbortSignal.prototype.abort = function () {
52+
this._aborted = true;
53+
this.notify(new AbortError());
54+
};
55+
return AbortSignal;
56+
}(subject_1.Subject));
57+
exports.AbortSignal = AbortSignal;

lib/core/components/config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var makeDefaultOrigins = function () { return Array.from({ length: 20 }, functio
99
var default_1 = /** @class */ (function () {
1010
function default_1(_a) {
1111
var setup = _a.setup;
12-
var _b, _c;
12+
var _b, _c, _d;
1313
this._PNSDKSuffix = {};
1414
this.instanceId = "pn-".concat(uuid_1.default.createUUID());
1515
this.secretKey = setup.secretKey || setup.secret_key;
@@ -37,6 +37,8 @@ var default_1 = /** @class */ (function () {
3737
this.customDecrypt = setup.customDecrypt;
3838
this.fileUploadPublishRetryLimit = (_b = setup.fileUploadPublishRetryLimit) !== null && _b !== void 0 ? _b : 5;
3939
this.useRandomIVs = (_c = setup.useRandomIVs) !== null && _c !== void 0 ? _c : true;
40+
// flag for beta subscribe feature enablement
41+
this.enableSubscribeBeta = (_d = setup.enableSubscribeBeta) !== null && _d !== void 0 ? _d : false;
4042
// if location config exist and we are in https, force secure to true.
4143
if (typeof location !== 'undefined' && location.protocol === 'https:') {
4244
this.secure = true;
@@ -143,7 +145,7 @@ var default_1 = /** @class */ (function () {
143145
return this;
144146
};
145147
default_1.prototype.getVersion = function () {
146-
return '5.0.0';
148+
return '6.0.0';
147149
};
148150
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
149151
this._PNSDKSuffix[name] = suffix;

lib/core/components/endpoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ var categories_1 = require("../constants/categories");
3434
var PubNubError = /** @class */ (function (_super) {
3535
__extends(PubNubError, _super);
3636
function PubNubError(message, status) {
37+
var _newTarget = this.constructor;
3738
var _this = _super.call(this, message) || this;
3839
_this.name = _this.constructor.name;
3940
_this.status = status;
4041
_this.message = message;
42+
Object.setPrototypeOf(_this, _newTarget.prototype);
4143
return _this;
4244
}
4345
return PubNubError;
@@ -177,6 +179,7 @@ function default_1(modules, endpoint) {
177179
headers: endpoint.getRequestHeaders ? endpoint.getRequestHeaders() : {},
178180
ignoreBody: typeof endpoint.ignoreBody === 'function' ? endpoint.ignoreBody(modules) : false,
179181
forceBuffered: typeof endpoint.forceBuffered === 'function' ? endpoint.forceBuffered(modules, incomingParams) : null,
182+
abortSignal: typeof endpoint.getAbortSignal === 'function' ? endpoint.getAbortSignal(modules, incomingParams) : null,
180183
};
181184
outgoingParams.uuid = config.UUID;
182185
outgoingParams.pnsdk = generatePNSDK(config);

lib/core/components/requestController.js

-62
This file was deleted.

lib/core/components/requestController.js.map

-1
This file was deleted.

lib/core/components/subject.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.Subject = void 0;
4+
var Subject = /** @class */ (function () {
5+
function Subject(sync) {
6+
if (sync === void 0) { sync = false; }
7+
this.sync = sync;
8+
this.listeners = new Set();
9+
}
10+
Subject.prototype.subscribe = function (listener) {
11+
var _this = this;
12+
this.listeners.add(listener);
13+
return function () {
14+
_this.listeners.delete(listener);
15+
};
16+
};
17+
Subject.prototype.notify = function (event) {
18+
var _this = this;
19+
var wrapper = function () {
20+
_this.listeners.forEach(function (listener) {
21+
listener(event);
22+
});
23+
};
24+
if (this.sync) {
25+
wrapper();
26+
}
27+
else {
28+
setTimeout(wrapper, 0);
29+
}
30+
};
31+
return Subject;
32+
}());
33+
exports.Subject = Subject;

lib/core/components/subscription_manager.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var default_1 = /** @class */ (function () {
144144
}
145145
}
146146
if (channelGroup in _this._presenceChannelGroups) {
147-
delete _this._channelGroups[channelGroup];
147+
delete _this._presenceChannelGroups[channelGroup];
148148
actualChannelGroups.push(channelGroup);
149149
}
150150
});
@@ -300,6 +300,10 @@ var default_1 = /** @class */ (function () {
300300
default_1.prototype._processSubscribeResponse = function (status, payload) {
301301
var _this = this;
302302
if (status.error) {
303+
// if error comes from request abort, ignore
304+
if (status.errorData && status.errorData.message === 'Aborted') {
305+
return;
306+
}
303307
// if we timeout from server, restart the loop.
304308
if (status.category === categories_1.default.PNTimeoutCategory) {
305309
this._startSubscribeLoop();

lib/core/constants/operations.js

+3
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ exports.default = {
7777
PNAccessManagerAudit: 'PNAccessManagerAudit',
7878
PNAccessManagerRevokeToken: 'PNAccessManagerRevokeToken',
7979
//
80+
// subscription utilities
81+
PNHandshakeOperation: 'PNHandshakeOperation',
82+
PNReceiveMessagesOperation: 'PNReceiveMessagesOperation',
8083
};

lib/core/endpoints/history/message_counts.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
"use strict";
22
/* */
3+
var __read = (this && this.__read) || function (o, n) {
4+
var m = typeof Symbol === "function" && o[Symbol.iterator];
5+
if (!m) return o;
6+
var i = m.call(o), r, ar = [], e;
7+
try {
8+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9+
}
10+
catch (error) { e = { error: error }; }
11+
finally {
12+
try {
13+
if (r && !r.done && (m = i["return"])) m.call(i);
14+
}
15+
finally { if (e) throw e.error; }
16+
}
17+
return ar;
18+
};
319
Object.defineProperty(exports, "__esModule", { value: true });
420
exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0;
521
var operations_1 = require("../../constants/operations");
@@ -42,7 +58,7 @@ function prepareParams(modules, incomingParams) {
4258
var timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens;
4359
var outgoingParams = {};
4460
if (channelTimetokens && channelTimetokens.length === 1) {
45-
var tt = channelTimetokens[0];
61+
var _a = __read(channelTimetokens, 1), tt = _a[0];
4662
outgoingParams.timetoken = tt;
4763
}
4864
else if (channelTimetokens) {

lib/core/endpoints/objects/channel/get_all.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
"use strict";
22
/** */
3+
var __read = (this && this.__read) || function (o, n) {
4+
var m = typeof Symbol === "function" && o[Symbol.iterator];
5+
if (!m) return o;
6+
var i = m.call(o), r, ar = [], e;
7+
try {
8+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9+
}
10+
catch (error) { e = { error: error }; }
11+
finally {
12+
try {
13+
if (r && !r.done && (m = i["return"])) m.call(i);
14+
}
15+
finally { if (e) throw e.error; }
16+
}
17+
return ar;
18+
};
319
Object.defineProperty(exports, "__esModule", { value: true });
420
var operations_1 = require("../../../constants/operations");
521
var endpoint = {
@@ -37,7 +53,7 @@ var endpoint = {
3753
queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100;
3854
if (params === null || params === void 0 ? void 0 : params.sort) {
3955
queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) {
40-
var key = _a[0], value = _a[1];
56+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
4157
if (value === 'asc' || value === 'desc') {
4258
return "".concat(key, ":").concat(value);
4359
}

lib/core/endpoints/objects/member/get.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
"use strict";
22
/** */
3+
var __read = (this && this.__read) || function (o, n) {
4+
var m = typeof Symbol === "function" && o[Symbol.iterator];
5+
if (!m) return o;
6+
var i = m.call(o), r, ar = [], e;
7+
try {
8+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9+
}
10+
catch (error) { e = { error: error }; }
11+
finally {
12+
try {
13+
if (r && !r.done && (m = i["return"])) m.call(i);
14+
}
15+
finally { if (e) throw e.error; }
16+
}
17+
return ar;
18+
};
319
Object.defineProperty(exports, "__esModule", { value: true });
420
var operations_1 = require("../../../constants/operations");
521
var utils_1 = require("../../../utils");
@@ -50,7 +66,7 @@ var endpoint = {
5066
queryParams.limit = (_l = params === null || params === void 0 ? void 0 : params.limit) !== null && _l !== void 0 ? _l : 100;
5167
if (params === null || params === void 0 ? void 0 : params.sort) {
5268
queryParams.sort = Object.entries((_m = params.sort) !== null && _m !== void 0 ? _m : {}).map(function (_a) {
53-
var key = _a[0], value = _a[1];
69+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
5470
if (value === 'asc' || value === 'desc') {
5571
return "".concat(key, ":").concat(value);
5672
}

0 commit comments

Comments
 (0)