snack-sdk 6.5.1 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/DependencyResolver.d.ts +1 -1
- package/build/DependencyResolver.js +25 -23
- package/build/DependencyResolver.js.map +1 -1
- package/build/DevSession.js +10 -9
- package/build/DevSession.js.map +1 -1
- package/build/FileUploader.d.ts +2 -2
- package/build/FileUploader.js +7 -7
- package/build/FileUploader.js.map +1 -1
- package/build/Logger.d.ts +1 -1
- package/build/Logger.js +9 -8
- package/build/Logger.js.map +1 -1
- package/build/Session.d.ts +4 -4
- package/build/Session.js +51 -43
- package/build/Session.js.map +1 -1
- package/build/State.d.ts +1 -1
- package/build/State.js +2 -2
- package/build/State.js.map +1 -1
- package/build/WantedVersions.d.ts +1 -1
- package/build/WantedVersions.js +3 -3
- package/build/WantedVersions.js.map +1 -1
- package/build/defaultConfig.js +1 -1
- package/build/defaultConfig.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +8 -2
- package/build/index.js.map +1 -1
- package/build/transports/CodeMessageBuilder.d.ts +2 -2
- package/build/transports/CodeMessageBuilder.js +5 -3
- package/build/transports/CodeMessageBuilder.js.map +1 -1
- package/build/transports/ConnectionMetricsEmitter.d.ts +2 -2
- package/build/transports/ConnectionMetricsEmitter.js.map +1 -1
- package/build/transports/Protocol.d.ts +11 -11
- package/build/transports/TransportImplBase.js +3 -3
- package/build/transports/TransportImplBase.js.map +1 -1
- package/build/transports/TransportImplSocketIO.js +4 -2
- package/build/transports/TransportImplSocketIO.js.map +1 -1
- package/build/transports/TransportImplWebPlayer.js +7 -5
- package/build/transports/TransportImplWebPlayer.js.map +1 -1
- package/build/transports/index.d.ts +0 -1
- package/build/transports/index.js +6 -7
- package/build/transports/index.js.map +1 -1
- package/build/transports/types.d.ts +14 -14
- package/build/transports/webPlayer.js +1 -1
- package/build/transports/webPlayer.js.map +1 -1
- package/build/types.d.ts +9 -9
- package/build/utils.d.ts +6 -2
- package/build/utils.js +25 -11
- package/build/utils.js.map +1 -1
- package/package.json +6 -10
- package/build/transports/TrafficMirroringTransport.d.ts +0 -8
- package/build/transports/TrafficMirroringTransport.js +0 -33
- package/build/transports/TrafficMirroringTransport.js.map +0 -1
- package/build/transports/TransportImplPubNub.d.ts +0 -15
- package/build/transports/TransportImplPubNub.js +0 -169
- package/build/transports/TransportImplPubNub.js.map +0 -1
package/build/utils.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { SDKVersion } from 'snack-content';
|
|
2
2
|
import { SnackError, SnackUser } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Stable reference to the fetch function that is used internally.
|
|
5
|
+
*/
|
|
6
|
+
declare const internalFetch: typeof fetch;
|
|
7
|
+
export { internalFetch as fetch };
|
|
8
|
+
export declare function setSnackSDKFetch(fn: typeof fetch): void;
|
|
5
9
|
export declare function createChannel(channel?: string): string;
|
|
6
10
|
export declare function createURL(endpoint: string, sdkVersion: SDKVersion, channel?: string, id?: string): string;
|
|
7
11
|
export declare function createError(config: {
|
package/build/utils.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createUserHeader = exports.createError = exports.createURL = exports.createChannel = exports.fetch = void 0;
|
|
7
|
-
var fetch_ponyfill_1 = __importDefault(require("fetch-ponyfill"));
|
|
3
|
+
exports.createUserHeader = exports.createError = exports.createURL = exports.createChannel = exports.setSnackSDKFetch = exports.fetch = void 0;
|
|
8
4
|
var nanoid_1 = require("nanoid");
|
|
9
5
|
var snack_content_1 = require("snack-content");
|
|
10
|
-
var
|
|
11
|
-
|
|
6
|
+
var fetchFn;
|
|
7
|
+
/**
|
|
8
|
+
* Stable reference to the fetch function that is used internally.
|
|
9
|
+
*/
|
|
10
|
+
var internalFetch = function () {
|
|
11
|
+
var args = [];
|
|
12
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
+
args[_i] = arguments[_i];
|
|
14
|
+
}
|
|
15
|
+
if (!fetchFn) {
|
|
16
|
+
// intialize on first use to avoid breaking global polyfill from user's code (or test mocks)
|
|
17
|
+
fetchFn = globalThis.fetch;
|
|
18
|
+
}
|
|
19
|
+
return fetchFn.apply(void 0, args);
|
|
20
|
+
};
|
|
21
|
+
exports.fetch = internalFetch;
|
|
22
|
+
function setSnackSDKFetch(fn) {
|
|
23
|
+
fetchFn = fn;
|
|
24
|
+
}
|
|
25
|
+
exports.setSnackSDKFetch = setSnackSDKFetch;
|
|
12
26
|
/**
|
|
13
27
|
* All valid characters to generate a new channel ID.
|
|
14
28
|
* Both `+` and `-` are used as delimiters in the classic updates URL.
|
|
15
29
|
* In the new URL format, we prefer URL/sub-domain safe characters.
|
|
16
30
|
*/
|
|
17
31
|
var VALID_CHANNEL_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
18
|
-
var generateChannel = nanoid_1.customAlphabet(VALID_CHANNEL_CHARS, 10);
|
|
32
|
+
var generateChannel = (0, nanoid_1.customAlphabet)(VALID_CHANNEL_CHARS, 10);
|
|
19
33
|
function createChannel(channel) {
|
|
20
34
|
channel = channel !== null && channel !== void 0 ? channel : generateChannel();
|
|
21
35
|
if (channel.length < 6) {
|
|
@@ -27,14 +41,14 @@ function createChannel(channel) {
|
|
|
27
41
|
for (var _i = 0, channel_1 = channel; _i < channel_1.length; _i++) {
|
|
28
42
|
var char = channel_1[_i];
|
|
29
43
|
if (VALID_CHANNEL_CHARS.indexOf(char) < 0) {
|
|
30
|
-
throw new Error("Channel id contains an invalid character \""
|
|
44
|
+
throw new Error("Channel id contains an invalid character \"".concat(char, "\", only \"[0-9a-zA-Z]\" are allowed"));
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
return channel;
|
|
34
48
|
}
|
|
35
49
|
exports.createChannel = createChannel;
|
|
36
50
|
function createURL(endpoint, sdkVersion, channel, id) {
|
|
37
|
-
return snack_content_1.createRuntimeUrl({ endpoint: endpoint, channel: channel, sdkVersion: sdkVersion, snack: id });
|
|
51
|
+
return (0, snack_content_1.createRuntimeUrl)({ endpoint: endpoint, channel: channel, sdkVersion: sdkVersion, snack: id });
|
|
38
52
|
}
|
|
39
53
|
exports.createURL = createURL;
|
|
40
54
|
function createError(config) {
|
|
@@ -57,7 +71,7 @@ function createUserHeader(user) {
|
|
|
57
71
|
return { 'Expo-Session': user.sessionSecret };
|
|
58
72
|
}
|
|
59
73
|
if (user === null || user === void 0 ? void 0 : user.accessToken) {
|
|
60
|
-
return { Authorization: "Bearer "
|
|
74
|
+
return { Authorization: "Bearer ".concat(user.accessToken) };
|
|
61
75
|
}
|
|
62
76
|
return {};
|
|
63
77
|
}
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,+CAA6D;AAI7D,IAAI,OAAqB,CAAC;AAE1B;;GAEG;AACH,IAAM,aAAa,GAAiB;IAAC,cAAO;SAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;QAAP,yBAAO;;IAC1C,IAAI,CAAC,OAAO,EAAE;QACZ,4FAA4F;QAC5F,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC;KAC5B;IAED,OAAO,OAAO,eAAI,IAAI,EAAE;AAC1B,CAAC,CAAC;AAEwB,8BAAK;AAE/B,SAAgB,gBAAgB,CAAC,EAAgB;IAC/C,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAFD,4CAEC;AAED;;;;GAIG;AAC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CAAC,UAAU;QAAE,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAC5D,IAAI,MAAM,CAAC,YAAY;QAAE,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAClE,IAAI,MAAM,CAAC,KAAK;QAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC7C,OAAO,KAAK,CAAC;AACf,CAAC;AAfD,kCAeC;AAED,SAAgB,gBAAgB,CAAC,IAAgB;IAC/C,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,aAAa,EAAE;QACvB,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;KAC/C;IAED,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,EAAE;QACrB,OAAO,EAAE,aAAa,EAAE,iBAAU,IAAI,CAAC,WAAW,CAAE,EAAE,CAAC;KACxD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAVD,4CAUC","sourcesContent":["import { customAlphabet } from 'nanoid';\nimport { SDKVersion, createRuntimeUrl } from 'snack-content';\n\nimport { SnackError, SnackUser } from './types';\n\nlet fetchFn: typeof fetch;\n\n/**\n * Stable reference to the fetch function that is used internally.\n */\nconst internalFetch: typeof fetch = (...args) => {\n if (!fetchFn) {\n // intialize on first use to avoid breaking global polyfill from user's code (or test mocks)\n fetchFn = globalThis.fetch;\n }\n\n return fetchFn(...args);\n};\n\nexport { internalFetch as fetch };\n\nexport function setSnackSDKFetch(fn: typeof fetch) {\n fetchFn = fn;\n}\n\n/**\n * All valid characters to generate a new channel ID.\n * Both `+` and `-` are used as delimiters in the classic updates URL.\n * In the new URL format, we prefer URL/sub-domain safe characters.\n */\nconst VALID_CHANNEL_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst generateChannel = customAlphabet(VALID_CHANNEL_CHARS, 10);\n\nexport function createChannel(channel?: string): string {\n channel = channel ?? generateChannel();\n\n if (channel.length < 6) {\n throw new Error('Please use a channel id with more characters (entropy)');\n }\n\n if (channel.length > 128) {\n throw new Error('Channel id too long, use a channel id thats shorter than 128 characters');\n }\n\n for (const char of channel) {\n if (VALID_CHANNEL_CHARS.indexOf(char) < 0) {\n throw new Error(\n `Channel id contains an invalid character \"${char}\", only \"[0-9a-zA-Z]\" are allowed`,\n );\n }\n }\n\n return channel;\n}\n\nexport function createURL(endpoint: string, sdkVersion: SDKVersion, channel?: string, id?: string) {\n return createRuntimeUrl({ endpoint, channel, sdkVersion, snack: id });\n}\n\nexport function createError(config: {\n message: string;\n name?: string;\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n stack?: string;\n}): SnackError {\n const error: SnackError = new Error(config.message);\n if (config.name) error.name = config.name;\n if (config.fileName) error.fileName = config.fileName;\n if (config.lineNumber) error.lineNumber = config.lineNumber;\n if (config.columnNumber) error.columnNumber = config.columnNumber;\n if (config.stack) error.stack = config.stack;\n return error;\n}\n\nexport function createUserHeader(user?: SnackUser): { [key: string]: string } {\n if (user?.sessionSecret) {\n return { 'Expo-Session': user.sessionSecret };\n }\n\n if (user?.accessToken) {\n return { Authorization: `Bearer ${user.accessToken}` };\n }\n\n return {};\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snack-sdk",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"description": "The Expo Snack SDK",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -33,45 +33,41 @@
|
|
|
33
33
|
"author": "Expo <support@expo.dev>",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"volta": {
|
|
36
|
-
"node": "
|
|
36
|
+
"node": "22.21.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@expo/spawn-async": "^1.5.0",
|
|
40
40
|
"@koa/router": "^10.0.0",
|
|
41
41
|
"@types/diff": "^4.0.2",
|
|
42
|
-
"@types/jest": "^
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
43
43
|
"@types/koa": "^2.11.6",
|
|
44
44
|
"@types/koa-bodyparser": "^4.3.0",
|
|
45
45
|
"@types/koa__router": "^8.0.3",
|
|
46
46
|
"@types/lodash.isequal": "^4.5.5",
|
|
47
47
|
"@types/lodash.mapvalues": "^4.6.6",
|
|
48
|
-
"@types/node-fetch": "^2.5.7",
|
|
49
|
-
"@types/pubnub": "^7.2.0",
|
|
50
48
|
"@types/semver": "^7.3.4",
|
|
51
49
|
"@types/ua-parser-js": "^0.7.33",
|
|
52
50
|
"@types/validate-npm-package-name": "^3.0.2",
|
|
53
51
|
"eslint": "^8.49.0",
|
|
54
52
|
"eslint-config-universe": "^12.0.0",
|
|
55
53
|
"form-data": "^3.0.0",
|
|
56
|
-
"jest": "^
|
|
54
|
+
"jest": "^29.7.0",
|
|
57
55
|
"jest-fetch-mock": "^3.0.3",
|
|
58
56
|
"koa": "^2.13.0",
|
|
59
57
|
"koa-bodyparser": "^4.3.0",
|
|
60
58
|
"prettier": "^3.0.3",
|
|
61
|
-
"ts-jest": "^
|
|
59
|
+
"ts-jest": "^29.1.2",
|
|
62
60
|
"typedoc": "^0.19.2",
|
|
63
61
|
"typedoc-plugin-markdown": "^3.0.11",
|
|
64
62
|
"typescript": "^4.1.2"
|
|
65
63
|
},
|
|
66
64
|
"dependencies": {
|
|
67
65
|
"diff": "^4.0.2",
|
|
68
|
-
"fetch-ponyfill": "^7.0.0",
|
|
69
66
|
"lodash": "^4.17.20",
|
|
70
67
|
"nanoid": "^3.1.20",
|
|
71
68
|
"nullthrows": "^1.1.1",
|
|
72
|
-
"pubnub": "^7.2.0",
|
|
73
69
|
"semver": "^7.3.4",
|
|
74
|
-
"snack-content": "~3.
|
|
70
|
+
"snack-content": "~3.6.1",
|
|
75
71
|
"socket.io-client": "~4.5.4",
|
|
76
72
|
"ua-parser-js": "^0.7.22",
|
|
77
73
|
"validate-npm-package-name": "^3.0.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SnackTransport, SnackTransportListener, SnackTransportMessage, SnackTransportOptions } from './types';
|
|
2
|
-
export default class TrafficMirroringTransport implements SnackTransport {
|
|
3
|
-
private readonly transports;
|
|
4
|
-
constructor(options: SnackTransportOptions);
|
|
5
|
-
addEventListener(type: 'message', listener: SnackTransportListener): void;
|
|
6
|
-
removeEventListener(type: 'message', listener: SnackTransportListener): void;
|
|
7
|
-
postMessage(message: SnackTransportMessage): void;
|
|
8
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var TransportImplPubNub_1 = __importDefault(require("./TransportImplPubNub"));
|
|
7
|
-
var TransportImplSocketIO_1 = __importDefault(require("./TransportImplSocketIO"));
|
|
8
|
-
var TrafficMirroringTransport = /** @class */ (function () {
|
|
9
|
-
function TrafficMirroringTransport(options) {
|
|
10
|
-
this.transports = [new TransportImplPubNub_1.default(options), new TransportImplSocketIO_1.default(options)];
|
|
11
|
-
}
|
|
12
|
-
TrafficMirroringTransport.prototype.addEventListener = function (type, listener) {
|
|
13
|
-
for (var _i = 0, _a = this.transports; _i < _a.length; _i++) {
|
|
14
|
-
var transport = _a[_i];
|
|
15
|
-
transport.addEventListener(type, listener);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
TrafficMirroringTransport.prototype.removeEventListener = function (type, listener) {
|
|
19
|
-
for (var _i = 0, _a = this.transports; _i < _a.length; _i++) {
|
|
20
|
-
var transport = _a[_i];
|
|
21
|
-
transport.removeEventListener(type, listener);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
TrafficMirroringTransport.prototype.postMessage = function (message) {
|
|
25
|
-
for (var _i = 0, _a = this.transports; _i < _a.length; _i++) {
|
|
26
|
-
var transport = _a[_i];
|
|
27
|
-
transport.postMessage(message);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
return TrafficMirroringTransport;
|
|
31
|
-
}());
|
|
32
|
-
exports.default = TrafficMirroringTransport;
|
|
33
|
-
//# sourceMappingURL=TrafficMirroringTransport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TrafficMirroringTransport.js","sourceRoot":"","sources":["../../src/transports/TrafficMirroringTransport.ts"],"names":[],"mappings":";;;;;AAAA,8EAAwD;AACxD,kFAA4D;AAQ5D;IAGE,mCAAY,OAA8B;QACxC,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,6BAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,+BAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,oDAAgB,GAAhB,UAAiB,IAAe,EAAE,QAAgC;QAChE,KAAwB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,EAAE;YAApC,IAAM,SAAS,SAAA;YAClB,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SAC5C;IACH,CAAC;IAED,uDAAmB,GAAnB,UAAoB,IAAe,EAAE,QAAgC;QACnE,KAAwB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,EAAE;YAApC,IAAM,SAAS,SAAA;YAClB,SAAS,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SAC/C;IACH,CAAC;IAED,+CAAW,GAAX,UAAY,OAA8B;QACxC,KAAwB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,EAAE;YAApC,IAAM,SAAS,SAAA;YAClB,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SAChC;IACH,CAAC;IACH,gCAAC;AAAD,CAAC,AAxBD,IAwBC","sourcesContent":["import TransportImplPubNub from './TransportImplPubNub';\nimport TransportImplSocketIO from './TransportImplSocketIO';\nimport {\n SnackTransport,\n SnackTransportListener,\n SnackTransportMessage,\n SnackTransportOptions,\n} from './types';\n\nexport default class TrafficMirroringTransport implements SnackTransport {\n private readonly transports: SnackTransport[];\n\n constructor(options: SnackTransportOptions) {\n this.transports = [new TransportImplPubNub(options), new TransportImplSocketIO(options)];\n }\n\n addEventListener(type: 'message', listener: SnackTransportListener): void {\n for (const transport of this.transports) {\n transport.addEventListener(type, listener);\n }\n }\n\n removeEventListener(type: 'message', listener: SnackTransportListener): void {\n for (const transport of this.transports) {\n transport.removeEventListener(type, listener);\n }\n }\n\n postMessage(message: SnackTransportMessage): void {\n for (const transport of this.transports) {\n transport.postMessage(message);\n }\n }\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ProtocolOutgoingMessage, ProtocolCodeMessage } from './Protocol';
|
|
2
|
-
import TransportImplBase from './TransportImplBase';
|
|
3
|
-
export declare function calcPubNubCodeMessageSize(channel: string, codeMessage: ProtocolCodeMessage): number;
|
|
4
|
-
export default class TransportImplPubNub extends TransportImplBase {
|
|
5
|
-
private pubNub?;
|
|
6
|
-
private pubNubClientId?;
|
|
7
|
-
protected start(): void;
|
|
8
|
-
protected stop(): void;
|
|
9
|
-
protected isStarted(): boolean;
|
|
10
|
-
protected sendAsync(channel: string, message: ProtocolOutgoingMessage): Promise<void>;
|
|
11
|
-
protected onVerifyCodeMessageSize(codeMessage: ProtocolCodeMessage): boolean;
|
|
12
|
-
private onPubNubPresence;
|
|
13
|
-
private onPubNubMessage;
|
|
14
|
-
private onPubNubStatus;
|
|
15
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
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
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
26
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
-
function step(op) {
|
|
29
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
-
while (_) try {
|
|
31
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
32
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
-
switch (op[0]) {
|
|
34
|
-
case 0: case 1: t = op; break;
|
|
35
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
-
default:
|
|
39
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
-
if (t[2]) _.ops.pop();
|
|
44
|
-
_.trys.pop(); continue;
|
|
45
|
-
}
|
|
46
|
-
op = body.call(thisArg, _);
|
|
47
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
-
};
|
|
54
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
exports.calcPubNubCodeMessageSize = void 0;
|
|
56
|
-
var pubnub_1 = __importDefault(require("pubnub"));
|
|
57
|
-
var TransportImplBase_1 = __importDefault(require("./TransportImplBase"));
|
|
58
|
-
function calcPubNubCodeMessageSize(channel, codeMessage) {
|
|
59
|
-
// https://support.pubnub.com/hc/en-us/articles/360051495932-Calculating-message-payload-size-before-publishing
|
|
60
|
-
return (encodeURIComponent(channel +
|
|
61
|
-
JSON.stringify(codeMessage).replace(/[!~*'()]/g, function (x) { return "%" + x.charCodeAt(0).toString(16).toUpperCase(); })).length + 200);
|
|
62
|
-
}
|
|
63
|
-
exports.calcPubNubCodeMessageSize = calcPubNubCodeMessageSize;
|
|
64
|
-
var TransportImplPubNub = /** @class */ (function (_super) {
|
|
65
|
-
__extends(TransportImplPubNub, _super);
|
|
66
|
-
function TransportImplPubNub() {
|
|
67
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
68
|
-
_this.onPubNubPresence = function (event) {
|
|
69
|
-
switch (event.action) {
|
|
70
|
-
case 'join':
|
|
71
|
-
_this.handleChannelEvent('join', event.uuid);
|
|
72
|
-
break;
|
|
73
|
-
case 'timeout':
|
|
74
|
-
case 'leave':
|
|
75
|
-
_this.handleChannelEvent('leave', event.uuid);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
_this.onPubNubMessage = function (event) {
|
|
80
|
-
var message = event.message;
|
|
81
|
-
_this.handleMessage(event.publisher, message);
|
|
82
|
-
};
|
|
83
|
-
_this.onPubNubStatus = function (_event) {
|
|
84
|
-
// TODO: Do something here?
|
|
85
|
-
};
|
|
86
|
-
return _this;
|
|
87
|
-
}
|
|
88
|
-
TransportImplPubNub.prototype.start = function () {
|
|
89
|
-
var _a;
|
|
90
|
-
this.stop();
|
|
91
|
-
if (!this.pubNubClientId) {
|
|
92
|
-
// Keep track of the client ID per transport instance.
|
|
93
|
-
// See: https://support.pubnub.com/hc/en-us/articles/360051496532-How-do-I-set-the-UUID-
|
|
94
|
-
this.pubNubClientId = pubnub_1.default.generateUUID();
|
|
95
|
-
}
|
|
96
|
-
if (this.channel) {
|
|
97
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.comm('Starting channel...', this.channel, this.logSuffix);
|
|
98
|
-
this.pubNub = new pubnub_1.default({
|
|
99
|
-
publishKey: 'pub-c-2a7fd67b-333d-40db-ad2d-3255f8835f70',
|
|
100
|
-
subscribeKey: 'sub-c-0b655000-d784-11e6-b950-02ee2ddab7fe',
|
|
101
|
-
uuid: this.pubNubClientId,
|
|
102
|
-
ssl: true,
|
|
103
|
-
presenceTimeout: 600,
|
|
104
|
-
heartbeatInterval: 60,
|
|
105
|
-
});
|
|
106
|
-
this.pubNub.addListener({
|
|
107
|
-
presence: this.onPubNubPresence,
|
|
108
|
-
message: this.onPubNubMessage,
|
|
109
|
-
status: this.onPubNubStatus,
|
|
110
|
-
});
|
|
111
|
-
this.pubNub.subscribe({
|
|
112
|
-
channels: [this.channel],
|
|
113
|
-
withPresence: true,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
TransportImplPubNub.prototype.stop = function () {
|
|
118
|
-
var _a;
|
|
119
|
-
if (this.pubNub) {
|
|
120
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.comm('Stopping...', this.logSuffix);
|
|
121
|
-
this.pubNub.removeListener({
|
|
122
|
-
presence: this.onPubNubPresence,
|
|
123
|
-
message: this.onPubNubMessage,
|
|
124
|
-
status: this.onPubNubStatus,
|
|
125
|
-
});
|
|
126
|
-
this.pubNub.unsubscribe({
|
|
127
|
-
channels: [this.channel],
|
|
128
|
-
});
|
|
129
|
-
this.pubNub.stop();
|
|
130
|
-
this.pubNub = undefined;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
TransportImplPubNub.prototype.isStarted = function () {
|
|
134
|
-
return this.pubNub != null;
|
|
135
|
-
};
|
|
136
|
-
TransportImplPubNub.prototype.sendAsync = function (channel, message) {
|
|
137
|
-
var _a;
|
|
138
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
return __generator(this, function (_b) {
|
|
140
|
-
switch (_b.label) {
|
|
141
|
-
case 0: return [4 /*yield*/, ((_a = this.pubNub) === null || _a === void 0 ? void 0 : _a.publish({
|
|
142
|
-
channel: channel,
|
|
143
|
-
message: message,
|
|
144
|
-
}))];
|
|
145
|
-
case 1:
|
|
146
|
-
_b.sent();
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
TransportImplPubNub.prototype.onVerifyCodeMessageSize = function (codeMessage) {
|
|
153
|
-
// Calculate unencoded size (quickly) and if that exceeds the limit
|
|
154
|
-
// then don't bother calculating the exact size (which is more expensive)
|
|
155
|
-
var approxSize = 0;
|
|
156
|
-
for (var path in codeMessage.diff) {
|
|
157
|
-
approxSize += path.length + codeMessage.diff[path].length;
|
|
158
|
-
}
|
|
159
|
-
if (approxSize >= TransportImplBase_1.default.CODE_SIZE_LIMIT_FOR_DIFF) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
// Calculate exact size and check whether it exceeds the limit
|
|
163
|
-
var size = calcPubNubCodeMessageSize(this.channel, codeMessage);
|
|
164
|
-
return size < TransportImplBase_1.default.CODE_SIZE_LIMIT_FOR_DIFF;
|
|
165
|
-
};
|
|
166
|
-
return TransportImplPubNub;
|
|
167
|
-
}(TransportImplBase_1.default));
|
|
168
|
-
exports.default = TransportImplPubNub;
|
|
169
|
-
//# sourceMappingURL=TransportImplPubNub.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransportImplPubNub.js","sourceRoot":"","sources":["../../src/transports/TransportImplPubNub.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4B;AAG5B,0EAAoD;AAEpD,SAAgB,yBAAyB,CAAC,OAAe,EAAE,WAAgC;IACzF,+GAA+G;IAC/G,OAAO,CACL,kBAAkB,CAChB,OAAO;QACL,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,CACjC,WAAW,EACX,UAAC,CAAC,IAAK,OAAA,MAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAI,EAAhD,CAAgD,CACxD,CACJ,CAAC,MAAM,GAAG,GAAG,CACf,CAAC;A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QACnB,KAAK,IAAM,IAAI,IAAI,WAAW,CAAC,IAAI,EAAE;YACnC,UAAU,IAAI,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;SAC3D;QACD,IAAI,UAAU,IAAI,2BAAiB,CAAC,wBAAwB,EAAE;YAC5D,OAAO,KAAK,CAAC;SACd;QAED,8DAA8D;QAC9D,IAAM,IAAI,GAAG,yBAAyB,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAClE,OAAO,IAAI,GAAG,2BAAiB,CAAC,wBAAwB,CAAC;IAC3D,CAAC;IAsBH,0BAAC;AAAD,CAAC,AAtGD,CAAiD,2BAAiB,GAsGjE","sourcesContent":["import PubNub from 'pubnub';\n\nimport { ProtocolOutgoingMessage, ProtocolIncomingMessage, ProtocolCodeMessage } from './Protocol';\nimport TransportImplBase from './TransportImplBase';\n\nexport function calcPubNubCodeMessageSize(channel: string, codeMessage: ProtocolCodeMessage) {\n // https://support.pubnub.com/hc/en-us/articles/360051495932-Calculating-message-payload-size-before-publishing\n return (\n encodeURIComponent(\n channel +\n JSON.stringify(codeMessage).replace(\n /[!~*'()]/g,\n (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`,\n ),\n ).length + 200\n );\n}\n\nexport default class TransportImplPubNub extends TransportImplBase {\n private pubNub?: PubNub;\n private pubNubClientId?: string;\n\n protected start() {\n this.stop();\n\n if (!this.pubNubClientId) {\n // Keep track of the client ID per transport instance.\n // See: https://support.pubnub.com/hc/en-us/articles/360051496532-How-do-I-set-the-UUID-\n this.pubNubClientId = PubNub.generateUUID();\n }\n\n if (this.channel) {\n this.logger?.comm('Starting channel...', this.channel, this.logSuffix);\n this.pubNub = new PubNub({\n publishKey: 'pub-c-2a7fd67b-333d-40db-ad2d-3255f8835f70',\n subscribeKey: 'sub-c-0b655000-d784-11e6-b950-02ee2ddab7fe',\n uuid: this.pubNubClientId,\n ssl: true,\n presenceTimeout: 600,\n heartbeatInterval: 60,\n });\n\n this.pubNub.addListener({\n presence: this.onPubNubPresence,\n message: this.onPubNubMessage,\n status: this.onPubNubStatus,\n });\n\n this.pubNub.subscribe({\n channels: [this.channel],\n withPresence: true,\n });\n }\n }\n\n protected stop() {\n if (this.pubNub) {\n this.logger?.comm('Stopping...', this.logSuffix);\n this.pubNub.removeListener({\n presence: this.onPubNubPresence,\n message: this.onPubNubMessage,\n status: this.onPubNubStatus,\n });\n\n this.pubNub.unsubscribe({\n channels: [this.channel],\n });\n\n this.pubNub.stop();\n this.pubNub = undefined;\n }\n }\n\n protected isStarted() {\n return this.pubNub != null;\n }\n\n protected async sendAsync(channel: string, message: ProtocolOutgoingMessage): Promise<void> {\n await this.pubNub?.publish({\n channel,\n message,\n });\n }\n\n protected onVerifyCodeMessageSize(codeMessage: ProtocolCodeMessage): boolean {\n // Calculate unencoded size (quickly) and if that exceeds the limit\n // then don't bother calculating the exact size (which is more expensive)\n let approxSize = 0;\n for (const path in codeMessage.diff) {\n approxSize += path.length + codeMessage.diff[path].length;\n }\n if (approxSize >= TransportImplBase.CODE_SIZE_LIMIT_FOR_DIFF) {\n return false;\n }\n\n // Calculate exact size and check whether it exceeds the limit\n const size = calcPubNubCodeMessageSize(this.channel, codeMessage);\n return size < TransportImplBase.CODE_SIZE_LIMIT_FOR_DIFF;\n }\n\n private onPubNubPresence = (event: PubNub.PresenceEvent) => {\n switch (event.action) {\n case 'join':\n this.handleChannelEvent('join', event.uuid);\n break;\n case 'timeout':\n case 'leave':\n this.handleChannelEvent('leave', event.uuid);\n break;\n }\n };\n\n private onPubNubMessage = (event: PubNub.MessageEvent) => {\n const message: ProtocolIncomingMessage = event.message;\n this.handleMessage(event.publisher, message);\n };\n\n private onPubNubStatus = (_event: PubNub.StatusEvent) => {\n // TODO: Do something here?\n };\n}\n"]}
|