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

eventEngine #334

Merged
merged 67 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ab2b9d9
feat: cucumber refactor
are Nov 4, 2022
d1fad58
feat: add more steps
are Nov 30, 2022
95b6674
Merge branch 'master' of github.com:pubnub/javascript into feat/cucum…
are Apr 3, 2023
11a5670
feat: current progress
are May 12, 2023
eb35e90
refactor event-engine(from draft PR)
mohitpubnub May 19, 2023
f41d248
event-engine: update to latest description, added some missing transi…
mohitpubnub May 19, 2023
6dd1294
prettier!
mohitpubnub May 19, 2023
ab2b566
take: fix hanging tests due to retry intro
mohitpubnub Jun 14, 2023
64d2371
update as per latest event engine specs
mohitpubnub Jun 26, 2023
85af6b4
Merge branch 'master' into CLEN-1127
mohitpubnub Jun 26, 2023
8afa248
* cucumber tsflow
mohitpubnub Jul 6, 2023
c030e31
prettier!
mohitpubnub Jul 6, 2023
e01236c
fix: test and version mismatch from branch merge
mohitpubnub Jul 6, 2023
4f77d20
fix: version
mohitpubnub Jul 6, 2023
0ac5cc7
add: reconnection configuration
mohitpubnub Jul 11, 2023
ecd43ca
Merge branch 'CLEN-1127' into CLEN_1361_event_engine_test
mohitpubnub Jul 11, 2023
1c376a9
lint/prettier
mohitpubnub Jul 11, 2023
09d7708
fix: test. destroy() not required
mohitpubnub Jul 11, 2023
0a2e391
fix: naming convention and removed unnecessary effect dispatch
mohitpubnub Jul 11, 2023
701a44f
WIP: presence event engine
mohitpubnub Aug 18, 2023
b377b3c
organised files and directories for presence
mohitpubnub Aug 18, 2023
9096100
fix: paths
mohitpubnub Aug 18, 2023
325fd52
fix: lint
mohitpubnub Aug 22, 2023
bb6809e
presence and subscribe event engine states
mohitpubnub Jan 8, 2024
ae98076
event engine effects and events
mohitpubnub Jan 8, 2024
e1e02cc
retry policy configuration
mohitpubnub Jan 8, 2024
85dc261
event engines tests
mohitpubnub Jan 8, 2024
69ce948
updated stateless utilities
mohitpubnub Jan 8, 2024
c253e96
updated PubNub with configurations
mohitpubnub Jan 8, 2024
f7b92ad
lib and dist
mohitpubnub Jan 8, 2024
528ca45
take-1 fix lint
mohitpubnub Jan 8, 2024
037378d
fix: elint config
mohitpubnub Jan 8, 2024
ea4b588
Merge remote-tracking branch 'origin/master' into presence
mohitpubnub Jan 8, 2024
944caca
sync: package-lock
mohitpubnub Jan 8, 2024
b57361f
fix: package-lock
mohitpubnub Jan 8, 2024
128c678
WIP take-1(non-status events): Listener compatibility with eventEngine
mohitpubnub Jan 9, 2024
200df8c
take-2: (presence) listener structs backward compatibility.
mohitpubnub Jan 9, 2024
1b4d38e
lib and dist
mohitpubnub Jan 9, 2024
0678212
lint
mohitpubnub Jan 9, 2024
1c35fe9
event engine: naming, missing transitions, handling `reconnect` and `…
mohitpubnub Jan 11, 2024
7723146
event engine: receiving state as per specifications
mohitpubnub Jan 11, 2024
29343c1
refined naming for event engine events and effects
mohitpubnub Jan 11, 2024
f4c7f15
retryConfiguration behaviour updates
mohitpubnub Jan 11, 2024
9a07850
presence eventengine: removed unnecessary emitStatus events as per sp…
mohitpubnub Jan 11, 2024
e03d14d
config naming convention, eventengine initialisation updates as per n…
mohitpubnub Jan 11, 2024
41383dc
updated tests
mohitpubnub Jan 11, 2024
aab7eae
dist, lib and lint fixes
mohitpubnub Jan 11, 2024
c35559f
package-lock dependabot suggestion, fix test
mohitpubnub Jan 11, 2024
b4db5b5
removed duplicate file
mohitpubnub Jan 11, 2024
f46818f
fix: prevent duplicate listener to be added.
mohitpubnub Jan 12, 2024
5389aaf
dist/lib files
mohitpubnub Jan 12, 2024
1bdda1f
retry delay can be override by retry after value
mohitpubnub Jan 14, 2024
1f050fb
handled cursor across the states
mohitpubnub Jan 14, 2024
d2b2809
manage cursor from event struct
mohitpubnub Jan 14, 2024
aa306aa
dist and lib
mohitpubnub Jan 14, 2024
a428e1e
refactor: reconnect event handling
mohitpubnub Jan 15, 2024
d5e88d7
getSubscribedChannels and channelGroups binding when eventEngine is e…
mohitpubnub Jan 15, 2024
82e6438
refactor: retry policy delay calculation
mohitpubnub Jan 15, 2024
79fd10b
handshake* states: handling cursor value across state and defaulting …
mohitpubnub Jan 15, 2024
1117a84
receiv* states: handling cursor across states
mohitpubnub Jan 15, 2024
0d4a6f3
lib/dist
mohitpubnub Jan 15, 2024
594b5c9
addressed review comments : handling cursor value from context from h…
mohitpubnub Jan 15, 2024
b7aaf7d
revert test file changes
mohitpubnub Jan 15, 2024
ea443b6
fix: lint
mohitpubnub Jan 15, 2024
ed83cab
sync package-lock
mohitpubnub Jan 16, 2024
f815ad8
removed flow_interfaces reference
mohitpubnub Jan 16, 2024
e93db09
PubNub SDK v7.5.0 release.
pubnub-release-bot Jan 16, 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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module.exports = {
'class-methods-use-this': 0,
'no-prototype-builtins': 1,
'prefer-destructuring': 0,
'no-unused-vars': 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dist/titanium/stats.json
dist/contract
dist/cucumber
upload
test/specs

# GitHub Actions #
##################
Expand Down
12 changes: 12 additions & 0 deletions cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
default: [
'test/specs/features/**/*.feature',
'--require test/contract/setup.js',
'--require test/contract/definitions/**/*.ts',
'--require test/contract/shared/**/*.ts',
'--format summary',
'--format progress-bar',
// '--format @cucumber/pretty-formatter',
'--publish-quiet',
].join(' '),
};
1,259 changes: 1,124 additions & 135 deletions dist/web/pubnub.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/core/components/_endpoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
24 changes: 21 additions & 3 deletions lib/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var makeDefaultOrigins = function () { return Array.from({ length: 20 }, functio
var default_1 = /** @class */ (function () {
function default_1(_a) {
var setup = _a.setup;
var _b, _c, _d;
var _b, _c, _d, _e;
this._PNSDKSuffix = {};
this.instanceId = "pn-".concat(uuid_1.default.createUUID());
this.secretKey = setup.secretKey || setup.secret_key;
Expand Down Expand Up @@ -40,8 +40,8 @@ var default_1 = /** @class */ (function () {
this.customDecrypt = setup.customDecrypt;
this.fileUploadPublishRetryLimit = (_b = setup.fileUploadPublishRetryLimit) !== null && _b !== void 0 ? _b : 5;
this.useRandomIVs = (_c = setup.useRandomIVs) !== null && _c !== void 0 ? _c : true;
// flag for beta subscribe feature enablement
this.enableSubscribeBeta = (_d = setup.enableSubscribeBeta) !== null && _d !== void 0 ? _d : false;
this.enableEventEngine = (_d = setup.enableEventEngine) !== null && _d !== void 0 ? _d : false;
this.maintainPresenceState = (_e = setup.maintainPresenceState) !== null && _e !== void 0 ? _e : true;
// if location config exist and we are in https, force secure to true.
if (typeof location !== 'undefined' && location.protocol === 'https:') {
this.secure = true;
Expand All @@ -53,6 +53,9 @@ var default_1 = /** @class */ (function () {
this.useInstanceId = setup.useInstanceId || false;
this.useRequestId = setup.useRequestId || false;
this.requestMessageCountThreshold = setup.requestMessageCountThreshold;
if (setup.retryConfiguration) {
this._setRetryConfiguration(setup.retryConfiguration);
}
// set timeout to how long a transaction request will wait for the server (default 15 seconds)
this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000);
// set timeout to how long a subscribe event loop will run (default 310 seconds)
Expand Down Expand Up @@ -179,6 +182,21 @@ var default_1 = /** @class */ (function () {
default_1.prototype.getVersion = function () {
return '7.4.5';
};
default_1.prototype._setRetryConfiguration = function (configuration) {
if (configuration.minimumdelay < 2) {
throw new Error('Minimum delay can not be set less than 2 seconds for retry');
}
if (configuration.maximumDelay > 150) {
throw new Error('Maximum delay can not be set more than 150 seconds for retry');
}
if (configuration.maximumDelay && maximumRetry > 6) {
throw new Error('Maximum retry for exponential retry policy can not be more than 6');
}
else if (configuration.maximumRetry > 10) {
throw new Error('Maximum retry for linear retry policy can not be more than 10');
}
this.retryConfiguration = configuration;
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
};
Expand Down
212 changes: 212 additions & 0 deletions lib/core/components/eventEmitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var EventEmitter = /** @class */ (function () {
function EventEmitter(_a) {
var modules = _a.modules, listenerManager = _a.listenerManager, getFileUrl = _a.getFileUrl;
this.modules = modules;
this.listenerManager = listenerManager;
this.getFileUrl = getFileUrl;
if (modules.cryptoModule)
this._decoder = new TextDecoder();
}
EventEmitter.prototype.emitEvent = function (e) {
var channel = e.channel, publishMetaData = e.publishMetaData;
var subscriptionMatch = e.subscriptionMatch;
if (channel === subscriptionMatch) {
subscriptionMatch = null;
}
if (e.channel.endsWith('-pnpres')) {
var announce = {};
announce.channel = null;
announce.subscription = null;
if (channel) {
announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres'));
}
if (subscriptionMatch) {
announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres'));
}
announce.action = e.payload.action;
announce.state = e.payload.data;
announce.timetoken = publishMetaData.publishTimetoken;
announce.occupancy = e.payload.occupancy;
announce.uuid = e.payload.uuid;
announce.timestamp = e.payload.timestamp;
if (e.payload.join) {
announce.join = e.payload.join;
}
if (e.payload.leave) {
announce.leave = e.payload.leave;
}
if (e.payload.timeout) {
announce.timeout = e.payload.timeout;
}
this.listenerManager.announcePresence(announce);
}
else if (e.messageType === 1) {
var announce = {};
announce.channel = null;
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
}
announce.message = e.payload;
this.listenerManager.announceSignal(announce);
}
else if (e.messageType === 2) {
var announce = {};
announce.channel = null;
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
}
announce.message = {
event: e.payload.event,
type: e.payload.type,
data: e.payload.data,
};
this.listenerManager.announceObjects(announce);
if (e.payload.type === 'uuid') {
var eventData = this._renameChannelField(announce);
this.listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }));
}
else if (message.payload.type === 'channel') {
var eventData = this._renameChannelField(announce);
this.listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }));
}
else if (message.payload.type === 'membership') {
var eventData = this._renameChannelField(announce);
var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]);
membershipData.user = user;
membershipData.space = space;
this.listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }));
}
}
else if (e.messageType === 3) {
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.publisher = e.issuingClientId;
announce.data = {
messageTimetoken: e.payload.data.messageTimetoken,
actionTimetoken: e.payload.data.actionTimetoken,
type: e.payload.data.type,
uuid: e.issuingClientId,
value: e.payload.data.value,
};
announce.event = e.payload.event;
this.listenerManager.announceMessageAction(announce);
}
else if (e.messageType === 4) {
var announce = {};
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.publisher = e.issuingClientId;
var msgPayload = e.payload;
if (this.modules.cryptoModule) {
var decryptedPayload = void 0;
try {
var decryptedData = this.modules.cryptoModule.decrypt(e.payload);
decryptedPayload =
decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData;
}
catch (e) {
decryptedPayload = null;
announce.error = "Error while decrypting message content: ".concat(e.message);
}
if (decryptedPayload !== null) {
msgPayload = decryptedPayload;
}
}
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
}
announce.message = msgPayload.message;
announce.file = {
id: msgPayload.file.id,
name: msgPayload.file.name,
url: this.getFileUrl({
id: msgPayload.file.id,
name: msgPayload.file.name,
channel: channel,
}),
};
this.listenerManager.announceFile(announce);
}
else {
var announce = {};
announce.channel = null;
announce.subscription = null;
announce.channel = channel;
announce.subscription = subscriptionMatch;
announce.timetoken = publishMetaData.publishTimetoken;
announce.publisher = e.issuingClientId;
if (e.userMetadata) {
announce.userMetadata = e.userMetadata;
}
if (this.modules.cryptoModule) {
var decryptedPayload = void 0;
try {
var decryptedData = this.modules.cryptoModule.decrypt(e.payload);
decryptedPayload =
decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData;
}
catch (e) {
decryptedPayload = null;
announce.error = "Error while decrypting message content: ".concat(e.message);
}
if (decryptedPayload != null) {
announce.message = decryptedPayload;
}
else {
announce.message = e.payload;
}
}
else {
announce.message = e.payload;
}
this.listenerManager.announceMessage(announce);
}
};
EventEmitter.prototype._renameEvent = function (e) {
return e === 'set' ? 'updated' : 'removed';
};
EventEmitter.prototype._renameChannelField = function (announce) {
var channel = announce.channel, eventData = __rest(announce, ["channel"]);
eventData.spaceId = channel;
return eventData;
};
return EventEmitter;
}());
exports.default = EventEmitter;
7 changes: 5 additions & 2 deletions lib/core/components/listener_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ var default_1 = /** @class */ (function () {
function default_1() {
this._listeners = [];
}
default_1.prototype.addListener = function (newListeners) {
this._listeners.push(newListeners);
default_1.prototype.addListener = function (newListener) {
if (this._listeners.includes(newListener)) {
return;
}
this._listeners.push(newListener);
};
default_1.prototype.removeListener = function (deprecatedListener) {
var newListeners = [];
Expand Down
3 changes: 3 additions & 0 deletions lib/core/constants/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ exports.default = {
PNReconnectedCategory: 'PNReconnectedCategory',
PNConnectedCategory: 'PNConnectedCategory',
PNRequestMessageCountExceededCategory: 'PNRequestMessageCountExceededCategory',
PNDisconnectedCategory: 'PNDisconnectedCategory',
PNConnectionErrorCategory: 'PNConnectionErrorCategory',
PNDisconnectedUnexpectedlyCategory: 'PNDisconnectedUnexpectedlyCategory',
};
Loading
Loading