snack-sdk 3.8.0 → 3.9.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 +22 -0
- package/build/DependencyResolver.d.ts +26 -26
- package/build/DependencyResolver.js +258 -258
- package/build/DevSession.d.ts +20 -20
- package/build/DevSession.js +203 -203
- package/build/FileUploader.d.ts +23 -23
- package/build/FileUploader.js +174 -174
- package/build/Logger.d.ts +11 -11
- package/build/Logger.js +33 -33
- package/build/Session.d.ts +301 -301
- package/build/Session.js +1172 -1171
- package/build/Session.js.map +1 -1
- package/build/State.d.ts +16 -16
- package/build/State.js +90 -90
- package/build/WantedVersions.d.ts +40 -17
- package/build/WantedVersions.js +156 -93
- package/build/WantedVersions.js.map +1 -1
- package/build/defaultConfig.d.ts +12 -12
- package/build/defaultConfig.js +29 -29
- package/build/index.d.ts +7 -7
- package/build/index.js +30 -30
- package/build/transports/CodeMessageBuilder.d.ts +31 -31
- package/build/transports/CodeMessageBuilder.js +196 -196
- package/build/transports/Protocol.d.ts +64 -64
- package/build/transports/Protocol.js +2 -2
- package/build/transports/Transport.d.ts +28 -27
- package/build/transports/Transport.js +303 -298
- package/build/transports/Transport.js.map +1 -1
- package/build/transports/index.d.ts +3 -3
- package/build/transports/index.js +22 -22
- package/build/transports/types.d.ts +63 -63
- package/build/transports/types.js +2 -2
- package/build/transports/webPlayer.d.ts +12 -12
- package/build/transports/webPlayer.js +70 -70
- package/build/types.d.ts +185 -185
- package/build/types.js +2 -2
- package/build/utils.d.ts +17 -17
- package/build/utils.js +68 -68
- package/package.json +11 -4
- package/src/DependencyResolver.ts +0 -218
- package/src/DevSession.ts +0 -159
- package/src/FileUploader.ts +0 -135
- package/src/Logger.ts +0 -33
- package/src/Session.ts +0 -1293
- package/src/State.ts +0 -98
- package/src/WantedVersions.ts +0 -57
- package/src/defaultConfig.ts +0 -33
- package/src/index.ts +0 -59
- package/src/transports/CodeMessageBuilder.ts +0 -226
- package/src/transports/Protocol.ts +0 -78
- package/src/transports/Transport.ts +0 -270
- package/src/transports/index.ts +0 -8
- package/src/transports/types.ts +0 -89
- package/src/transports/webPlayer.ts +0 -93
- package/src/types.ts +0 -223
- package/src/utils.ts +0 -71
- package/tsconfig.json +0 -28
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import PubNub from 'pubnub';
|
|
2
|
-
|
|
3
|
-
import { createLogger, Logger } from '../Logger';
|
|
4
|
-
import CodeMessageBuilder, { CodeMessageBuilderCallback } from './CodeMessageBuilder';
|
|
5
|
-
import { ProtocolOutgoingMessage, ProtocolIncomingMessage, ProtocolCodeMessage } from './Protocol';
|
|
6
|
-
import {
|
|
7
|
-
SnackTransport,
|
|
8
|
-
SnackTransportListener,
|
|
9
|
-
SnackTransportMessage,
|
|
10
|
-
SnackTransportOptions,
|
|
11
|
-
} from './types';
|
|
12
|
-
|
|
13
|
-
export function calcPubNubCodeMessageSize(channel: string, codeMessage: ProtocolCodeMessage) {
|
|
14
|
-
// https://support.pubnub.com/hc/en-us/articles/360051495932-Calculating-message-payload-size-before-publishing
|
|
15
|
-
return (
|
|
16
|
-
encodeURIComponent(
|
|
17
|
-
channel +
|
|
18
|
-
JSON.stringify(codeMessage).replace(
|
|
19
|
-
/[!~*'()]/g,
|
|
20
|
-
(x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`
|
|
21
|
-
)
|
|
22
|
-
).length + 200
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default class Transport implements SnackTransport {
|
|
27
|
-
private readonly channel: string;
|
|
28
|
-
private readonly logger?: Logger;
|
|
29
|
-
private callback?: SnackTransportListener;
|
|
30
|
-
private pubNub?: PubNub;
|
|
31
|
-
private codeMessageBuilder: CodeMessageBuilder;
|
|
32
|
-
private codeMessage?: ProtocolCodeMessage;
|
|
33
|
-
private connectionsCount: number = 0;
|
|
34
|
-
private readonly logSuffix: string;
|
|
35
|
-
|
|
36
|
-
constructor(options: SnackTransportOptions) {
|
|
37
|
-
const { apiURL, channel, verbose } = options;
|
|
38
|
-
this.channel = channel ?? '';
|
|
39
|
-
this.logger = verbose ? createLogger(true) : undefined;
|
|
40
|
-
this.logSuffix = options.name ? ` (${options.name})` : '';
|
|
41
|
-
|
|
42
|
-
if (channel) {
|
|
43
|
-
this.codeMessageBuilder = new CodeMessageBuilder({
|
|
44
|
-
verifyCodeMessageSize: this.onPubNubVerifyCodeMessageSize,
|
|
45
|
-
callback: this.onCodeMessageReady,
|
|
46
|
-
apiURL,
|
|
47
|
-
logger: this.logger,
|
|
48
|
-
maxDiffPlaceholder: 'X'.repeat(32768),
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
this.codeMessageBuilder = new CodeMessageBuilder({
|
|
52
|
-
verifyCodeMessageSize: () => true,
|
|
53
|
-
callback: this.onCodeMessageReady,
|
|
54
|
-
logger: this.logger,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
addEventListener(_type: 'message', callback: SnackTransportListener) {
|
|
60
|
-
this.callback = callback;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
removeEventListener(_type: 'message', _callback: SnackTransportListener) {
|
|
64
|
-
this.callback = undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
postMessage(message: SnackTransportMessage) {
|
|
68
|
-
switch (message.type) {
|
|
69
|
-
case 'start':
|
|
70
|
-
this.start();
|
|
71
|
-
break;
|
|
72
|
-
case 'stop':
|
|
73
|
-
this.stop();
|
|
74
|
-
break;
|
|
75
|
-
case 'update_code':
|
|
76
|
-
this.codeMessageBuilder.setCode(message.data);
|
|
77
|
-
break;
|
|
78
|
-
case 'protocol_message':
|
|
79
|
-
this.publish(message.data);
|
|
80
|
-
break;
|
|
81
|
-
case 'synthetic_event':
|
|
82
|
-
this.onSyntheticEvent(message.data);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private start() {
|
|
88
|
-
this.stop();
|
|
89
|
-
|
|
90
|
-
if (this.channel) {
|
|
91
|
-
this.logger?.comm('Starting channel...', this.channel, this.logSuffix);
|
|
92
|
-
this.pubNub = new PubNub({
|
|
93
|
-
publishKey: 'pub-c-2a7fd67b-333d-40db-ad2d-3255f8835f70',
|
|
94
|
-
subscribeKey: 'sub-c-0b655000-d784-11e6-b950-02ee2ddab7fe',
|
|
95
|
-
ssl: true,
|
|
96
|
-
// uuid: TODO
|
|
97
|
-
presenceTimeout: 600,
|
|
98
|
-
heartbeatInterval: 60,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
this.pubNub.addListener({
|
|
102
|
-
presence: this.onPubNubPresence,
|
|
103
|
-
message: this.onPubNubMessage,
|
|
104
|
-
status: this.onPubNubStatus,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
this.pubNub.subscribe({
|
|
108
|
-
channels: [this.channel],
|
|
109
|
-
withPresence: true,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private stop() {
|
|
115
|
-
if (this.pubNub) {
|
|
116
|
-
this.logger?.comm('Stopping...', this.logSuffix);
|
|
117
|
-
this.pubNub.removeListener({
|
|
118
|
-
presence: this.onPubNubPresence,
|
|
119
|
-
message: this.onPubNubMessage,
|
|
120
|
-
status: this.onPubNubStatus,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
this.pubNub.unsubscribe({
|
|
124
|
-
channels: [this.channel],
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
this.pubNub.stop();
|
|
128
|
-
this.pubNub = undefined;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private onProtocolMessage(connectionId: string, message: ProtocolIncomingMessage) {
|
|
133
|
-
if (message.type === 'RESEND_CODE') {
|
|
134
|
-
if (this.codeMessage) {
|
|
135
|
-
this.logger?.comm('Resending code...', this.logSuffix);
|
|
136
|
-
this.publish(this.codeMessage);
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
this.callback?.({
|
|
140
|
-
type: 'protocol_message',
|
|
141
|
-
connectionId,
|
|
142
|
-
data: message,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private async publish(message: ProtocolOutgoingMessage) {
|
|
148
|
-
if (!this.connectionsCount) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (this.pubNub) {
|
|
152
|
-
try {
|
|
153
|
-
await this.pubNub.publish({
|
|
154
|
-
channel: this.channel,
|
|
155
|
-
message,
|
|
156
|
-
});
|
|
157
|
-
} catch (e) {
|
|
158
|
-
this.logger?.error('Failed to publish message', message.type, e, this.logSuffix);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
this.callback?.({
|
|
162
|
-
type: 'synthetic_event',
|
|
163
|
-
data: message,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
this.callback?.({
|
|
167
|
-
type: 'send_message',
|
|
168
|
-
data: message,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private onPubNubPresence = (event: PubNub.PresenceEvent) => {
|
|
173
|
-
switch (event.action) {
|
|
174
|
-
case 'join':
|
|
175
|
-
try {
|
|
176
|
-
const device = JSON.parse(event.uuid);
|
|
177
|
-
this.connectionsCount++;
|
|
178
|
-
this.callback?.({
|
|
179
|
-
type: 'connect',
|
|
180
|
-
connectionId: event.uuid,
|
|
181
|
-
data: device,
|
|
182
|
-
});
|
|
183
|
-
if (this.codeMessage) {
|
|
184
|
-
this.logger?.comm('Sending code...', this.logSuffix);
|
|
185
|
-
this.publish(this.codeMessage);
|
|
186
|
-
}
|
|
187
|
-
} catch (e) {
|
|
188
|
-
// Wasn't from the device
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
case 'timeout':
|
|
192
|
-
case 'leave':
|
|
193
|
-
this.connectionsCount = Math.max(this.connectionsCount - 1, 0);
|
|
194
|
-
this.callback?.({
|
|
195
|
-
type: 'disconnect',
|
|
196
|
-
connectionId: event.uuid,
|
|
197
|
-
data: {
|
|
198
|
-
timedout: event.action === 'timeout',
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
private onPubNubMessage = (event: PubNub.MessageEvent) => {
|
|
206
|
-
const message: ProtocolIncomingMessage = event.message;
|
|
207
|
-
this.onProtocolMessage(event.publisher, message);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
private onPubNubStatus = (_event: PubNub.StatusEvent) => {
|
|
211
|
-
// TODO: Do something here?
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
private onPubNubVerifyCodeMessageSize = (codeMessage: ProtocolCodeMessage) => {
|
|
215
|
-
// Calculate unencoded size (quickly) and if that exceeds the limit
|
|
216
|
-
// then don't bother calculating the exact size (which is more expensive)
|
|
217
|
-
let approxSize = 0;
|
|
218
|
-
for (const path in codeMessage.diff) {
|
|
219
|
-
approxSize += path.length + codeMessage.diff[path].length;
|
|
220
|
-
}
|
|
221
|
-
if (approxSize >= 32768) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Calculate exact size and check whether it exceeds the limit
|
|
226
|
-
const size = calcPubNubCodeMessageSize(this.channel, codeMessage);
|
|
227
|
-
return size < 32768;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
private onSyntheticEvent(data: any) {
|
|
231
|
-
if (typeof data !== 'string') {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
const message = JSON.parse(data);
|
|
237
|
-
switch (message.type) {
|
|
238
|
-
case 'CONNECT':
|
|
239
|
-
this.connectionsCount++;
|
|
240
|
-
this.callback?.({
|
|
241
|
-
type: 'connect',
|
|
242
|
-
connectionId: JSON.stringify(message.device),
|
|
243
|
-
data: message.device,
|
|
244
|
-
});
|
|
245
|
-
break;
|
|
246
|
-
case 'DISCONNECT':
|
|
247
|
-
this.connectionsCount = Math.max(this.connectionsCount - 1, 0);
|
|
248
|
-
this.callback?.({
|
|
249
|
-
type: 'disconnect',
|
|
250
|
-
connectionId: JSON.stringify(message.device),
|
|
251
|
-
data: {
|
|
252
|
-
timedout: false,
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
break;
|
|
256
|
-
case 'MESSAGE':
|
|
257
|
-
this.onProtocolMessage(JSON.stringify(message.message.device), message.message);
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
} catch (e) {
|
|
261
|
-
this.logger?.error('Failed to parse postMessage', e, data, this.logSuffix);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private onCodeMessageReady: CodeMessageBuilderCallback = (codeMessage) => {
|
|
266
|
-
this.codeMessage = codeMessage;
|
|
267
|
-
this.logger?.comm('Sending code...', this.logSuffix);
|
|
268
|
-
this.publish(codeMessage);
|
|
269
|
-
};
|
|
270
|
-
}
|
package/src/transports/index.ts
DELETED
package/src/transports/types.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { SnackFiles, SnackDependencies, SDKVersion } from 'snack-content';
|
|
2
|
-
|
|
3
|
-
import { ProtocolOutgoingMessage, ProtocolIncomingMessage } from './Protocol';
|
|
4
|
-
|
|
5
|
-
export type SnackTransportStartMessage = {
|
|
6
|
-
type: 'start';
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type SnackTransportStopMessage = {
|
|
10
|
-
type: 'stop';
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type SnackTransportUpdateCodeMessage = {
|
|
14
|
-
type: 'update_code';
|
|
15
|
-
data: {
|
|
16
|
-
files: SnackFiles;
|
|
17
|
-
dependencies: SnackDependencies;
|
|
18
|
-
sdkVersion: SDKVersion;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type SnackTransportProtocolMessage = {
|
|
23
|
-
type: 'protocol_message';
|
|
24
|
-
data: ProtocolOutgoingMessage;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type SnackTransportSyntheticMessage = {
|
|
28
|
-
type: 'synthetic_event';
|
|
29
|
-
data: any;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type SnackTransportMessage =
|
|
33
|
-
| SnackTransportStartMessage
|
|
34
|
-
| SnackTransportStopMessage
|
|
35
|
-
| SnackTransportUpdateCodeMessage
|
|
36
|
-
| SnackTransportProtocolMessage
|
|
37
|
-
| SnackTransportSyntheticMessage;
|
|
38
|
-
|
|
39
|
-
export type SnackTransportEventConnect = {
|
|
40
|
-
type: 'connect';
|
|
41
|
-
connectionId: string;
|
|
42
|
-
data: any; // DeviceInfo
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type SnackTransportEventDisconnect = {
|
|
46
|
-
type: 'disconnect';
|
|
47
|
-
connectionId: string;
|
|
48
|
-
data: {
|
|
49
|
-
timedout: boolean;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type SnackTransportEventProtocolMessage = {
|
|
54
|
-
type: 'protocol_message';
|
|
55
|
-
connectionId: string;
|
|
56
|
-
data: ProtocolIncomingMessage;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type SnackTransportEventSendMessage = {
|
|
60
|
-
type: 'send_message';
|
|
61
|
-
data: ProtocolOutgoingMessage;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type SnackTransportEventSyntheticMessage = {
|
|
65
|
-
type: 'synthetic_event';
|
|
66
|
-
data: any;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type SnackTransportEvent =
|
|
70
|
-
| SnackTransportEventConnect
|
|
71
|
-
| SnackTransportEventDisconnect
|
|
72
|
-
| SnackTransportEventProtocolMessage
|
|
73
|
-
| SnackTransportEventSendMessage
|
|
74
|
-
| SnackTransportEventSyntheticMessage;
|
|
75
|
-
|
|
76
|
-
export type SnackTransportListener = (event: SnackTransportEvent) => void;
|
|
77
|
-
|
|
78
|
-
export interface SnackTransport {
|
|
79
|
-
addEventListener(type: 'message', listener: SnackTransportListener): void;
|
|
80
|
-
removeEventListener(type: 'message', listener: SnackTransportListener): void;
|
|
81
|
-
postMessage(message: SnackTransportMessage): void;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type SnackTransportOptions = {
|
|
85
|
-
channel?: string;
|
|
86
|
-
apiURL?: string;
|
|
87
|
-
verbose?: boolean;
|
|
88
|
-
name?: string;
|
|
89
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { SDKVersion } from 'snack-content';
|
|
2
|
-
|
|
3
|
-
import { SnackWindowRef } from '../types';
|
|
4
|
-
import {
|
|
5
|
-
SnackTransport,
|
|
6
|
-
SnackTransportOptions,
|
|
7
|
-
SnackTransportListener,
|
|
8
|
-
SnackTransportMessage,
|
|
9
|
-
} from './types';
|
|
10
|
-
|
|
11
|
-
export function createWebPlayerTransport(config: {
|
|
12
|
-
name?: string;
|
|
13
|
-
verbose?: boolean;
|
|
14
|
-
webPlayerURL: string;
|
|
15
|
-
window: Window;
|
|
16
|
-
ref: SnackWindowRef;
|
|
17
|
-
createTransport: (options: SnackTransportOptions) => SnackTransport;
|
|
18
|
-
}): SnackTransport {
|
|
19
|
-
let transport: SnackTransport | null = null;
|
|
20
|
-
function getTransport(): SnackTransport {
|
|
21
|
-
transport =
|
|
22
|
-
transport ??
|
|
23
|
-
config.createTransport({
|
|
24
|
-
name: config.name ?? 'webplayer',
|
|
25
|
-
verbose: config.verbose,
|
|
26
|
-
});
|
|
27
|
-
return transport;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let { origin } = new URL(config.webPlayerURL);
|
|
31
|
-
|
|
32
|
-
let windowListener: ((event: any) => void) | undefined;
|
|
33
|
-
let transportListener: ((event: any) => void) | undefined;
|
|
34
|
-
return {
|
|
35
|
-
addEventListener: (type: 'message', listener: SnackTransportListener) => {
|
|
36
|
-
if (!windowListener) {
|
|
37
|
-
windowListener = (event: any) => {
|
|
38
|
-
if (event.origin === origin && typeof event.data === 'string') {
|
|
39
|
-
if (transport) {
|
|
40
|
-
transport.postMessage({
|
|
41
|
-
type: 'synthetic_event',
|
|
42
|
-
data: event.data,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
config.window?.addEventListener(type, windowListener);
|
|
48
|
-
}
|
|
49
|
-
if (!transportListener) {
|
|
50
|
-
transportListener = (event: any) => {
|
|
51
|
-
const message = event;
|
|
52
|
-
if (message.type === 'synthetic_event') {
|
|
53
|
-
config.ref.current?.postMessage(JSON.stringify(message.data), origin);
|
|
54
|
-
} else {
|
|
55
|
-
listener(message);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
getTransport().addEventListener(type, transportListener);
|
|
60
|
-
},
|
|
61
|
-
removeEventListener: (type: 'message', _listener: SnackTransportListener) => {
|
|
62
|
-
if (windowListener) {
|
|
63
|
-
config.window?.removeEventListener(type, windowListener);
|
|
64
|
-
windowListener = undefined;
|
|
65
|
-
}
|
|
66
|
-
if (transportListener) {
|
|
67
|
-
transport?.removeEventListener(type, transportListener);
|
|
68
|
-
transportListener = undefined;
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
postMessage: (message: SnackTransportMessage) => getTransport().postMessage(message),
|
|
72
|
-
// @ts-ignore: Dirty hack to allow snack web to to communicate with older web-players
|
|
73
|
-
updateOrigin: (newOrigin: string) => (origin = newOrigin),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function getWebPlayerIFrameURL(
|
|
78
|
-
webPlayerURL: string,
|
|
79
|
-
sdkVersion: SDKVersion,
|
|
80
|
-
initialURL: string,
|
|
81
|
-
verbose: boolean
|
|
82
|
-
) {
|
|
83
|
-
if (sdkVersion < '40.0.0' || typeof window === 'undefined') {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return `${webPlayerURL.replace(
|
|
88
|
-
'%%SDK_VERSION%%',
|
|
89
|
-
sdkVersion.split('.')[0]
|
|
90
|
-
)}/index.html?initialUrl=${encodeURIComponent(initialURL)}&origin=${encodeURIComponent(
|
|
91
|
-
window.location.origin
|
|
92
|
-
)}&verbose=${verbose}`;
|
|
93
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SDKVersion,
|
|
3
|
-
SnackDependencies,
|
|
4
|
-
SnackDependencyVersions,
|
|
5
|
-
SnackFiles,
|
|
6
|
-
SnackMissingDependencies,
|
|
7
|
-
} from 'snack-content';
|
|
8
|
-
|
|
9
|
-
import { SnackTransport } from './transports';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* An error that can optionally hold a file-name and line/column location.
|
|
13
|
-
*/
|
|
14
|
-
export interface SnackError extends Error {
|
|
15
|
-
fileName?: string;
|
|
16
|
-
lineNumber?: number;
|
|
17
|
-
columnNumber?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type SnackConnectedClientStatus = 'ok' | 'error' | 'reloading';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Client which connected to the Snack.
|
|
24
|
-
*
|
|
25
|
-
* Clients are only able to connect when the Snack is `online`.
|
|
26
|
-
*/
|
|
27
|
-
export type SnackConnectedClient = {
|
|
28
|
-
transport: string;
|
|
29
|
-
id: string;
|
|
30
|
-
name: string;
|
|
31
|
-
platform: string;
|
|
32
|
-
status: SnackConnectedClientStatus;
|
|
33
|
-
error?: SnackError;
|
|
34
|
-
previewURL?: string;
|
|
35
|
-
previewTimestamp?: number;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Collection of connected clients.
|
|
40
|
-
*/
|
|
41
|
-
export type SnackConnectedClients = {
|
|
42
|
-
[key: string]: SnackConnectedClient;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* User that is used for communicating with the Expo servers.
|
|
47
|
-
*/
|
|
48
|
-
export type SnackUser = {
|
|
49
|
-
sessionSecret?: string;
|
|
50
|
-
accessToken?: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Request data to be used with the `sendBeacon` API.
|
|
55
|
-
*/
|
|
56
|
-
export type SnackSendBeaconRequest = {
|
|
57
|
-
url: string;
|
|
58
|
-
data: any;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export type SnackListenerSubscription = () => any;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Log data for when a connected client calls one of the
|
|
65
|
-
* `console.[log,info,warn,error]` to log information to the
|
|
66
|
-
* console.
|
|
67
|
-
*/
|
|
68
|
-
export type SnackLogEvent = {
|
|
69
|
-
type: 'error' | 'warn' | 'log' | 'info';
|
|
70
|
-
message: string;
|
|
71
|
-
connectedClient?: SnackConnectedClient;
|
|
72
|
-
error?: SnackError;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type SnackWindowRef = {
|
|
76
|
-
current: Window | null;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type SnackState = {
|
|
80
|
-
/**
|
|
81
|
-
* Expo SDK version.
|
|
82
|
-
*/
|
|
83
|
-
sdkVersion: SDKVersion;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Files that make up the content (code & assets) of the Snack. There should
|
|
87
|
-
* always be a file called "App.js" or "App.tsx" as the main entry point.
|
|
88
|
-
*/
|
|
89
|
-
files: SnackFiles;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Packages that can be used in the code files. Packages that are pre-loaded
|
|
93
|
-
* by the sdk may be ommited, but it is recommended to add them anyway.
|
|
94
|
-
*/
|
|
95
|
-
dependencies: SnackDependencies;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Optional name. The name is used when saving or downloading the Snack; and is used
|
|
99
|
-
* for the onlineName property.
|
|
100
|
-
*/
|
|
101
|
-
name: string;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Additional description of the Snack. The description is used when saving the Snack
|
|
105
|
-
* and may also be used for searching purposes.
|
|
106
|
-
*/
|
|
107
|
-
description: string;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Collection of dependencies that are missing but are required by one or more of
|
|
111
|
-
* the dependencies.
|
|
112
|
-
*/
|
|
113
|
-
missingDependencies: SnackMissingDependencies;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Collection of packages and versions that are compatible with the selected
|
|
117
|
-
* SDK version. This is similar to using `expo install`, which ensures the latest
|
|
118
|
-
* compatible version is installed.
|
|
119
|
-
*/
|
|
120
|
-
wantedDependencyVersions?: SnackDependencyVersions;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Disabled state. When the Snack is disabled it will not resolve any dependencies
|
|
124
|
-
* or upload any asset files. It also disables the ability to go online.
|
|
125
|
-
*/
|
|
126
|
-
disabled: boolean;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* When online is true, Expo clients can connect to the Snack and receive live updates
|
|
130
|
-
* when code or dependencies are changed. It also makes the Snack visible in the
|
|
131
|
-
* "Recently in Development" section of the Expo client.
|
|
132
|
-
*/
|
|
133
|
-
online: boolean;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Communication channel ("pubnub") through which live updates are transferred.
|
|
137
|
-
* The communication channel is only used when the Snack is "online".
|
|
138
|
-
*/
|
|
139
|
-
channel: string;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Device-id of the Expo client. When set causes the Snack to be visible in the
|
|
143
|
-
* "Recently in Development" section of the Expo client with that device-id.
|
|
144
|
-
* The device-id is only used when the Snack is "online".
|
|
145
|
-
*/
|
|
146
|
-
deviceId?: string;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Unique experience url which can be used to open the Expo client and connect
|
|
150
|
-
* to the Snack (e.g. "exp://exp.host/@snack/sdk.38.0.0-78173941").
|
|
151
|
-
*/
|
|
152
|
-
url: string;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Name of the Snack as shown in the "Recently in Development" section in the
|
|
156
|
-
* Expo client. The online-name will be empty when the Snack is not "online".
|
|
157
|
-
*/
|
|
158
|
-
onlineName?: string;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* A close request that should be send using the browser `sendBeacon` API
|
|
162
|
-
* whenever the browser session is unloaded. This gives the Snack a last opportunity
|
|
163
|
-
* to gracefully close its connections so that the "Recently in Development"
|
|
164
|
-
* section in the Expo client no longer shows the Snack.
|
|
165
|
-
*/
|
|
166
|
-
sendBeaconCloseRequest?: SnackSendBeaconRequest;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
transports: { [id: string]: SnackTransport };
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Clients that are currently connected.
|
|
175
|
-
*/
|
|
176
|
-
connectedClients: SnackConnectedClients;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
user?: SnackUser;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Unsaved status of the Snack. Becomes `true` when the Snack code is changed and
|
|
185
|
-
* `false` whenever the Snack is saved.
|
|
186
|
-
*/
|
|
187
|
-
unsaved: boolean;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Full name of the saved Snack.
|
|
191
|
-
*/
|
|
192
|
-
id?: string;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Id of this version of the saved Snack. Each Snack can have many different versions or revisions, each revision has its own snackId.
|
|
196
|
-
*/
|
|
197
|
-
snackId?: string;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Id of a Snack saved to an account. This id points to the latest version of a Snack revision and associated user.
|
|
201
|
-
*/
|
|
202
|
-
accountSnackId?: string;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* URL of the saved Snack.
|
|
206
|
-
* The URL is empty when no save "id" is available.
|
|
207
|
-
*/
|
|
208
|
-
saveURL?: string;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Last saved (non-draft) Expo SDK version.
|
|
212
|
-
*/
|
|
213
|
-
savedSDKVersion?: string;
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* URL to use to when loading the web-preview in an iframe.
|
|
217
|
-
*
|
|
218
|
-
* Web-preview is supported from SDK 40 and higher.
|
|
219
|
-
* To enable it, set the `webPreviewRef` to the contentWindow
|
|
220
|
-
* of the iframe.
|
|
221
|
-
*/
|
|
222
|
-
webPreviewURL?: string;
|
|
223
|
-
};
|