snack-sdk 3.9.0 → 4.0.0
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/CHANGELOG.md +18 -8
- package/build/Session.d.ts +9 -3
- package/build/Session.js +61 -34
- package/build/Session.js.map +1 -1
- package/build/defaultConfig.d.ts +2 -0
- package/build/defaultConfig.js +3 -1
- package/build/defaultConfig.js.map +1 -1
- package/build/transports/CompositeTransport.d.ts +8 -0
- package/build/transports/CompositeTransport.js +33 -0
- package/build/transports/CompositeTransport.js.map +1 -0
- package/build/transports/CompositedTransport.d.ts +8 -0
- package/build/transports/CompositedTransport.js +33 -0
- package/build/transports/CompositedTransport.js.map +1 -0
- package/build/transports/ConnectionMetricsEmitter.d.ts +23 -0
- package/build/transports/ConnectionMetricsEmitter.js +49 -0
- package/build/transports/ConnectionMetricsEmitter.js.map +1 -0
- package/build/transports/TrafficMirroringTransport.d.ts +8 -0
- package/build/transports/TrafficMirroringTransport.js +33 -0
- package/build/transports/TrafficMirroringTransport.js.map +1 -0
- package/build/transports/TransportImplBase.d.ts +51 -0
- package/build/transports/TransportImplBase.js +231 -0
- package/build/transports/TransportImplBase.js.map +1 -0
- package/build/transports/TransportImplComposited.d.ts +8 -0
- package/build/transports/TransportImplComposited.js +33 -0
- package/build/transports/TransportImplComposited.js.map +1 -0
- package/build/transports/TransportImplPubNub.d.ts +15 -0
- package/build/transports/TransportImplPubNub.js +169 -0
- package/build/transports/TransportImplPubNub.js.map +1 -0
- package/build/transports/TransportImplSocketIO.d.ts +18 -0
- package/build/transports/TransportImplSocketIO.js +122 -0
- package/build/transports/TransportImplSocketIO.js.map +1 -0
- package/build/transports/TransportImplWebPlayer.d.ts +23 -0
- package/build/transports/TransportImplWebPlayer.js +128 -0
- package/build/transports/TransportImplWebPlayer.js.map +1 -0
- package/build/transports/index.d.ts +3 -0
- package/build/transports/index.js +11 -3
- package/build/transports/index.js.map +1 -1
- package/build/transports/types.d.ts +2 -3
- package/build/transports/types.js.map +1 -1
- package/build/transports/webPlayer.d.ts +1 -2
- package/build/transports/webPlayer.js +5 -57
- package/build/transports/webPlayer.js.map +1 -1
- package/build/types.d.ts +5 -1
- package/build/types.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,122 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
var socket_io_client_1 = require("socket.io-client");
|
|
20
|
+
var ConnectionMetricsEmitter_1 = __importDefault(require("./ConnectionMetricsEmitter"));
|
|
21
|
+
var TransportImplBase_1 = __importDefault(require("./TransportImplBase"));
|
|
22
|
+
var TransportImplSocketIO = /** @class */ (function (_super) {
|
|
23
|
+
__extends(TransportImplSocketIO, _super);
|
|
24
|
+
function TransportImplSocketIO(options) {
|
|
25
|
+
var _this = _super.call(this, options) || this;
|
|
26
|
+
_this.socket = null;
|
|
27
|
+
_this.onMessage = function (data) {
|
|
28
|
+
var sender = data.sender, message = data.message;
|
|
29
|
+
_this.handleMessage(sender, message);
|
|
30
|
+
};
|
|
31
|
+
_this.onJoinChannel = function (data) {
|
|
32
|
+
var _a;
|
|
33
|
+
var sender = data.sender;
|
|
34
|
+
if (sender !== '' && sender !== ((_a = _this.socket) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
35
|
+
_this.handleChannelEvent('join', sender);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
_this.onLeaveChannel = function (data) {
|
|
39
|
+
var _a;
|
|
40
|
+
var sender = data.sender;
|
|
41
|
+
if (sender !== '' && sender !== ((_a = _this.socket) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
42
|
+
_this.handleChannelEvent('leave', sender);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var snackpubURL = options.snackpubURL;
|
|
46
|
+
if (!snackpubURL) {
|
|
47
|
+
throw new Error('The `snackpubURL` option is unspecified.');
|
|
48
|
+
}
|
|
49
|
+
_this.snackpubURL = snackpubURL;
|
|
50
|
+
_this.connectionAttempts = 0;
|
|
51
|
+
return _this;
|
|
52
|
+
}
|
|
53
|
+
TransportImplSocketIO.prototype.start = function () {
|
|
54
|
+
var _this = this;
|
|
55
|
+
this.stop();
|
|
56
|
+
this.startTime = Date.now();
|
|
57
|
+
this.socket = socket_io_client_1.io(this.snackpubURL, { transports: ['websocket'] });
|
|
58
|
+
this.socket.on('connect', function () {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
(_a = _this.socket) === null || _a === void 0 ? void 0 : _a.emit('subscribeChannel', { channel: _this.channel, sender: (_b = _this.socket) === null || _b === void 0 ? void 0 : _b.id });
|
|
61
|
+
if (_this.startTime) {
|
|
62
|
+
ConnectionMetricsEmitter_1.default.emitSuccessed({
|
|
63
|
+
timeMs: Date.now() - _this.startTime,
|
|
64
|
+
attempts: _this.connectionAttempts,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.socket.io.on('reconnect_attempt', function (attempts) {
|
|
69
|
+
_this.connectionAttempts = attempts;
|
|
70
|
+
if (_this.startTime) {
|
|
71
|
+
ConnectionMetricsEmitter_1.default.emitFailed({
|
|
72
|
+
timeMs: Date.now() - _this.startTime,
|
|
73
|
+
attempts: attempts,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
this.socket.on('message', this.onMessage);
|
|
78
|
+
this.socket.on('joinChannel', this.onJoinChannel);
|
|
79
|
+
this.socket.on('leaveChannel', this.onLeaveChannel);
|
|
80
|
+
this.socket.on('terminate', function (reason) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
(_a = _this.logger) === null || _a === void 0 ? void 0 : _a.comm("Terminating connection: " + reason);
|
|
83
|
+
(_b = _this.socket) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
TransportImplSocketIO.prototype.stop = function () {
|
|
87
|
+
var _a;
|
|
88
|
+
if (this.socket != null) {
|
|
89
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.comm('Stopping...', this.logSuffix);
|
|
90
|
+
this.socket.offAny();
|
|
91
|
+
this.socket.close();
|
|
92
|
+
this.socket = null;
|
|
93
|
+
}
|
|
94
|
+
this.startTime = undefined;
|
|
95
|
+
};
|
|
96
|
+
TransportImplSocketIO.prototype.isStarted = function () {
|
|
97
|
+
return this.socket != null;
|
|
98
|
+
};
|
|
99
|
+
TransportImplSocketIO.prototype.sendAsync = function (channel, message) {
|
|
100
|
+
var _a;
|
|
101
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.emit('message', {
|
|
102
|
+
channel: channel,
|
|
103
|
+
message: message,
|
|
104
|
+
sender: this.socket.id,
|
|
105
|
+
});
|
|
106
|
+
return Promise.resolve();
|
|
107
|
+
};
|
|
108
|
+
TransportImplSocketIO.prototype.onVerifyCodeMessageSize = function (codeMessage) {
|
|
109
|
+
// https://socket.io/docs/v4/server-options/#maxhttpbuffersize
|
|
110
|
+
var MAX_SIZE = 1e6;
|
|
111
|
+
// Calculate unencoded size (quickly) and if that exceeds the limit
|
|
112
|
+
// then don't bother calculating the exact size (which is more expensive)
|
|
113
|
+
var approxSize = 0;
|
|
114
|
+
for (var path in codeMessage.diff) {
|
|
115
|
+
approxSize += path.length + codeMessage.diff[path].length;
|
|
116
|
+
}
|
|
117
|
+
return approxSize < MAX_SIZE;
|
|
118
|
+
};
|
|
119
|
+
return TransportImplSocketIO;
|
|
120
|
+
}(TransportImplBase_1.default));
|
|
121
|
+
exports.default = TransportImplSocketIO;
|
|
122
|
+
//# sourceMappingURL=TransportImplSocketIO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransportImplSocketIO.js","sourceRoot":"","sources":["../../src/transports/TransportImplSocketIO.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,qDAAsC;AAGtC,wFAAkE;AAElE,0EAAoD;AAgBpD;IAAmD,yCAAiB;IAMlE,+BAAY,OAA8B;QAA1C,YACE,kBAAM,OAAO,CAAC,SAOf;QAZO,YAAM,GAA8D,IAAI,CAAC;QAqFzE,eAAS,GAAG,UAAC,IAIpB;YACS,IAAA,MAAM,GAAc,IAAI,OAAlB,EAAE,OAAO,GAAK,IAAI,QAAT,CAAU;YACjC,KAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC;QAEM,mBAAa,GAAG,UAAC,IAAyC;;YACxD,IAAA,MAAM,GAAK,IAAI,OAAT,CAAU;YACxB,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,YAAK,KAAI,CAAC,MAAM,0CAAE,EAAE,CAAA,EAAE;gBAC/C,KAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aACzC;QACH,CAAC,CAAC;QAEM,oBAAc,GAAG,UAAC,IAAyC;;YACzD,IAAA,MAAM,GAAK,IAAI,OAAT,CAAU;YACxB,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,YAAK,KAAI,CAAC,MAAM,0CAAE,EAAE,CAAA,EAAE;gBAC/C,KAAI,CAAC,k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AAO,EAAE,CAAC;IAC3B,CAAC;IAES,uDAAuB,GAAjC,UAAkC,WAAgC;QAChE,8DAA8D;QAC9D,IAAM,QAAQ,GAAG,GAAG,CAAC;QAErB,mEAAmE;QACnE,yEAAyE;QACzE,IAAI,UAAU,GAAG,CAAC,CAAC;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,OAAO,UAAU,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAwBH,4BAAC;AAAD,CAAC,AA7GD,CAAmD,2BAAiB,GA6GnE","sourcesContent":["import { io } from 'socket.io-client';\nimport type { Socket } from 'socket.io-client';\n\nimport ConnectionMetricsEmitter from './ConnectionMetricsEmitter';\nimport { ProtocolOutgoingMessage, ProtocolIncomingMessage, ProtocolCodeMessage } from './Protocol';\nimport TransportImplBase from './TransportImplBase';\nimport type { SnackTransportOptions } from './types';\n\ninterface ServerToClientEvents {\n message: (data: { channel: string; message: ProtocolIncomingMessage; sender: string }) => void;\n joinChannel: (data: { channel: string; sender: string }) => void;\n leaveChannel: (data: { channel: string; sender: string }) => void;\n terminate: (reason: string) => void;\n}\n\ninterface ClientToServerEvents {\n message: (data: { channel: string; message: ProtocolOutgoingMessage; sender: string }) => void;\n subscribeChannel: (data: { channel: string; sender: string }) => void;\n unsubscribeChannel: (data: { channel: string; sender: string }) => void;\n}\n\nexport default class TransportImplSocketIO extends TransportImplBase {\n private readonly snackpubURL: string;\n private socket: Socket<ServerToClientEvents, ClientToServerEvents> | null = null;\n private startTime: number | undefined;\n private connectionAttempts: number;\n\n constructor(options: SnackTransportOptions) {\n super(options);\n const { snackpubURL } = options;\n if (!snackpubURL) {\n throw new Error('The `snackpubURL` option is unspecified.');\n }\n this.snackpubURL = snackpubURL;\n this.connectionAttempts = 0;\n }\n\n protected start(): void {\n this.stop();\n this.startTime = Date.now();\n\n this.socket = io(this.snackpubURL, { transports: ['websocket'] });\n\n this.socket.on('connect', () => {\n this.socket?.emit('subscribeChannel', { channel: this.channel, sender: this.socket?.id });\n if (this.startTime) {\n ConnectionMetricsEmitter.emitSuccessed({\n timeMs: Date.now() - this.startTime,\n attempts: this.connectionAttempts,\n });\n }\n });\n this.socket.io.on('reconnect_attempt', (attempts: number) => {\n this.connectionAttempts = attempts;\n if (this.startTime) {\n ConnectionMetricsEmitter.emitFailed({\n timeMs: Date.now() - this.startTime,\n attempts,\n });\n }\n });\n\n this.socket.on('message', this.onMessage);\n this.socket.on('joinChannel', this.onJoinChannel);\n this.socket.on('leaveChannel', this.onLeaveChannel);\n this.socket.on('terminate', (reason) => {\n this.logger?.comm(`Terminating connection: ${reason}`);\n this.socket?.disconnect();\n });\n }\n\n protected stop(): void {\n if (this.socket != null) {\n this.logger?.comm('Stopping...', this.logSuffix);\n\n this.socket.offAny();\n this.socket.close();\n this.socket = null;\n }\n this.startTime = undefined;\n }\n\n protected isStarted(): boolean {\n return this.socket != null;\n }\n\n protected sendAsync(channel: string, message: ProtocolOutgoingMessage): Promise<void> {\n this.socket?.emit('message', {\n channel,\n message,\n sender: this.socket.id,\n });\n return Promise.resolve();\n }\n\n protected onVerifyCodeMessageSize(codeMessage: ProtocolCodeMessage): boolean {\n // https://socket.io/docs/v4/server-options/#maxhttpbuffersize\n const MAX_SIZE = 1e6;\n\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 return approxSize < MAX_SIZE;\n }\n\n private onMessage = (data: {\n channel: string;\n message: ProtocolIncomingMessage;\n sender: string;\n }) => {\n const { sender, message } = data;\n this.handleMessage(sender, message);\n };\n\n private onJoinChannel = (data: { channel: string; sender: string }) => {\n const { sender } = data;\n if (sender !== '' && sender !== this.socket?.id) {\n this.handleChannelEvent('join', sender);\n }\n };\n\n private onLeaveChannel = (data: { channel: string; sender: string }) => {\n const { sender } = data;\n if (sender !== '' && sender !== this.socket?.id) {\n this.handleChannelEvent('leave', sender);\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SnackWindowRef } from '../types';
|
|
2
|
+
import type { ProtocolOutgoingMessage, ProtocolCodeMessage } from './Protocol';
|
|
3
|
+
import TransportImplBase from './TransportImplBase';
|
|
4
|
+
export interface TransportWebPlayerConfig {
|
|
5
|
+
name?: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
webPlayerURL: string;
|
|
8
|
+
window: Window;
|
|
9
|
+
ref: SnackWindowRef;
|
|
10
|
+
}
|
|
11
|
+
export default class TransportImplWebPlayer extends TransportImplBase {
|
|
12
|
+
private currentWindow;
|
|
13
|
+
private targetWindowRef;
|
|
14
|
+
private status;
|
|
15
|
+
private readonly origin;
|
|
16
|
+
constructor(config: TransportWebPlayerConfig);
|
|
17
|
+
protected start(): void;
|
|
18
|
+
protected stop(): void;
|
|
19
|
+
protected isStarted(): boolean;
|
|
20
|
+
protected sendAsync(channel: string, message: ProtocolOutgoingMessage): Promise<void>;
|
|
21
|
+
protected onVerifyCodeMessageSize(codeMessage: ProtocolCodeMessage): boolean;
|
|
22
|
+
handleDomWindowMessage: (event: MessageEvent) => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
var assert_1 = __importDefault(require("assert"));
|
|
56
|
+
var TransportImplBase_1 = __importDefault(require("./TransportImplBase"));
|
|
57
|
+
var TransportImplWebPlayer = /** @class */ (function (_super) {
|
|
58
|
+
__extends(TransportImplWebPlayer, _super);
|
|
59
|
+
function TransportImplWebPlayer(config) {
|
|
60
|
+
var _this = _super.call(this, { name: config.name, verbose: config.verbose }) || this;
|
|
61
|
+
_this.status = 'stopped';
|
|
62
|
+
_this.handleDomWindowMessage = function (event) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (event.origin === _this.origin) {
|
|
65
|
+
try {
|
|
66
|
+
var message = JSON.parse(event.data);
|
|
67
|
+
var type = message.type;
|
|
68
|
+
if (type === 'CONNECT') {
|
|
69
|
+
var connectionId = JSON.stringify(message.device);
|
|
70
|
+
_this.handleChannelEvent('join', connectionId);
|
|
71
|
+
}
|
|
72
|
+
else if (type === 'DISCONNECT') {
|
|
73
|
+
var connectionId = JSON.stringify(message.device);
|
|
74
|
+
_this.handleChannelEvent('leave', connectionId);
|
|
75
|
+
}
|
|
76
|
+
else if (type === 'MESSAGE') {
|
|
77
|
+
var connectionId = JSON.stringify(message.message.device);
|
|
78
|
+
_this.handleMessage(connectionId, message.message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
(_a = _this.logger) === null || _a === void 0 ? void 0 : _a.warn('Invalid message', event.data);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var origin = new URL(config.webPlayerURL).origin;
|
|
87
|
+
_this.currentWindow = config.window;
|
|
88
|
+
_this.targetWindowRef = config.ref;
|
|
89
|
+
_this.status = 'stopped';
|
|
90
|
+
_this.origin = origin;
|
|
91
|
+
return _this;
|
|
92
|
+
}
|
|
93
|
+
TransportImplWebPlayer.prototype.start = function () {
|
|
94
|
+
var _a;
|
|
95
|
+
assert_1.default(this.currentWindow);
|
|
96
|
+
(_a = this.currentWindow) === null || _a === void 0 ? void 0 : _a.addEventListener('message', this.handleDomWindowMessage, false);
|
|
97
|
+
this.status = 'started';
|
|
98
|
+
};
|
|
99
|
+
TransportImplWebPlayer.prototype.stop = function () {
|
|
100
|
+
assert_1.default(this.currentWindow);
|
|
101
|
+
this.currentWindow.removeEventListener('message', this.handleDomWindowMessage, false);
|
|
102
|
+
this.currentWindow = undefined;
|
|
103
|
+
this.targetWindowRef = undefined;
|
|
104
|
+
this.status = 'stopped';
|
|
105
|
+
};
|
|
106
|
+
TransportImplWebPlayer.prototype.isStarted = function () {
|
|
107
|
+
return this.status === 'started' && this.currentWindow != null;
|
|
108
|
+
};
|
|
109
|
+
TransportImplWebPlayer.prototype.sendAsync = function (channel, message) {
|
|
110
|
+
var _a;
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var targetWindow;
|
|
113
|
+
return __generator(this, function (_b) {
|
|
114
|
+
assert_1.default(this.isStarted);
|
|
115
|
+
targetWindow = (_a = this.targetWindowRef) === null || _a === void 0 ? void 0 : _a.current;
|
|
116
|
+
assert_1.default(targetWindow);
|
|
117
|
+
targetWindow.postMessage(JSON.stringify(message), this.origin);
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
TransportImplWebPlayer.prototype.onVerifyCodeMessageSize = function (codeMessage) {
|
|
123
|
+
return true;
|
|
124
|
+
};
|
|
125
|
+
return TransportImplWebPlayer;
|
|
126
|
+
}(TransportImplBase_1.default));
|
|
127
|
+
exports.default = TransportImplWebPlayer;
|
|
128
|
+
//# sourceMappingURL=TransportImplWebPlayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransportImplWebPlayer.js","sourceRoot":"","sources":["../../src/transports/TransportImplWebPlayer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4B;AAI5B,0EAAoD;AAUpD;IAAoD,0CAAiB;IAMnE,gCAAY,MAAgC;QAA5C,YACE,kBAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,SAMtD;QAVO,YAAM,GAA0B,SAAS,CAAC;QAyClD,4BAAsB,GAAG,UAAC,KAAmB;;YAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,KAAI,CAAC,MAAM,EAAE;gBAChC,IAAI;oBACF,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC/B,IAAA,IAAI,GAAK,OAAO,KAAZ,CAAa;oBACzB,IAAI,IAAI,KAAK,SAAS,EAAE;wBACtB,IAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;wBACpD,KAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;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C,CAAC;QACtF,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAES,0CAAS,GAAnB;QACE,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC;IACjE,CAAC;IAEe,0CAAS,GAAzB,UAA0B,OAAe,EAAE,OAAgC;;;;;gBACzE,gBAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACjB,YAAY,SAAG,IAAI,CAAC,eAAe,0CAAE,OAAO,CAAC;gBACnD,gBAAM,CAAC,YAAY,CAAC,CAAC;gBACrB,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;;;;KAChE;IAES,wDAAuB,GAAjC,UAAkC,WAAgC;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;IAsBH,6BAAC;AAAD,CAAC,AAhED,CAAoD,2BAAiB,GAgEpE","sourcesContent":["import assert from 'assert';\n\nimport type { SnackWindowRef } from '../types';\nimport type { ProtocolOutgoingMessage, ProtocolCodeMessage } from './Protocol';\nimport TransportImplBase from './TransportImplBase';\n\nexport interface TransportWebPlayerConfig {\n name?: string;\n verbose?: boolean;\n webPlayerURL: string;\n window: Window;\n ref: SnackWindowRef;\n}\n\nexport default class TransportImplWebPlayer extends TransportImplBase {\n private currentWindow: Window | undefined;\n private targetWindowRef: SnackWindowRef | undefined;\n private status: 'stopped' | 'started' = 'stopped';\n private readonly origin: string;\n\n constructor(config: TransportWebPlayerConfig) {\n super({ name: config.name, verbose: config.verbose });\n const { origin } = new URL(config.webPlayerURL);\n this.currentWindow = config.window;\n this.targetWindowRef = config.ref;\n this.status = 'stopped';\n this.origin = origin;\n }\n\n protected start(): void {\n assert(this.currentWindow);\n this.currentWindow?.addEventListener('message', this.handleDomWindowMessage, false);\n this.status = 'started';\n }\n\n protected stop(): void {\n assert(this.currentWindow);\n this.currentWindow.removeEventListener('message', this.handleDomWindowMessage, false);\n this.currentWindow = undefined;\n this.targetWindowRef = undefined;\n this.status = 'stopped';\n }\n\n protected isStarted(): boolean {\n return this.status === 'started' && this.currentWindow != null;\n }\n\n protected async sendAsync(channel: string, message: ProtocolOutgoingMessage): Promise<void> {\n assert(this.isStarted);\n const targetWindow = this.targetWindowRef?.current;\n assert(targetWindow);\n targetWindow.postMessage(JSON.stringify(message), this.origin);\n }\n\n protected onVerifyCodeMessageSize(codeMessage: ProtocolCodeMessage): boolean {\n return true;\n }\n\n handleDomWindowMessage = (event: MessageEvent) => {\n if (event.origin === this.origin) {\n try {\n const message = JSON.parse(event.data);\n const { type } = message;\n if (type === 'CONNECT') {\n const connectionId = JSON.stringify(message.device);\n this.handleChannelEvent('join', connectionId);\n } else if (type === 'DISCONNECT') {\n const connectionId = JSON.stringify(message.device);\n this.handleChannelEvent('leave', connectionId);\n } else if (type === 'MESSAGE') {\n const connectionId = JSON.stringify(message.message.device);\n this.handleMessage(connectionId, message.message);\n }\n } catch (e: unknown) {\n this.logger?.warn('Invalid message', event.data);\n }\n }\n };\n}\n"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { SnackTransport, SnackTransportOptions } from './types';
|
|
2
2
|
export * from './types';
|
|
3
|
+
export * from './ConnectionMetricsEmitter';
|
|
4
|
+
export { default as ConnectionMetricsEmitter } from './ConnectionMetricsEmitter';
|
|
3
5
|
export declare function createTransport(options: SnackTransportOptions): SnackTransport;
|
|
6
|
+
export declare function createTrafficMirroringTransport(options: SnackTransportOptions): SnackTransport;
|
|
@@ -13,11 +13,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.createTransport = void 0;
|
|
17
|
-
var
|
|
16
|
+
exports.createTrafficMirroringTransport = exports.createTransport = exports.ConnectionMetricsEmitter = void 0;
|
|
17
|
+
var TrafficMirroringTransport_1 = __importDefault(require("./TrafficMirroringTransport"));
|
|
18
|
+
var TransportImplSocketIO_1 = __importDefault(require("./TransportImplSocketIO"));
|
|
18
19
|
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./ConnectionMetricsEmitter"), exports);
|
|
21
|
+
var ConnectionMetricsEmitter_1 = require("./ConnectionMetricsEmitter");
|
|
22
|
+
Object.defineProperty(exports, "ConnectionMetricsEmitter", { enumerable: true, get: function () { return __importDefault(ConnectionMetricsEmitter_1).default; } });
|
|
19
23
|
function createTransport(options) {
|
|
20
|
-
return new
|
|
24
|
+
return new TransportImplSocketIO_1.default(options);
|
|
21
25
|
}
|
|
22
26
|
exports.createTransport = createTransport;
|
|
27
|
+
function createTrafficMirroringTransport(options) {
|
|
28
|
+
return new TrafficMirroringTransport_1.default(options);
|
|
29
|
+
}
|
|
30
|
+
exports.createTrafficMirroringTransport = createTrafficMirroringTransport;
|
|
23
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0FAAoE;AACpE,kFAA4D;AAG5D,0CAAwB;AACxB,6DAA2C;AAC3C,uEAAiF;AAAxE,qJAAA,OAAO,OAA4B;AAE5C,SAAgB,eAAe,CAAC,OAA8B;IAC5D,OAAO,IAAI,+BAAqB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAFD,0CAEC;AAED,SAAgB,+BAA+B,CAAC,OAA8B;IAC5E,OAAO,IAAI,mCAAyB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AAFD,0EAEC","sourcesContent":["import TrafficMirroringTransport from './TrafficMirroringTransport';\nimport TransportImplSocketIO from './TransportImplSocketIO';\nimport { SnackTransport, SnackTransportOptions } from './types';\n\nexport * from './types';\nexport * from './ConnectionMetricsEmitter';\nexport { default as ConnectionMetricsEmitter } from './ConnectionMetricsEmitter';\n\nexport function createTransport(options: SnackTransportOptions): SnackTransport {\n return new TransportImplSocketIO(options);\n}\n\nexport function createTrafficMirroringTransport(options: SnackTransportOptions): SnackTransport {\n return new TrafficMirroringTransport(options);\n}\n"]}
|
|
@@ -31,9 +31,7 @@ export declare type SnackTransportEventConnect = {
|
|
|
31
31
|
export declare type SnackTransportEventDisconnect = {
|
|
32
32
|
type: 'disconnect';
|
|
33
33
|
connectionId: string;
|
|
34
|
-
data:
|
|
35
|
-
timedout: boolean;
|
|
36
|
-
};
|
|
34
|
+
data: any;
|
|
37
35
|
};
|
|
38
36
|
export declare type SnackTransportEventProtocolMessage = {
|
|
39
37
|
type: 'protocol_message';
|
|
@@ -60,4 +58,5 @@ export declare type SnackTransportOptions = {
|
|
|
60
58
|
apiURL?: string;
|
|
61
59
|
verbose?: boolean;
|
|
62
60
|
name?: string;
|
|
61
|
+
snackpubURL?: string | undefined;
|
|
63
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/transports/types.ts"],"names":[],"mappings":"","sourcesContent":["import { SnackFiles, SnackDependencies, SDKVersion } from 'snack-content';\n\nimport { ProtocolOutgoingMessage, ProtocolIncomingMessage } from './Protocol';\n\nexport type SnackTransportStartMessage = {\n type: 'start';\n};\n\nexport type SnackTransportStopMessage = {\n type: 'stop';\n};\n\nexport type SnackTransportUpdateCodeMessage = {\n type: 'update_code';\n data: {\n files: SnackFiles;\n dependencies: SnackDependencies;\n sdkVersion: SDKVersion;\n };\n};\n\nexport type SnackTransportProtocolMessage = {\n type: 'protocol_message';\n data: ProtocolOutgoingMessage;\n};\n\nexport type SnackTransportSyntheticMessage = {\n type: 'synthetic_event';\n data: any;\n};\n\nexport type SnackTransportMessage =\n | SnackTransportStartMessage\n | SnackTransportStopMessage\n | SnackTransportUpdateCodeMessage\n | SnackTransportProtocolMessage\n | SnackTransportSyntheticMessage;\n\nexport type SnackTransportEventConnect = {\n type: 'connect';\n connectionId: string;\n data: any; // DeviceInfo\n};\n\nexport type SnackTransportEventDisconnect = {\n type: 'disconnect';\n connectionId: string;\n data
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/transports/types.ts"],"names":[],"mappings":"","sourcesContent":["import { SnackFiles, SnackDependencies, SDKVersion } from 'snack-content';\n\nimport { ProtocolOutgoingMessage, ProtocolIncomingMessage } from './Protocol';\n\nexport type SnackTransportStartMessage = {\n type: 'start';\n};\n\nexport type SnackTransportStopMessage = {\n type: 'stop';\n};\n\nexport type SnackTransportUpdateCodeMessage = {\n type: 'update_code';\n data: {\n files: SnackFiles;\n dependencies: SnackDependencies;\n sdkVersion: SDKVersion;\n };\n};\n\nexport type SnackTransportProtocolMessage = {\n type: 'protocol_message';\n data: ProtocolOutgoingMessage;\n};\n\nexport type SnackTransportSyntheticMessage = {\n type: 'synthetic_event';\n data: any;\n};\n\nexport type SnackTransportMessage =\n | SnackTransportStartMessage\n | SnackTransportStopMessage\n | SnackTransportUpdateCodeMessage\n | SnackTransportProtocolMessage\n | SnackTransportSyntheticMessage;\n\nexport type SnackTransportEventConnect = {\n type: 'connect';\n connectionId: string;\n data: any; // DeviceInfo\n};\n\nexport type SnackTransportEventDisconnect = {\n type: 'disconnect';\n connectionId: string;\n // Keeps the `data` keys here for SnackTransportEvent polymorphism, even though we do not use the data in disconnect event actually\n data: any;\n};\n\nexport type SnackTransportEventProtocolMessage = {\n type: 'protocol_message';\n connectionId: string;\n data: ProtocolIncomingMessage;\n};\n\nexport type SnackTransportEventSendMessage = {\n type: 'send_message';\n data: ProtocolOutgoingMessage;\n};\n\nexport type SnackTransportEventSyntheticMessage = {\n type: 'synthetic_event';\n data: any;\n};\n\nexport type SnackTransportEvent =\n | SnackTransportEventConnect\n | SnackTransportEventDisconnect\n | SnackTransportEventProtocolMessage\n | SnackTransportEventSendMessage\n | SnackTransportEventSyntheticMessage;\n\nexport type SnackTransportListener = (event: SnackTransportEvent) => void;\n\nexport interface SnackTransport {\n addEventListener(type: 'message', listener: SnackTransportListener): void;\n removeEventListener(type: 'message', listener: SnackTransportListener): void;\n postMessage(message: SnackTransportMessage): void;\n}\n\nexport type SnackTransportOptions = {\n channel?: string;\n apiURL?: string;\n verbose?: boolean;\n name?: string;\n snackpubURL?: string | undefined;\n};\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { SDKVersion } from 'snack-content';
|
|
2
2
|
import { SnackWindowRef } from '../types';
|
|
3
|
-
import { SnackTransport
|
|
3
|
+
import { SnackTransport } from './types';
|
|
4
4
|
export declare function createWebPlayerTransport(config: {
|
|
5
5
|
name?: string;
|
|
6
6
|
verbose?: boolean;
|
|
7
7
|
webPlayerURL: string;
|
|
8
8
|
window: Window;
|
|
9
9
|
ref: SnackWindowRef;
|
|
10
|
-
createTransport: (options: SnackTransportOptions) => SnackTransport;
|
|
11
10
|
}): SnackTransport;
|
|
12
11
|
export declare function getWebPlayerIFrameURL(webPlayerURL: string, sdkVersion: SDKVersion, initialURL: string, verbose: boolean): string | undefined;
|
|
@@ -1,64 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getWebPlayerIFrameURL = exports.createWebPlayerTransport = void 0;
|
|
7
|
+
var TransportImplWebPlayer_1 = __importDefault(require("./TransportImplWebPlayer"));
|
|
4
8
|
function createWebPlayerTransport(config) {
|
|
5
|
-
|
|
6
|
-
function getTransport() {
|
|
7
|
-
var _a;
|
|
8
|
-
transport = transport !== null && transport !== void 0 ? transport : config.createTransport({
|
|
9
|
-
name: (_a = config.name) !== null && _a !== void 0 ? _a : 'webplayer',
|
|
10
|
-
verbose: config.verbose,
|
|
11
|
-
});
|
|
12
|
-
return transport;
|
|
13
|
-
}
|
|
14
|
-
var origin = new URL(config.webPlayerURL).origin;
|
|
15
|
-
var windowListener;
|
|
16
|
-
var transportListener;
|
|
17
|
-
return {
|
|
18
|
-
addEventListener: function (type, listener) {
|
|
19
|
-
var _a;
|
|
20
|
-
if (!windowListener) {
|
|
21
|
-
windowListener = function (event) {
|
|
22
|
-
if (event.origin === origin && typeof event.data === 'string') {
|
|
23
|
-
if (transport) {
|
|
24
|
-
transport.postMessage({
|
|
25
|
-
type: 'synthetic_event',
|
|
26
|
-
data: event.data,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
(_a = config.window) === null || _a === void 0 ? void 0 : _a.addEventListener(type, windowListener);
|
|
32
|
-
}
|
|
33
|
-
if (!transportListener) {
|
|
34
|
-
transportListener = function (event) {
|
|
35
|
-
var _a;
|
|
36
|
-
var message = event;
|
|
37
|
-
if (message.type === 'synthetic_event') {
|
|
38
|
-
(_a = config.ref.current) === null || _a === void 0 ? void 0 : _a.postMessage(JSON.stringify(message.data), origin);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
listener(message);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
getTransport().addEventListener(type, transportListener);
|
|
46
|
-
},
|
|
47
|
-
removeEventListener: function (type, _listener) {
|
|
48
|
-
var _a;
|
|
49
|
-
if (windowListener) {
|
|
50
|
-
(_a = config.window) === null || _a === void 0 ? void 0 : _a.removeEventListener(type, windowListener);
|
|
51
|
-
windowListener = undefined;
|
|
52
|
-
}
|
|
53
|
-
if (transportListener) {
|
|
54
|
-
transport === null || transport === void 0 ? void 0 : transport.removeEventListener(type, transportListener);
|
|
55
|
-
transportListener = undefined;
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
postMessage: function (message) { return getTransport().postMessage(message); },
|
|
59
|
-
// @ts-ignore: Dirty hack to allow snack web to to communicate with older web-players
|
|
60
|
-
updateOrigin: function (newOrigin) { return (origin = newOrigin); },
|
|
61
|
-
};
|
|
9
|
+
return new TransportImplWebPlayer_1.default(config);
|
|
62
10
|
}
|
|
63
11
|
exports.createWebPlayerTransport = createWebPlayerTransport;
|
|
64
12
|
function getWebPlayerIFrameURL(webPlayerURL, sdkVersion, initialURL, verbose) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webPlayer.js","sourceRoot":"","sources":["../../src/transports/webPlayer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webPlayer.js","sourceRoot":"","sources":["../../src/transports/webPlayer.ts"],"names":[],"mappings":";;;;;;AAGA,oFAA8D;AAG9D,SAAgB,wBAAwB,CAAC,MAMxC;IACC,OAAO,IAAI,gCAAsB,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AARD,4DAQC;AAED,SAAgB,qBAAqB,CACnC,YAAoB,EACpB,UAAsB,EACtB,UAAkB,EAClB,OAAgB;IAEhB,IAAI,UAAU,GAAG,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAC1D,OAAO,SAAS,CAAC;KAClB;IAED,OAAU,YAAY,CAAC,OAAO,CAC5B,iBAAiB,EACjB,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACzB,+BAA0B,kBAAkB,CAAC,UAAU,CAAC,gBAAW,kBAAkB,CACpF,MAAM,CAAC,QAAQ,CAAC,MAAM,CACvB,iBAAY,OAAS,CAAC;AACzB,CAAC;AAhBD,sDAgBC","sourcesContent":["import { SDKVersion } from 'snack-content';\n\nimport { SnackWindowRef } from '../types';\nimport TransportImplWebPlayer from './TransportImplWebPlayer';\nimport { SnackTransport } from './types';\n\nexport function createWebPlayerTransport(config: {\n name?: string;\n verbose?: boolean;\n webPlayerURL: string;\n window: Window;\n ref: SnackWindowRef;\n}): SnackTransport {\n return new TransportImplWebPlayer(config);\n}\n\nexport function getWebPlayerIFrameURL(\n webPlayerURL: string,\n sdkVersion: SDKVersion,\n initialURL: string,\n verbose: boolean\n) {\n if (sdkVersion < '40.0.0' || typeof window === 'undefined') {\n return undefined;\n }\n\n return `${webPlayerURL.replace(\n '%%SDK_VERSION%%',\n sdkVersion.split('.')[0]\n )}/index.html?initialUrl=${encodeURIComponent(initialURL)}&origin=${encodeURIComponent(\n window.location.origin\n )}&verbose=${verbose}`;\n}\n"]}
|
package/build/types.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ export declare type SnackState = {
|
|
|
107
107
|
*/
|
|
108
108
|
online: boolean;
|
|
109
109
|
/**
|
|
110
|
-
* Communication channel ("
|
|
110
|
+
* Communication channel ("pubsub") through which live updates are transferred.
|
|
111
111
|
* The communication channel is only used when the Snack is "online".
|
|
112
112
|
*/
|
|
113
113
|
channel: string;
|
|
@@ -182,4 +182,8 @@ export declare type SnackState = {
|
|
|
182
182
|
* of the iframe.
|
|
183
183
|
*/
|
|
184
184
|
webPreviewURL?: string;
|
|
185
|
+
/**
|
|
186
|
+
* The runtime URL to serve webPlayer.
|
|
187
|
+
*/
|
|
188
|
+
webPlayerURL?: string;
|
|
185
189
|
};
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n SDKVersion,\n SnackDependencies,\n SnackDependencyVersions,\n SnackFiles,\n SnackMissingDependencies,\n} from 'snack-content';\n\nimport { SnackTransport } from './transports';\n\n/**\n * An error that can optionally hold a file-name and line/column location.\n */\nexport interface SnackError extends Error {\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n}\n\nexport type SnackConnectedClientStatus = 'ok' | 'error' | 'reloading';\n\n/**\n * Client which connected to the Snack.\n *\n * Clients are only able to connect when the Snack is `online`.\n */\nexport type SnackConnectedClient = {\n transport: string;\n id: string;\n name: string;\n platform: string;\n status: SnackConnectedClientStatus;\n error?: SnackError;\n previewURL?: string;\n previewTimestamp?: number;\n};\n\n/**\n * Collection of connected clients.\n */\nexport type SnackConnectedClients = {\n [key: string]: SnackConnectedClient;\n};\n\n/**\n * User that is used for communicating with the Expo servers.\n */\nexport type SnackUser = {\n sessionSecret?: string;\n accessToken?: string;\n};\n\n/**\n * Request data to be used with the `sendBeacon` API.\n */\nexport type SnackSendBeaconRequest = {\n url: string;\n data: any;\n};\n\nexport type SnackListenerSubscription = () => any;\n\n/**\n * Log data for when a connected client calls one of the\n * `console.[log,info,warn,error]` to log information to the\n * console.\n */\nexport type SnackLogEvent = {\n type: 'error' | 'warn' | 'log' | 'info';\n message: string;\n connectedClient?: SnackConnectedClient;\n error?: SnackError;\n};\n\nexport type SnackWindowRef = {\n current: Window | null;\n};\n\nexport type SnackState = {\n /**\n * Expo SDK version.\n */\n sdkVersion: SDKVersion;\n\n /**\n * Files that make up the content (code & assets) of the Snack. There should\n * always be a file called \"App.js\" or \"App.tsx\" as the main entry point.\n */\n files: SnackFiles;\n\n /**\n * Packages that can be used in the code files. Packages that are pre-loaded\n * by the sdk may be ommited, but it is recommended to add them anyway.\n */\n dependencies: SnackDependencies;\n\n /**\n * Optional name. The name is used when saving or downloading the Snack; and is used\n * for the onlineName property.\n */\n name: string;\n\n /**\n * Additional description of the Snack. The description is used when saving the Snack\n * and may also be used for searching purposes.\n */\n description: string;\n\n /**\n * Collection of dependencies that are missing but are required by one or more of\n * the dependencies.\n */\n missingDependencies: SnackMissingDependencies;\n\n /**\n * Collection of packages and versions that are compatible with the selected\n * SDK version. This is similar to using `expo install`, which ensures the latest\n * compatible version is installed.\n */\n wantedDependencyVersions?: SnackDependencyVersions;\n\n /**\n * Disabled state. When the Snack is disabled it will not resolve any dependencies\n * or upload any asset files. It also disables the ability to go online.\n */\n disabled: boolean;\n\n /**\n * When online is true, Expo clients can connect to the Snack and receive live updates\n * when code or dependencies are changed. It also makes the Snack visible in the\n * \"Recently in Development\" section of the Expo client.\n */\n online: boolean;\n\n /**\n * Communication channel (\"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n SDKVersion,\n SnackDependencies,\n SnackDependencyVersions,\n SnackFiles,\n SnackMissingDependencies,\n} from 'snack-content';\n\nimport { SnackTransport } from './transports';\n\n/**\n * An error that can optionally hold a file-name and line/column location.\n */\nexport interface SnackError extends Error {\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n}\n\nexport type SnackConnectedClientStatus = 'ok' | 'error' | 'reloading';\n\n/**\n * Client which connected to the Snack.\n *\n * Clients are only able to connect when the Snack is `online`.\n */\nexport type SnackConnectedClient = {\n transport: string;\n id: string;\n name: string;\n platform: string;\n status: SnackConnectedClientStatus;\n error?: SnackError;\n previewURL?: string;\n previewTimestamp?: number;\n};\n\n/**\n * Collection of connected clients.\n */\nexport type SnackConnectedClients = {\n [key: string]: SnackConnectedClient;\n};\n\n/**\n * User that is used for communicating with the Expo servers.\n */\nexport type SnackUser = {\n sessionSecret?: string;\n accessToken?: string;\n};\n\n/**\n * Request data to be used with the `sendBeacon` API.\n */\nexport type SnackSendBeaconRequest = {\n url: string;\n data: any;\n};\n\nexport type SnackListenerSubscription = () => any;\n\n/**\n * Log data for when a connected client calls one of the\n * `console.[log,info,warn,error]` to log information to the\n * console.\n */\nexport type SnackLogEvent = {\n type: 'error' | 'warn' | 'log' | 'info';\n message: string;\n connectedClient?: SnackConnectedClient;\n error?: SnackError;\n};\n\nexport type SnackWindowRef = {\n current: Window | null;\n};\n\nexport type SnackState = {\n /**\n * Expo SDK version.\n */\n sdkVersion: SDKVersion;\n\n /**\n * Files that make up the content (code & assets) of the Snack. There should\n * always be a file called \"App.js\" or \"App.tsx\" as the main entry point.\n */\n files: SnackFiles;\n\n /**\n * Packages that can be used in the code files. Packages that are pre-loaded\n * by the sdk may be ommited, but it is recommended to add them anyway.\n */\n dependencies: SnackDependencies;\n\n /**\n * Optional name. The name is used when saving or downloading the Snack; and is used\n * for the onlineName property.\n */\n name: string;\n\n /**\n * Additional description of the Snack. The description is used when saving the Snack\n * and may also be used for searching purposes.\n */\n description: string;\n\n /**\n * Collection of dependencies that are missing but are required by one or more of\n * the dependencies.\n */\n missingDependencies: SnackMissingDependencies;\n\n /**\n * Collection of packages and versions that are compatible with the selected\n * SDK version. This is similar to using `expo install`, which ensures the latest\n * compatible version is installed.\n */\n wantedDependencyVersions?: SnackDependencyVersions;\n\n /**\n * Disabled state. When the Snack is disabled it will not resolve any dependencies\n * or upload any asset files. It also disables the ability to go online.\n */\n disabled: boolean;\n\n /**\n * When online is true, Expo clients can connect to the Snack and receive live updates\n * when code or dependencies are changed. It also makes the Snack visible in the\n * \"Recently in Development\" section of the Expo client.\n */\n online: boolean;\n\n /**\n * Communication channel (\"pubsub\") through which live updates are transferred.\n * The communication channel is only used when the Snack is \"online\".\n */\n channel: string;\n\n /**\n * Device-id of the Expo client. When set causes the Snack to be visible in the\n * \"Recently in Development\" section of the Expo client with that device-id.\n * The device-id is only used when the Snack is \"online\".\n */\n deviceId?: string;\n\n /**\n * Unique experience url which can be used to open the Expo client and connect\n * to the Snack (e.g. \"exp://exp.host/@snack/sdk.38.0.0-78173941\").\n */\n url: string;\n\n /**\n * Name of the Snack as shown in the \"Recently in Development\" section in the\n * Expo client. The online-name will be empty when the Snack is not \"online\".\n */\n onlineName?: string;\n\n /**\n * A close request that should be send using the browser `sendBeacon` API\n * whenever the browser session is unloaded. This gives the Snack a last opportunity\n * to gracefully close its connections so that the \"Recently in Development\"\n * section in the Expo client no longer shows the Snack.\n */\n sendBeaconCloseRequest?: SnackSendBeaconRequest;\n\n /**\n * @internal\n */\n transports: { [id: string]: SnackTransport };\n\n /**\n * Clients that are currently connected.\n */\n connectedClients: SnackConnectedClients;\n\n /**\n *\n */\n user?: SnackUser;\n\n /**\n * Unsaved status of the Snack. Becomes `true` when the Snack code is changed and\n * `false` whenever the Snack is saved.\n */\n unsaved: boolean;\n\n /**\n * Full name of the saved Snack.\n */\n id?: string;\n\n /**\n * Id of this version of the saved Snack. Each Snack can have many different versions or revisions, each revision has its own snackId.\n */\n snackId?: string;\n\n /**\n * Id of a Snack saved to an account. This id points to the latest version of a Snack revision and associated user.\n */\n accountSnackId?: string;\n\n /**\n * URL of the saved Snack.\n * The URL is empty when no save \"id\" is available.\n */\n saveURL?: string;\n\n /**\n * Last saved (non-draft) Expo SDK version.\n */\n savedSDKVersion?: string;\n\n /**\n * URL to use to when loading the web-preview in an iframe.\n *\n * Web-preview is supported from SDK 40 and higher.\n * To enable it, set the `webPreviewRef` to the contentWindow\n * of the iframe.\n */\n webPreviewURL?: string;\n\n /**\n * The runtime URL to serve webPlayer.\n */\n webPlayerURL?: string;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snack-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "The Expo Snack SDK",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"nullthrows": "^1.1.1",
|
|
69
69
|
"pubnub": "^7.2.0",
|
|
70
70
|
"semver": "^7.3.4",
|
|
71
|
-
"snack-content": "
|
|
71
|
+
"snack-content": "~1.3.0",
|
|
72
|
+
"socket.io-client": "~4.5.4",
|
|
72
73
|
"ua-parser-js": "^0.7.22",
|
|
73
74
|
"validate-npm-package-name": "^3.0.0"
|
|
74
75
|
}
|