@lavitre/apps 1.49.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/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/Common/AiChannel.d.ts +59 -0
- package/dist/Common/AiChannel.js +97 -0
- package/dist/Common/AiChannel.js.map +1 -0
- package/dist/Common/BlobStore.d.ts +44 -0
- package/dist/Common/BlobStore.js +186 -0
- package/dist/Common/BlobStore.js.map +1 -0
- package/dist/Common/Common.Model.d.ts +1020 -0
- package/dist/Common/Common.Model.js +21 -0
- package/dist/Common/Common.Model.js.map +1 -0
- package/dist/Common/CrdtChannel.d.ts +198 -0
- package/dist/Common/CrdtChannel.js +659 -0
- package/dist/Common/CrdtChannel.js.map +1 -0
- package/dist/Common/Version.d.ts +21 -0
- package/dist/Common/Version.js +62 -0
- package/dist/Common/Version.js.map +1 -0
- package/dist/Common/index.d.ts +6 -0
- package/dist/Common/index.js +32 -0
- package/dist/Common/index.js.map +1 -0
- package/dist/CompanionConnector/CompanionConnector.Model.d.ts +85 -0
- package/dist/CompanionConnector/CompanionConnector.Model.js +17 -0
- package/dist/CompanionConnector/CompanionConnector.Model.js.map +1 -0
- package/dist/CompanionConnector/CompanionConnector.d.ts +28 -0
- package/dist/CompanionConnector/CompanionConnector.js +385 -0
- package/dist/CompanionConnector/CompanionConnector.js.map +1 -0
- package/dist/CompanionConnector/index.d.ts +2 -0
- package/dist/CompanionConnector/index.js +3 -0
- package/dist/CompanionConnector/index.js.map +1 -0
- package/dist/CompanionFrame/CompanionFrame.d.ts +103 -0
- package/dist/CompanionFrame/CompanionFrame.js +100 -0
- package/dist/CompanionFrame/CompanionFrame.js.map +1 -0
- package/dist/CompanionFrame/index.d.ts +1 -0
- package/dist/CompanionFrame/index.js +2 -0
- package/dist/CompanionFrame/index.js.map +1 -0
- package/dist/Connector/Connector.Model.d.ts +567 -0
- package/dist/Connector/Connector.Model.js +2 -0
- package/dist/Connector/Connector.Model.js.map +1 -0
- package/dist/Connector/Connector.d.ts +227 -0
- package/dist/Connector/Connector.js +1337 -0
- package/dist/Connector/Connector.js.map +1 -0
- package/dist/Connector/index.d.ts +2 -0
- package/dist/Connector/index.js +3 -0
- package/dist/Connector/index.js.map +1 -0
- package/dist/Frame/Frame.Model.d.ts +533 -0
- package/dist/Frame/Frame.Model.js +2 -0
- package/dist/Frame/Frame.Model.js.map +1 -0
- package/dist/Frame/Frame.d.ts +309 -0
- package/dist/Frame/Frame.js +1408 -0
- package/dist/Frame/Frame.js.map +1 -0
- package/dist/Frame/SyncAdapter.d.ts +75 -0
- package/dist/Frame/SyncAdapter.js +134 -0
- package/dist/Frame/SyncAdapter.js.map +1 -0
- package/dist/Frame/index.d.ts +3 -0
- package/dist/Frame/index.js +4 -0
- package/dist/Frame/index.js.map +1 -0
- package/dist/MediaLink/MediaLink.d.ts +178 -0
- package/dist/MediaLink/MediaLink.js +1432 -0
- package/dist/MediaLink/MediaLink.js.map +1 -0
- package/dist/MediaLink/index.d.ts +1 -0
- package/dist/MediaLink/index.js +2 -0
- package/dist/MediaLink/index.js.map +1 -0
- package/dist/Native/index.d.ts +170 -0
- package/dist/Native/index.js +19 -0
- package/dist/Native/index.js.map +1 -0
- package/dist/Version.d.ts +1 -0
- package/dist/Version.js +2 -0
- package/dist/Version.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,1408 @@
|
|
|
1
|
+
/// <reference path="../Connector/insertable-streams.d.ts" />
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import { CrdtChannel, MIN_CRDT_HOST_VERSION } from '../Common/CrdtChannel.js';
|
|
4
|
+
import { BlobStore } from '../Common/BlobStore.js';
|
|
5
|
+
import { AiChannel, MIN_AI_HOST_VERSION } from '../Common/AiChannel.js';
|
|
6
|
+
import { isMinVersion } from '../Common/index.js';
|
|
7
|
+
import { apiVersion } from '../Version.js';
|
|
8
|
+
export class Frame {
|
|
9
|
+
/** @deprecated Use `crdt.doc`. See Connector.yjsDoc for the setter
|
|
10
|
+
* rationale (legacy field-assignment backward-compat). */
|
|
11
|
+
get yjsDoc() {
|
|
12
|
+
return this.crdt.doc;
|
|
13
|
+
}
|
|
14
|
+
set yjsDoc(doc) {
|
|
15
|
+
this.crdt.attach(doc);
|
|
16
|
+
}
|
|
17
|
+
constructor(
|
|
18
|
+
// `protected` (not `private`) so the companion-only subclass
|
|
19
|
+
// `CompanionFrameImpl` (CompanionFrame.ts) can post its companion-frame
|
|
20
|
+
// messages while keeping those methods off the Vitre `Frame` surface.
|
|
21
|
+
postMessage, initMessage, options, initState) {
|
|
22
|
+
Object.defineProperty(this, "postMessage", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: postMessage
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "options", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: options
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "onDeviceJoined", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "onDeviceLeft", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "onDeviceMessageReceived", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "onLocalConnectorMessageReceived", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "onMenuClicked", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: void 0
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(this, "onFieldUpdated", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: void 0
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "onInteractingChanged", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: void 0
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(this, "onPrivacyChanged", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "onFileProgress", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
value: void 0
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "onFileLoaded", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: void 0
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(this, "onExportRequest", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: void 0
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(this, "onKnockKnock", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: void 0
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(this, "onSettingsUpdated", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: void 0
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(this, "onVitreSettingsUpdated", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
configurable: true,
|
|
115
|
+
writable: true,
|
|
116
|
+
value: void 0
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(this, "onConnectionCodeUpdated", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: void 0
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(this, "onNotificationDismissed", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: void 0
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(this, "onNotificationButtonClicked", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
configurable: true,
|
|
133
|
+
writable: true,
|
|
134
|
+
value: void 0
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(this, "onDevicePrivacyChanged", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true,
|
|
140
|
+
value: void 0
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(this, "onDeviceFrameLoaded", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true,
|
|
145
|
+
writable: true,
|
|
146
|
+
value: void 0
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(this, "onDeviceFrameConnectorLoaded", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
configurable: true,
|
|
151
|
+
writable: true,
|
|
152
|
+
value: void 0
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(this, "onDeviceFrameUnloaded", {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
configurable: true,
|
|
157
|
+
writable: true,
|
|
158
|
+
value: void 0
|
|
159
|
+
});
|
|
160
|
+
Object.defineProperty(this, "onMessageReceived", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true,
|
|
163
|
+
writable: true,
|
|
164
|
+
value: void 0
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(this, "onPendingDevicesConnectionRequested", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true,
|
|
169
|
+
writable: true,
|
|
170
|
+
value: void 0
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* Peer-presence events for the companion frame. `onCompanionFramePeersUpdated`
|
|
174
|
+
* is the AUTHORITATIVE full snapshot — it fires on every change with the
|
|
175
|
+
* complete current peer set. `onCompanionFramePeerJoined` /
|
|
176
|
+
* `onCompanionFramePeerLeft` are convenience incremental events derived
|
|
177
|
+
* from the same underlying stream.
|
|
178
|
+
*
|
|
179
|
+
* Subscribe to ONE model, not both: either consume the snapshot and
|
|
180
|
+
* recompute, or consume the incremental pair — wiring up both will
|
|
181
|
+
* double-count every transition.
|
|
182
|
+
*/
|
|
183
|
+
Object.defineProperty(this, "onCompanionFramePeerJoined", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: void 0
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(this, "onCompanionFramePeerLeft", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: void 0
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(this, "onCompanionFramePeersUpdated", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
configurable: true,
|
|
198
|
+
writable: true,
|
|
199
|
+
value: void 0
|
|
200
|
+
});
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Use onBorderOptionsUpdated
|
|
203
|
+
*/
|
|
204
|
+
Object.defineProperty(this, "onBorderlessChanged", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
configurable: true,
|
|
207
|
+
writable: true,
|
|
208
|
+
value: void 0
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(this, "onFullscreenChanged", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
configurable: true,
|
|
213
|
+
writable: true,
|
|
214
|
+
value: void 0
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(this, "onBorderOptionsUpdated", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
configurable: true,
|
|
219
|
+
writable: true,
|
|
220
|
+
value: void 0
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(this, "onVoiceActionDetected", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
configurable: true,
|
|
225
|
+
writable: true,
|
|
226
|
+
value: void 0
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(this, "onStateReplaced", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
configurable: true,
|
|
231
|
+
writable: true,
|
|
232
|
+
value: void 0
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(this, "onPositionUpdated", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
configurable: true,
|
|
237
|
+
writable: true,
|
|
238
|
+
value: void 0
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(this, "onDeviceFullscreenUpdated", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
configurable: true,
|
|
243
|
+
writable: true,
|
|
244
|
+
value: void 0
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(this, "onVisibilityChanged", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
configurable: true,
|
|
249
|
+
writable: true,
|
|
250
|
+
value: void 0
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(this, "onDeviceScalingUpdated", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
configurable: true,
|
|
255
|
+
writable: true,
|
|
256
|
+
value: void 0
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(this, "onUpdateFrameName", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
configurable: true,
|
|
261
|
+
writable: true,
|
|
262
|
+
value: void 0
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(this, "onSharedStreamUpdate", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true,
|
|
268
|
+
value: void 0
|
|
269
|
+
});
|
|
270
|
+
/**
|
|
271
|
+
* Reverse breakout box: fires when the Vitre host exposes a live
|
|
272
|
+
* `MediaStream` it owns INTO this frame (e.g. a received shared camera, or a
|
|
273
|
+
* companion stream routed to this frame for transformation). The stream is
|
|
274
|
+
* rebuilt locally via `MediaStreamTrackGenerator` from transferred readables
|
|
275
|
+
* — zero re-encode, same-site + Chromium only. `streamId` matches a later
|
|
276
|
+
* `onSharedStreamRemoved`. Inverse of {@link shareStream}.
|
|
277
|
+
*/
|
|
278
|
+
Object.defineProperty(this, "onSharedStream", {
|
|
279
|
+
enumerable: true,
|
|
280
|
+
configurable: true,
|
|
281
|
+
writable: true,
|
|
282
|
+
value: void 0
|
|
283
|
+
});
|
|
284
|
+
Object.defineProperty(this, "onSharedStreamRemoved", {
|
|
285
|
+
enumerable: true,
|
|
286
|
+
configurable: true,
|
|
287
|
+
writable: true,
|
|
288
|
+
value: void 0
|
|
289
|
+
});
|
|
290
|
+
Object.defineProperty(this, "onMediaDevicesChanged", {
|
|
291
|
+
enumerable: true,
|
|
292
|
+
configurable: true,
|
|
293
|
+
writable: true,
|
|
294
|
+
value: void 0
|
|
295
|
+
});
|
|
296
|
+
Object.defineProperty(this, "onBluetoothMessage", {
|
|
297
|
+
enumerable: true,
|
|
298
|
+
configurable: true,
|
|
299
|
+
writable: true,
|
|
300
|
+
value: void 0
|
|
301
|
+
});
|
|
302
|
+
/** @deprecated Use `crdt.onSynced` */
|
|
303
|
+
Object.defineProperty(this, "onYjsSynced", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
configurable: true,
|
|
306
|
+
writable: true,
|
|
307
|
+
value: void 0
|
|
308
|
+
});
|
|
309
|
+
/** @deprecated Subscribe via `crdt.doc.on('update', ...)` instead. */
|
|
310
|
+
Object.defineProperty(this, "onYjsUpdate", {
|
|
311
|
+
enumerable: true,
|
|
312
|
+
configurable: true,
|
|
313
|
+
writable: true,
|
|
314
|
+
value: void 0
|
|
315
|
+
});
|
|
316
|
+
Object.defineProperty(this, "hostInformation", {
|
|
317
|
+
enumerable: true,
|
|
318
|
+
configurable: true,
|
|
319
|
+
writable: true,
|
|
320
|
+
value: void 0
|
|
321
|
+
});
|
|
322
|
+
/**
|
|
323
|
+
* The companion's own identity/runtime context, present only when this
|
|
324
|
+
* frame is loaded by a la Vitre **companion** (`hostInformation.isCompanion`
|
|
325
|
+
* is then true). Undefined on Vitre-side frames. Mirrors
|
|
326
|
+
* `CompanionConnector.companionInformation`. Added 1.19.
|
|
327
|
+
*/
|
|
328
|
+
Object.defineProperty(this, "companionInformation", {
|
|
329
|
+
enumerable: true,
|
|
330
|
+
configurable: true,
|
|
331
|
+
writable: true,
|
|
332
|
+
value: void 0
|
|
333
|
+
});
|
|
334
|
+
Object.defineProperty(this, "initiator", {
|
|
335
|
+
enumerable: true,
|
|
336
|
+
configurable: true,
|
|
337
|
+
writable: true,
|
|
338
|
+
value: void 0
|
|
339
|
+
});
|
|
340
|
+
Object.defineProperty(this, "id", {
|
|
341
|
+
enumerable: true,
|
|
342
|
+
configurable: true,
|
|
343
|
+
writable: true,
|
|
344
|
+
value: void 0
|
|
345
|
+
});
|
|
346
|
+
Object.defineProperty(this, "appId", {
|
|
347
|
+
enumerable: true,
|
|
348
|
+
configurable: true,
|
|
349
|
+
writable: true,
|
|
350
|
+
value: void 0
|
|
351
|
+
});
|
|
352
|
+
Object.defineProperty(this, "initOptions", {
|
|
353
|
+
enumerable: true,
|
|
354
|
+
configurable: true,
|
|
355
|
+
writable: true,
|
|
356
|
+
value: void 0
|
|
357
|
+
});
|
|
358
|
+
/**
|
|
359
|
+
* @deprecated Use initOptions.border.modeinitOptions
|
|
360
|
+
*/
|
|
361
|
+
Object.defineProperty(this, "isBorderless", {
|
|
362
|
+
enumerable: true,
|
|
363
|
+
configurable: true,
|
|
364
|
+
writable: true,
|
|
365
|
+
value: void 0
|
|
366
|
+
});
|
|
367
|
+
Object.defineProperty(this, "isFullscreen", {
|
|
368
|
+
enumerable: true,
|
|
369
|
+
configurable: true,
|
|
370
|
+
writable: true,
|
|
371
|
+
value: void 0
|
|
372
|
+
});
|
|
373
|
+
Object.defineProperty(this, "state", {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
configurable: true,
|
|
376
|
+
writable: true,
|
|
377
|
+
value: {}
|
|
378
|
+
});
|
|
379
|
+
/**
|
|
380
|
+
* CRDT channel — Yjs doc + Awareness piped over the la Vitre transport.
|
|
381
|
+
* Libraries (Carbone, …) can call `crdt.attach(doc, awareness)` to bring
|
|
382
|
+
* their own; simple apps use `crdt.doc` / `crdt.awareness` directly.
|
|
383
|
+
*/
|
|
384
|
+
Object.defineProperty(this, "crdt", {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
configurable: true,
|
|
387
|
+
writable: true,
|
|
388
|
+
value: void 0
|
|
389
|
+
});
|
|
390
|
+
/**
|
|
391
|
+
* CRDT-backed blob store built on `crdt.attachSubdoc` — see Connector.blobs.
|
|
392
|
+
*/
|
|
393
|
+
Object.defineProperty(this, "blobs", {
|
|
394
|
+
enumerable: true,
|
|
395
|
+
configurable: true,
|
|
396
|
+
writable: true,
|
|
397
|
+
value: void 0
|
|
398
|
+
});
|
|
399
|
+
/**
|
|
400
|
+
* AI tool channel — publish a catalog of tools the on-prem agent's LLM can call
|
|
401
|
+
* on this frame: `ai.registerTools([{ name, description, parameters, sensitive }],
|
|
402
|
+
* (name, args) => …)`. Register SIMPLE local names; the host namespaces them as
|
|
403
|
+
* `<appId>__<name>`. Invocations run against the handler and reply automatically.
|
|
404
|
+
*/
|
|
405
|
+
Object.defineProperty(this, "ai", {
|
|
406
|
+
enumerable: true,
|
|
407
|
+
configurable: true,
|
|
408
|
+
writable: true,
|
|
409
|
+
value: void 0
|
|
410
|
+
});
|
|
411
|
+
Object.defineProperty(this, "position", {
|
|
412
|
+
enumerable: true,
|
|
413
|
+
configurable: true,
|
|
414
|
+
writable: true,
|
|
415
|
+
value: void 0
|
|
416
|
+
});
|
|
417
|
+
Object.defineProperty(this, "zIndex", {
|
|
418
|
+
enumerable: true,
|
|
419
|
+
configurable: true,
|
|
420
|
+
writable: true,
|
|
421
|
+
value: void 0
|
|
422
|
+
});
|
|
423
|
+
Object.defineProperty(this, "requestResolvers", {
|
|
424
|
+
enumerable: true,
|
|
425
|
+
configurable: true,
|
|
426
|
+
writable: true,
|
|
427
|
+
value: []
|
|
428
|
+
});
|
|
429
|
+
Object.defineProperty(this, "sharedStream", {
|
|
430
|
+
enumerable: true,
|
|
431
|
+
configurable: true,
|
|
432
|
+
writable: true,
|
|
433
|
+
value: {
|
|
434
|
+
lastState: {
|
|
435
|
+
position: 0,
|
|
436
|
+
duration: 0,
|
|
437
|
+
volume: 1,
|
|
438
|
+
state: 'paused',
|
|
439
|
+
},
|
|
440
|
+
play: () => {
|
|
441
|
+
this.postMessage({
|
|
442
|
+
type: 'sharedStreamAction',
|
|
443
|
+
action: 'play',
|
|
444
|
+
});
|
|
445
|
+
},
|
|
446
|
+
pause: () => {
|
|
447
|
+
this.postMessage({
|
|
448
|
+
type: 'sharedStreamAction',
|
|
449
|
+
action: 'pause',
|
|
450
|
+
});
|
|
451
|
+
},
|
|
452
|
+
seek: (position, isRelative = false) => {
|
|
453
|
+
this.postMessage({
|
|
454
|
+
type: 'sharedStreamAction',
|
|
455
|
+
action: 'seek',
|
|
456
|
+
position,
|
|
457
|
+
isRelative,
|
|
458
|
+
});
|
|
459
|
+
},
|
|
460
|
+
setVolume: (volume, muted = false) => {
|
|
461
|
+
this.postMessage({
|
|
462
|
+
type: 'sharedStreamAction',
|
|
463
|
+
action: 'volume',
|
|
464
|
+
volume,
|
|
465
|
+
muted,
|
|
466
|
+
});
|
|
467
|
+
},
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
this.hostInformation = initMessage.hostInfo;
|
|
471
|
+
this.companionInformation = initMessage.companionInfo;
|
|
472
|
+
this.initiator = initMessage.initiator;
|
|
473
|
+
this.id = initMessage.id;
|
|
474
|
+
this.appId = initMessage.appId ?? '';
|
|
475
|
+
this.initOptions = initMessage.options;
|
|
476
|
+
this.isBorderless = initMessage.isBorderless;
|
|
477
|
+
this.isFullscreen = initMessage.isFullscreen;
|
|
478
|
+
this.position = initMessage.position;
|
|
479
|
+
this.zIndex = 0;
|
|
480
|
+
this.isFullscreen = initMessage.isFullscreen;
|
|
481
|
+
this.postMessage({
|
|
482
|
+
type: 'frameInitialized',
|
|
483
|
+
options,
|
|
484
|
+
});
|
|
485
|
+
const w = window;
|
|
486
|
+
w.frameConnector = this;
|
|
487
|
+
w.connector = this;
|
|
488
|
+
this.state = initState ?? {};
|
|
489
|
+
// Mirror of the Connector guard — both connectors must behave
|
|
490
|
+
// identically. See MIN_CRDT_HOST_VERSION for the rationale.
|
|
491
|
+
//
|
|
492
|
+
// Exception: a companion frame (`hostInformation.isCompanion`) is never
|
|
493
|
+
// gated. Its host is the la-Vitre companion, which is deployed centrally
|
|
494
|
+
// and always runs HEAD, so it always carries the CRDT relay. Gating it is
|
|
495
|
+
// also actively harmful: the version it advertises is the companion's OWN
|
|
496
|
+
// build version, and a misconfigured deploy can ship a stale placeholder
|
|
497
|
+
// (a preview build shipped `1.2.0.0`), which silently disables Yjs sync
|
|
498
|
+
// for every companion frame. The real sync peer is the Vitre, whose own
|
|
499
|
+
// gate still applies on its side.
|
|
500
|
+
const crdtSupported = this.hostInformation.isCompanion === true ||
|
|
501
|
+
isMinVersion(this.hostInformation.version, MIN_CRDT_HOST_VERSION);
|
|
502
|
+
this.crdt = new CrdtChannel((message, transfer) => {
|
|
503
|
+
// Same as Connector: `FrameApiMessagesOut` already includes the four
|
|
504
|
+
// `crdt*` arms (Frame.Model.ts), so no cast is needed.
|
|
505
|
+
if (!crdtSupported)
|
|
506
|
+
return;
|
|
507
|
+
this.postMessage(message, transfer);
|
|
508
|
+
});
|
|
509
|
+
this.crdt.onSynced(() => this.onYjsSynced?.());
|
|
510
|
+
this.crdt.onUpdate((update) => this.onYjsUpdate?.(update));
|
|
511
|
+
this.blobs = new BlobStore(this.crdt);
|
|
512
|
+
// AI tool channel — same companion-exception + version gate as CRDT (a host
|
|
513
|
+
// that predates the ai bridge ignores the unknown arms and never invokes).
|
|
514
|
+
const aiSupported = this.hostInformation.isCompanion === true ||
|
|
515
|
+
isMinVersion(this.hostInformation.version, MIN_AI_HOST_VERSION);
|
|
516
|
+
this.ai = new AiChannel((message) => {
|
|
517
|
+
if (!aiSupported)
|
|
518
|
+
return;
|
|
519
|
+
this.postMessage(message);
|
|
520
|
+
});
|
|
521
|
+
if (this.state['@sharedStreamState.state']) {
|
|
522
|
+
this.sharedStream.lastState = {
|
|
523
|
+
...this.sharedStream.lastState,
|
|
524
|
+
state: this.state['@sharedStreamState.state'],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
if (typeof this.state['@sharedStreamState.duration'] === 'number') {
|
|
528
|
+
this.sharedStream.lastState = {
|
|
529
|
+
...this.sharedStream.lastState,
|
|
530
|
+
duration: this.state['@sharedStreamState.duration'],
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
if (typeof this.state['@sharedStreamState.position'] === 'number') {
|
|
534
|
+
this.sharedStream.lastState = {
|
|
535
|
+
...this.sharedStream.lastState,
|
|
536
|
+
position: this.state['@sharedStreamState.position'],
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
resolveRequest(msg) {
|
|
541
|
+
this.requestResolvers = this.requestResolvers.filter((rr) => !rr.isHandled(msg));
|
|
542
|
+
}
|
|
543
|
+
raiseMessage(msg) {
|
|
544
|
+
this.resolveRequest(msg);
|
|
545
|
+
switch (msg.type) {
|
|
546
|
+
case 'privacyChanged':
|
|
547
|
+
this.hostInformation = {
|
|
548
|
+
...this.hostInformation,
|
|
549
|
+
device: { ...this.hostInformation.device, privacy: msg.privacy },
|
|
550
|
+
};
|
|
551
|
+
this.onPrivacyChanged?.(msg.privacy);
|
|
552
|
+
break;
|
|
553
|
+
case 'deviceJoined':
|
|
554
|
+
this.hostInformation = {
|
|
555
|
+
...this.hostInformation,
|
|
556
|
+
devicesInSpace: [
|
|
557
|
+
...this.hostInformation.devicesInSpace.filter((d) => d.id !== msg.device.id),
|
|
558
|
+
msg.device,
|
|
559
|
+
],
|
|
560
|
+
};
|
|
561
|
+
this.onDeviceJoined?.(msg.device);
|
|
562
|
+
break;
|
|
563
|
+
case 'deviceLeft':
|
|
564
|
+
this.hostInformation = {
|
|
565
|
+
...this.hostInformation,
|
|
566
|
+
devicesInSpace: this.hostInformation.devicesInSpace.filter((d) => d.id !== msg.deviceId),
|
|
567
|
+
};
|
|
568
|
+
this.onDeviceLeft?.(msg.deviceId);
|
|
569
|
+
break;
|
|
570
|
+
case 'deviceMessageReceived':
|
|
571
|
+
this.onDeviceMessageReceived?.(msg);
|
|
572
|
+
break;
|
|
573
|
+
case 'localConnectorMessageReceived':
|
|
574
|
+
this.onLocalConnectorMessageReceived?.(msg.data, msg.from, msg.fileData);
|
|
575
|
+
break;
|
|
576
|
+
case 'menuClicked':
|
|
577
|
+
this.onMenuClicked?.(msg.menuId, msg.tag, msg.isChecked);
|
|
578
|
+
break;
|
|
579
|
+
case 'fieldUpdated':
|
|
580
|
+
this.onFieldUpdated?.(msg.field);
|
|
581
|
+
break;
|
|
582
|
+
case 'isInteractingChanged':
|
|
583
|
+
this.onInteractingChanged?.(msg.isInteracting);
|
|
584
|
+
break;
|
|
585
|
+
case 'borderlessUpdated':
|
|
586
|
+
this.isBorderless = msg.isBorderless;
|
|
587
|
+
this.onBorderlessChanged?.(msg.isBorderless);
|
|
588
|
+
break;
|
|
589
|
+
case 'fullscreenUpdated':
|
|
590
|
+
this.isFullscreen = msg.isFullscreen;
|
|
591
|
+
this.onFullscreenChanged?.(msg.isFullscreen);
|
|
592
|
+
break;
|
|
593
|
+
case 'fileLoaded':
|
|
594
|
+
this.onFileLoaded?.(msg.file);
|
|
595
|
+
break;
|
|
596
|
+
case 'fileProgress':
|
|
597
|
+
this.onFileProgress?.(msg.bytes, msg.totalBytes);
|
|
598
|
+
break;
|
|
599
|
+
case 'exportRequest':
|
|
600
|
+
{
|
|
601
|
+
const resolve = (data) => {
|
|
602
|
+
this.postMessage({
|
|
603
|
+
type: 'exportDone',
|
|
604
|
+
request: msg,
|
|
605
|
+
data,
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
const reject = (error) => {
|
|
609
|
+
this.postMessage({
|
|
610
|
+
type: 'exportDone',
|
|
611
|
+
request: msg,
|
|
612
|
+
error,
|
|
613
|
+
});
|
|
614
|
+
};
|
|
615
|
+
this.onExportRequest?.(msg, resolve, reject);
|
|
616
|
+
}
|
|
617
|
+
break;
|
|
618
|
+
case 'knockKnockReceived':
|
|
619
|
+
this.onKnockKnock?.(msg);
|
|
620
|
+
break;
|
|
621
|
+
case 'settingsUpdated':
|
|
622
|
+
this.hostInformation = {
|
|
623
|
+
...this.hostInformation,
|
|
624
|
+
settings: msg.settings,
|
|
625
|
+
};
|
|
626
|
+
this.onSettingsUpdated?.(msg.settings);
|
|
627
|
+
break;
|
|
628
|
+
case 'vitreSettingsUpdated':
|
|
629
|
+
this.hostInformation = {
|
|
630
|
+
...this.hostInformation,
|
|
631
|
+
space: msg.currentSpace,
|
|
632
|
+
vitreSettings: msg,
|
|
633
|
+
device: {
|
|
634
|
+
...this.hostInformation.device,
|
|
635
|
+
name: msg.name ?? this.hostInformation.device.name,
|
|
636
|
+
color: msg.color,
|
|
637
|
+
},
|
|
638
|
+
};
|
|
639
|
+
this.onVitreSettingsUpdated?.(msg);
|
|
640
|
+
break;
|
|
641
|
+
case 'connectionCodeUpdated':
|
|
642
|
+
this.hostInformation = {
|
|
643
|
+
...this.hostInformation,
|
|
644
|
+
companionCode: msg.companionCode,
|
|
645
|
+
};
|
|
646
|
+
this.onConnectionCodeUpdated?.(msg.companionCode);
|
|
647
|
+
break;
|
|
648
|
+
case 'notificationButtonClicked':
|
|
649
|
+
this.onNotificationButtonClicked?.(msg);
|
|
650
|
+
break;
|
|
651
|
+
case 'notificationDismissed':
|
|
652
|
+
this.onNotificationDismissed?.(msg.id);
|
|
653
|
+
break;
|
|
654
|
+
case 'devicePrivacyChanged':
|
|
655
|
+
this.hostInformation = {
|
|
656
|
+
...this.hostInformation,
|
|
657
|
+
devicesInSpace: [
|
|
658
|
+
...this.hostInformation.devicesInSpace.filter((d) => d.id !== msg.device.id),
|
|
659
|
+
msg.device,
|
|
660
|
+
],
|
|
661
|
+
};
|
|
662
|
+
this.onDevicePrivacyChanged?.(msg.device);
|
|
663
|
+
break;
|
|
664
|
+
case 'deviceFrameLoaded':
|
|
665
|
+
this.onDeviceFrameLoaded?.(msg);
|
|
666
|
+
break;
|
|
667
|
+
case 'deviceFrameUnloaded':
|
|
668
|
+
this.onDeviceFrameUnloaded?.(msg);
|
|
669
|
+
break;
|
|
670
|
+
case 'deviceFrameConnectorLoaded':
|
|
671
|
+
this.onDeviceFrameConnectorLoaded?.(msg);
|
|
672
|
+
break;
|
|
673
|
+
case 'pendingDevicesConnectionRequested':
|
|
674
|
+
this.onPendingDevicesConnectionRequested?.(msg.pendingDevices);
|
|
675
|
+
break;
|
|
676
|
+
case 'borderOptionsUpdated':
|
|
677
|
+
this.onBorderOptionsUpdated?.(msg);
|
|
678
|
+
break;
|
|
679
|
+
case 'voiceActionDetected':
|
|
680
|
+
this.onVoiceActionDetected?.(msg);
|
|
681
|
+
break;
|
|
682
|
+
case 'stateReplaced':
|
|
683
|
+
this._onStateReplaced(msg);
|
|
684
|
+
break;
|
|
685
|
+
case 'positionUpdated':
|
|
686
|
+
this.position = msg.position;
|
|
687
|
+
this.zIndex = msg.zIndex;
|
|
688
|
+
this.isFullscreen = msg.isFullscreen;
|
|
689
|
+
this.onPositionUpdated?.(msg);
|
|
690
|
+
break;
|
|
691
|
+
case 'deviceFullscreenUpdated':
|
|
692
|
+
this.hostInformation.devicesInSpace =
|
|
693
|
+
this.hostInformation.devicesInSpace.map((d) => d.id === msg.deviceId ? { ...d, fullscreen: msg.fullscreen } : d);
|
|
694
|
+
this.onDeviceFullscreenUpdated?.(msg);
|
|
695
|
+
break;
|
|
696
|
+
case 'visibilityChanged':
|
|
697
|
+
this.onVisibilityChanged?.(msg);
|
|
698
|
+
break;
|
|
699
|
+
case 'deviceScalingUpdated':
|
|
700
|
+
if (msg.deviceId === this.hostInformation.device.id) {
|
|
701
|
+
this.hostInformation.device.sendingScaling = msg.sendingScaling;
|
|
702
|
+
this.hostInformation.device.orientation = msg.orientation;
|
|
703
|
+
this.hostInformation.device.orientationBy = msg.orientationBy;
|
|
704
|
+
}
|
|
705
|
+
this.hostInformation.devicesInSpace =
|
|
706
|
+
this.hostInformation.devicesInSpace.map((d) => d.id === msg.deviceId
|
|
707
|
+
? {
|
|
708
|
+
...d,
|
|
709
|
+
sendingScaling: msg.sendingScaling,
|
|
710
|
+
orientation: msg.orientation,
|
|
711
|
+
orientationBy: msg.orientationBy,
|
|
712
|
+
}
|
|
713
|
+
: d);
|
|
714
|
+
this.onDeviceScalingUpdated?.(msg);
|
|
715
|
+
break;
|
|
716
|
+
case 'updateFrameName':
|
|
717
|
+
this.options.name = msg.name;
|
|
718
|
+
this.onUpdateFrameName?.(msg.name);
|
|
719
|
+
break;
|
|
720
|
+
case 'localSharedStreamUpdate':
|
|
721
|
+
this.sharedStream.lastState = {
|
|
722
|
+
...this.sharedStream.lastState,
|
|
723
|
+
volume: msg.volume,
|
|
724
|
+
};
|
|
725
|
+
this.onSharedStreamUpdate?.(this.sharedStream.lastState);
|
|
726
|
+
break;
|
|
727
|
+
case 'sharedStreamAvailable': {
|
|
728
|
+
// Reverse breakout box — rebuild a live MediaStream from the readables
|
|
729
|
+
// the host transferred into this frame (one MediaStreamTrackGenerator
|
|
730
|
+
// per track; pipe the readable into its writable). Mirrors the host's
|
|
731
|
+
// tracksFromReadables / SDK toShareTracks on the share side.
|
|
732
|
+
const tracks = msg.tracks.map((t) => {
|
|
733
|
+
const generator = new MediaStreamTrackGenerator({ kind: t.kind });
|
|
734
|
+
t.readable.pipeTo(generator.writable).catch(() => { });
|
|
735
|
+
return generator;
|
|
736
|
+
});
|
|
737
|
+
this.onSharedStream?.(msg.streamId, new MediaStream(tracks));
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
case 'sharedStreamRemoved':
|
|
741
|
+
this.onSharedStreamRemoved?.(msg.streamId);
|
|
742
|
+
break;
|
|
743
|
+
case 'mediaDevicesChanged':
|
|
744
|
+
this.hostInformation = {
|
|
745
|
+
...this.hostInformation,
|
|
746
|
+
vitreSettings: {
|
|
747
|
+
...this.hostInformation.vitreSettings,
|
|
748
|
+
availableMediaDevices: msg.devices,
|
|
749
|
+
},
|
|
750
|
+
};
|
|
751
|
+
this.onMediaDevicesChanged?.(msg.devices);
|
|
752
|
+
break;
|
|
753
|
+
case 'bluetooth':
|
|
754
|
+
this.onBluetoothMessage?.(msg);
|
|
755
|
+
break;
|
|
756
|
+
case 'crdtUpdate':
|
|
757
|
+
case 'crdtSyncComplete':
|
|
758
|
+
case 'crdtRequestSync':
|
|
759
|
+
case 'crdtAwarenessUpdate':
|
|
760
|
+
case 'crdtSubdocUpdate':
|
|
761
|
+
case 'crdtSubdocSyncComplete':
|
|
762
|
+
case 'crdtSubdocTransferProgress':
|
|
763
|
+
case 'crdtSubdocRequestSync':
|
|
764
|
+
this.crdt.handleMessage(msg);
|
|
765
|
+
break;
|
|
766
|
+
case 'aiInvoke':
|
|
767
|
+
void this.ai.handleInvoke(msg.id, msg.name, msg.args);
|
|
768
|
+
break;
|
|
769
|
+
case 'companionFramePeerJoined':
|
|
770
|
+
this.onCompanionFramePeerJoined?.(msg.peer);
|
|
771
|
+
break;
|
|
772
|
+
case 'companionFramePeerLeft':
|
|
773
|
+
this.onCompanionFramePeerLeft?.(msg.peerId);
|
|
774
|
+
break;
|
|
775
|
+
case 'companionFramePeersUpdated':
|
|
776
|
+
this.onCompanionFramePeersUpdated?.(msg.peers);
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
this.onMessageReceived?.(msg);
|
|
780
|
+
}
|
|
781
|
+
_onStateReplaced(msg) {
|
|
782
|
+
const oldState = this.state;
|
|
783
|
+
this.state = msg.state;
|
|
784
|
+
let hasSharedStreamUpdate = false;
|
|
785
|
+
msg.delta.forEach((update) => {
|
|
786
|
+
if (update.key === '@sharedStreamState.state' &&
|
|
787
|
+
update.action === 'add') {
|
|
788
|
+
this.sharedStream.lastState = {
|
|
789
|
+
...this.sharedStream.lastState,
|
|
790
|
+
state: update.value,
|
|
791
|
+
};
|
|
792
|
+
hasSharedStreamUpdate = true;
|
|
793
|
+
}
|
|
794
|
+
else if (update.key === '@sharedStreamState.duration' &&
|
|
795
|
+
update.action === 'add') {
|
|
796
|
+
this.sharedStream.lastState = {
|
|
797
|
+
...this.sharedStream.lastState,
|
|
798
|
+
duration: update.value,
|
|
799
|
+
};
|
|
800
|
+
hasSharedStreamUpdate = true;
|
|
801
|
+
}
|
|
802
|
+
else if (update.key === '@sharedStreamState.position' &&
|
|
803
|
+
update.action === 'add') {
|
|
804
|
+
this.sharedStream.lastState = {
|
|
805
|
+
...this.sharedStream.lastState,
|
|
806
|
+
position: update.value,
|
|
807
|
+
};
|
|
808
|
+
hasSharedStreamUpdate = true;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
if (hasSharedStreamUpdate) {
|
|
812
|
+
this.onSharedStreamUpdate?.(this.sharedStream.lastState);
|
|
813
|
+
}
|
|
814
|
+
this.onStateReplaced?.(this.state, oldState, msg.replacedBy, msg.delta);
|
|
815
|
+
}
|
|
816
|
+
sendMessageTo(message) {
|
|
817
|
+
this.postMessage({ type: 'sendMessageTo', ...message });
|
|
818
|
+
}
|
|
819
|
+
sendMessageToAll(message) {
|
|
820
|
+
this.postMessage({ type: 'sendMessageToAll', ...message });
|
|
821
|
+
}
|
|
822
|
+
sendKnockKnock(message) {
|
|
823
|
+
this.postMessage({ type: 'sendKnockKnock', ...message });
|
|
824
|
+
}
|
|
825
|
+
/** Release the resources owned by this frame. Tears the CRDT channel
|
|
826
|
+
* down (unbinds doc/awareness listeners, destroys the default Y.Doc +
|
|
827
|
+
* Awareness). Safe to call multiple times. */
|
|
828
|
+
destroy() {
|
|
829
|
+
this.crdt.destroy();
|
|
830
|
+
}
|
|
831
|
+
setFullscreen() {
|
|
832
|
+
this.postMessage({
|
|
833
|
+
type: 'setFullscreen',
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
setMenu(menu) {
|
|
837
|
+
this.postMessage({
|
|
838
|
+
type: 'setFrameMenu',
|
|
839
|
+
menu,
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* SDK 1.47 — replace the frame's export sources after initialization.
|
|
844
|
+
*
|
|
845
|
+
* The initial set comes from the `ViewOptions.exportSources` returned by
|
|
846
|
+
* `initializeFrame`; this is the only way to change it afterwards, e.g.
|
|
847
|
+
* when a document gains a format, or to flip `availableForCompanion` on a
|
|
848
|
+
* source once it becomes too large to hand to a phone.
|
|
849
|
+
*
|
|
850
|
+
* The call REPLACES the whole list — pass every source you still want,
|
|
851
|
+
* not just the new ones. The host rebuilds both its own export menu and
|
|
852
|
+
* the companions' from it.
|
|
853
|
+
*/
|
|
854
|
+
setExportSources(exportSources) {
|
|
855
|
+
this.postMessage({
|
|
856
|
+
type: 'setExportSources',
|
|
857
|
+
exportSources,
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
applyStreamAdvancedConstraints(constraints) {
|
|
861
|
+
this.postMessage({
|
|
862
|
+
...constraints,
|
|
863
|
+
type: 'applyStreamAdvancedConstraints',
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Replace the video track of this frame's shared stream with a fresh
|
|
868
|
+
* `getUserMedia` capture matching `constraints` (e.g. to switch camera),
|
|
869
|
+
* keeping the same share alive (`replaceTrack` on the host, no
|
|
870
|
+
* renegotiation). The host forces the requested `deviceId` as `{ exact }`.
|
|
871
|
+
* Resolves with the new track infos so the frame can rebuild its menu.
|
|
872
|
+
*/
|
|
873
|
+
async requestReplaceStream(constraints) {
|
|
874
|
+
const requestId = uuid();
|
|
875
|
+
return await this.postRequest({ type: 'replaceFrameStream', requestId, constraints }, (msg, resolve, reject) => {
|
|
876
|
+
if (msg.type === 'replaceFrameStreamCompleted' &&
|
|
877
|
+
msg.requestId === requestId) {
|
|
878
|
+
if (msg.error != null || msg.tracks == null) {
|
|
879
|
+
reject(msg.error ?? 'replaceFrameStream failed');
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
resolve(msg.tracks);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
setWindowed() {
|
|
888
|
+
this.postMessage({
|
|
889
|
+
type: 'setWindowed',
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
close() {
|
|
893
|
+
this.postMessage({
|
|
894
|
+
type: 'close',
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
sendToLocalFrame(frameConnectorId, data, fileData) {
|
|
898
|
+
this.postMessage({
|
|
899
|
+
type: 'sendToLocalFrame',
|
|
900
|
+
frameConnectorId,
|
|
901
|
+
data,
|
|
902
|
+
fileData,
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
sendToLocalMainConnector(data, fileData) {
|
|
906
|
+
this.postMessage({
|
|
907
|
+
type: 'sendToLocalFrame',
|
|
908
|
+
frameConnectorId: undefined,
|
|
909
|
+
data,
|
|
910
|
+
fileData,
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Convenience for companion frames: send a message to the paired Vitre
|
|
915
|
+
* frame (same `frameConnectorId`). Wraps `sendToLocalFrame` with the
|
|
916
|
+
* current frame's id so callers don't have to repeat it. The receiving
|
|
917
|
+
* Vitre frame surfaces it on `onLocalConnectorMessageReceived` (data,
|
|
918
|
+
* from, fileData). The same primitive works from a Vitre frame too,
|
|
919
|
+
* but on the Vitre most apps want `sendMessageTo` / `sendMessageToAll`
|
|
920
|
+
* to reach other devices instead — which the companion has no way to
|
|
921
|
+
* address. See `CompanionFrame` for the trimmed surface intended for
|
|
922
|
+
* apps running on a companion frame iframe.
|
|
923
|
+
*/
|
|
924
|
+
sendToVitreFrame(data, fileData) {
|
|
925
|
+
this.sendToLocalFrame(this.id, data, fileData);
|
|
926
|
+
}
|
|
927
|
+
// The companion-only send methods `sendMessageToVitreConnector` and
|
|
928
|
+
// `closeOnCompanion` deliberately do NOT live on the Vitre `Frame`. They post
|
|
929
|
+
// host messages (`sendToVitreConnector` / `closeOnCompanion`) that ONLY the
|
|
930
|
+
// companion host decodes — a Vitre host rejects them with "case type not
|
|
931
|
+
// found". They live on `CompanionFrame` (the subclass returned by
|
|
932
|
+
// `initializeCompanionFrame`, see CompanionFrame.ts). A Vitre frame that needs
|
|
933
|
+
// to reach its own connector uses `sendToLocalMainConnector` instead.
|
|
934
|
+
stopInteracting() {
|
|
935
|
+
this.postMessage({
|
|
936
|
+
type: 'stopInteracting',
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
setPosition(position) {
|
|
940
|
+
this.postMessage({
|
|
941
|
+
type: 'setPosition',
|
|
942
|
+
...position,
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
setVisibility(visibility) {
|
|
946
|
+
this.postMessage({
|
|
947
|
+
type: 'setVisibility',
|
|
948
|
+
visibility,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
setReducedAudioMode(enabled) {
|
|
952
|
+
this.postMessage({
|
|
953
|
+
type: 'setReducedAudioMode',
|
|
954
|
+
enabled,
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
startInteracting() {
|
|
958
|
+
this.postMessage({ type: 'startInteracting' });
|
|
959
|
+
}
|
|
960
|
+
sendToSerialPort(serialPort) {
|
|
961
|
+
this.postMessage({
|
|
962
|
+
type: 'sendToSerialPort',
|
|
963
|
+
...serialPort,
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/// Request access to a serial port (see `Connector.requestSerialPortAccess`).
|
|
967
|
+
/// Resolves with the granted port name (empty string if denied/cancelled).
|
|
968
|
+
/// With `{ port }` the host pre-grants it; with no argument the host shows
|
|
969
|
+
/// its port-picker and resolves with the chosen port.
|
|
970
|
+
async requestSerialPortAccess(request) {
|
|
971
|
+
const requestId = uuid();
|
|
972
|
+
return await this.postRequest({ type: 'requestSerialPortAccess', requestId, port: request?.port }, (msg, resolve, reject) => {
|
|
973
|
+
if (msg.type === 'serialPortAccessResult' &&
|
|
974
|
+
msg.requestId === requestId) {
|
|
975
|
+
if (msg.port) {
|
|
976
|
+
resolve(msg.port);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
reject(msg.reason ?? 'cancelled');
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
sendBluetoothMessage(msg) {
|
|
985
|
+
this.postMessage({ ...msg, type: 'bluetooth' });
|
|
986
|
+
}
|
|
987
|
+
disconnectGuests(deviceIds) {
|
|
988
|
+
this.postMessage({
|
|
989
|
+
type: 'disconnectGuests',
|
|
990
|
+
deviceIds,
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
requestStreamSizeUpdate(updates) {
|
|
994
|
+
this.postMessage({
|
|
995
|
+
type: 'requestStreamSizeUpdate',
|
|
996
|
+
...updates,
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
updateName(name) {
|
|
1000
|
+
this.postMessage({
|
|
1001
|
+
type: 'updateName',
|
|
1002
|
+
name,
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Whether {@link shareStream} is available in this runtime (Chromium
|
|
1007
|
+
* Insertable Streams + same-site hosting). Same gate as
|
|
1008
|
+
* `Connector.canShareStream`.
|
|
1009
|
+
*/
|
|
1010
|
+
canShareStream() {
|
|
1011
|
+
return typeof MediaStreamTrackProcessor !== 'undefined';
|
|
1012
|
+
}
|
|
1013
|
+
toShareTracks(stream) {
|
|
1014
|
+
const tracks = [];
|
|
1015
|
+
const transfer = [];
|
|
1016
|
+
for (const track of stream.getTracks()) {
|
|
1017
|
+
const { readable } = new MediaStreamTrackProcessor({ track });
|
|
1018
|
+
tracks.push({
|
|
1019
|
+
kind: track.kind,
|
|
1020
|
+
readable,
|
|
1021
|
+
settings: track.getSettings(),
|
|
1022
|
+
});
|
|
1023
|
+
transfer.push(readable);
|
|
1024
|
+
}
|
|
1025
|
+
return { tracks, transfer };
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Share a `MediaStream` the frame produced (e.g. a WebGL-transformed track,
|
|
1029
|
+
* or a camera the frame opened) TO the Vitre, which forwards it to the space
|
|
1030
|
+
* peers. Frame-context counterpart of `Connector.shareStream`: needed because
|
|
1031
|
+
* a transform frame builds its output track locally and must reshare it.
|
|
1032
|
+
* Handed over zero-copy via the breakout box. Returns a `sharedStreamId` for
|
|
1033
|
+
* {@link replaceShareStream} / {@link stopShareStream}.
|
|
1034
|
+
*/
|
|
1035
|
+
async shareStream(stream, options) {
|
|
1036
|
+
if (!this.canShareStream()) {
|
|
1037
|
+
throw new Error('shareStream is not supported in this runtime (requires Chromium MediaStreamTrackProcessor and same-site hosting)');
|
|
1038
|
+
}
|
|
1039
|
+
const sharedStreamId = uuid();
|
|
1040
|
+
const requestId = uuid();
|
|
1041
|
+
const { tracks, transfer } = this.toShareTracks(stream);
|
|
1042
|
+
await this.postRequest({ type: 'shareStream', requestId, sharedStreamId, options, tracks }, (msg, resolve, reject) => {
|
|
1043
|
+
if (msg.type === 'shareStreamCompleted' && msg.requestId === requestId) {
|
|
1044
|
+
if (msg.error != null)
|
|
1045
|
+
reject(msg.error);
|
|
1046
|
+
else
|
|
1047
|
+
resolve(undefined);
|
|
1048
|
+
}
|
|
1049
|
+
}, transfer);
|
|
1050
|
+
return sharedStreamId;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Swap the source of an open frame share WITHOUT closing it (no
|
|
1054
|
+
* renegotiation blip). `sharedStreamId` is the value returned by
|
|
1055
|
+
* {@link shareStream}. See `Connector.replaceShareStream`.
|
|
1056
|
+
*/
|
|
1057
|
+
async replaceShareStream(sharedStreamId, streamOrTrack) {
|
|
1058
|
+
if (!this.canShareStream()) {
|
|
1059
|
+
throw new Error('replaceShareStream is not supported in this runtime');
|
|
1060
|
+
}
|
|
1061
|
+
const stream = streamOrTrack instanceof MediaStream
|
|
1062
|
+
? streamOrTrack
|
|
1063
|
+
: new MediaStream([streamOrTrack]);
|
|
1064
|
+
const requestId = uuid();
|
|
1065
|
+
const { tracks, transfer } = this.toShareTracks(stream);
|
|
1066
|
+
await this.postRequest({ type: 'replaceShareStream', requestId, sharedStreamId, tracks }, (msg, resolve, reject) => {
|
|
1067
|
+
if (msg.type === 'shareStreamCompleted' && msg.requestId === requestId) {
|
|
1068
|
+
if (msg.error != null)
|
|
1069
|
+
reject(msg.error);
|
|
1070
|
+
else
|
|
1071
|
+
resolve(undefined);
|
|
1072
|
+
}
|
|
1073
|
+
}, transfer);
|
|
1074
|
+
}
|
|
1075
|
+
/** Stop a frame share. `sharedStreamId` is the value returned by {@link shareStream}. */
|
|
1076
|
+
stopShareStream(sharedStreamId) {
|
|
1077
|
+
this.postMessage({ type: 'stopShareStream', sharedStreamId });
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Attach a `MediaStream` produced by this frame to a target frame's standard
|
|
1081
|
+
* sharing slot, WITHOUT opening a new `SharedContent` or establishing a new
|
|
1082
|
+
* `RTCPeerConnection`. The stream is forwarded zero-copy (breakout box) from
|
|
1083
|
+
* this frame's vitre to the already-open instances of `targetFrameConnectorId`
|
|
1084
|
+
* on other vitres; those instances receive it via {@link onSharedStream} (the
|
|
1085
|
+
* existing `sharedStreamAvailable` delivery arm — no new protocol arm).
|
|
1086
|
+
*
|
|
1087
|
+
* - Requires Chromium Insertable Streams (same guard as {@link shareStream}).
|
|
1088
|
+
* - Default target: this frame's own `frameConnectorId`, i.e. the same app
|
|
1089
|
+
* type running on peer vitres. Pass `opts.targetFrameConnectorId` to route
|
|
1090
|
+
* to a different frame type.
|
|
1091
|
+
* - Resolves when the host confirms delivery (or rejects with the host error).
|
|
1092
|
+
*
|
|
1093
|
+
* **Delivery semantics:**
|
|
1094
|
+
* - When `targetFrameConnectorId` is absent (default, target == this frame
|
|
1095
|
+
* type), the stream is delivered to peer vitres' instances of this frame via
|
|
1096
|
+
* {@link onSharedStream}. The calling frame already holds `stream` and does
|
|
1097
|
+
* NOT receive it back via `onSharedStream` (no loopback — intentional).
|
|
1098
|
+
* - When `targetFrameConnectorId` designates a DIFFERENT frame type, that
|
|
1099
|
+
* frame — including its instance on the emitting vitre — receives the stream
|
|
1100
|
+
* via {@link onSharedStream}.
|
|
1101
|
+
*/
|
|
1102
|
+
async attachStream(stream, opts) {
|
|
1103
|
+
if (!this.canShareStream()) {
|
|
1104
|
+
throw new Error('attachStream is not supported in this runtime (requires Chromium MediaStreamTrackProcessor and same-site hosting)');
|
|
1105
|
+
}
|
|
1106
|
+
const requestId = uuid();
|
|
1107
|
+
const { tracks, transfer } = this.toShareTracks(stream);
|
|
1108
|
+
await this.postRequest({
|
|
1109
|
+
type: 'attachStream',
|
|
1110
|
+
requestId,
|
|
1111
|
+
targetFrameConnectorId: opts?.targetFrameConnectorId,
|
|
1112
|
+
tracks,
|
|
1113
|
+
}, (msg, resolve, reject) => {
|
|
1114
|
+
if (msg.type === 'attachStreamCompleted' &&
|
|
1115
|
+
msg.requestId === requestId) {
|
|
1116
|
+
if (msg.error != null)
|
|
1117
|
+
reject(msg.error);
|
|
1118
|
+
else
|
|
1119
|
+
resolve(undefined);
|
|
1120
|
+
}
|
|
1121
|
+
}, transfer);
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Stop a stream previously attached with {@link attachStream} on the target
|
|
1125
|
+
* frame. Receivers see {@link onSharedStreamRemoved}. Default target: this
|
|
1126
|
+
* frame's own `frameConnectorId`.
|
|
1127
|
+
*/
|
|
1128
|
+
detachStream(opts) {
|
|
1129
|
+
this.postMessage({
|
|
1130
|
+
type: 'detachStream',
|
|
1131
|
+
targetFrameConnectorId: opts?.targetFrameConnectorId,
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Fetch the ICE/TURN servers the HOST already uses for its own WebRTC P2P
|
|
1136
|
+
* (the Vitre's `StartWebRTCOffer` config, or the companion's `WebRTCOffer`
|
|
1137
|
+
* config — same relays, same credentials). The result feeds straight into
|
|
1138
|
+
* `new RTCPeerConnection({ iceServers })`, letting an app stand up its OWN
|
|
1139
|
+
* peer connection — e.g. a companion-camera frame connecting directly to its
|
|
1140
|
+
* paired Vitre transform frame — that traverses NAT through the platform's
|
|
1141
|
+
* TURN infrastructure without shipping its own credentials.
|
|
1142
|
+
*
|
|
1143
|
+
* Resolves to `[]` on hosts that predate this request (the caller should
|
|
1144
|
+
* race a timeout and fall back to a public STUN-only config). See
|
|
1145
|
+
* {@link IceServerConfig}.
|
|
1146
|
+
*/
|
|
1147
|
+
async getIceServers() {
|
|
1148
|
+
const requestId = uuid();
|
|
1149
|
+
return await this.postRequest({ type: 'getIceServers', requestId }, (msg, resolve, _reject) => {
|
|
1150
|
+
if (msg.type === 'iceServersResponse' && msg.requestId === requestId) {
|
|
1151
|
+
resolve(msg.iceServers ?? []);
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
async postRequest(data, handler, transfer) {
|
|
1156
|
+
return await new Promise((resolve, reject) => {
|
|
1157
|
+
let isHandled = false;
|
|
1158
|
+
const handleAndResolve = (data) => {
|
|
1159
|
+
isHandled = true;
|
|
1160
|
+
resolve(data);
|
|
1161
|
+
};
|
|
1162
|
+
const handleAndReject = (error) => {
|
|
1163
|
+
isHandled = true;
|
|
1164
|
+
reject(error);
|
|
1165
|
+
};
|
|
1166
|
+
const resolver = {
|
|
1167
|
+
isHandled: (msg) => {
|
|
1168
|
+
try {
|
|
1169
|
+
handler(msg, handleAndResolve, handleAndReject);
|
|
1170
|
+
}
|
|
1171
|
+
catch (error) {
|
|
1172
|
+
handleAndReject(error);
|
|
1173
|
+
}
|
|
1174
|
+
return isHandled;
|
|
1175
|
+
},
|
|
1176
|
+
};
|
|
1177
|
+
this.requestResolvers.push(resolver);
|
|
1178
|
+
this.postMessage(data, transfer);
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
async requestEnumerateLocalFrames() {
|
|
1182
|
+
const requestId = uuid();
|
|
1183
|
+
return await this.postRequest({ type: 'enumerateLoadedFrames', requestId }, (msg, resolve, _reject) => {
|
|
1184
|
+
if (msg.type === 'enumerateLoadedFramesCompleted' &&
|
|
1185
|
+
msg.requestId === requestId) {
|
|
1186
|
+
resolve(msg.frames);
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
/** @deprecated Use sendMessageToEmbed */
|
|
1191
|
+
sendExtensionMessage(data, target, fileData) {
|
|
1192
|
+
this.postMessage({
|
|
1193
|
+
type: 'extensionMessage',
|
|
1194
|
+
data,
|
|
1195
|
+
target,
|
|
1196
|
+
fileData,
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
/** @deprecated Use sendMessageToEmbed */
|
|
1200
|
+
sendAppMessage(data, target, fileData) {
|
|
1201
|
+
this.postMessage({
|
|
1202
|
+
type: 'appMessage',
|
|
1203
|
+
data,
|
|
1204
|
+
target,
|
|
1205
|
+
fileData,
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
sendMessageToEmbed(data, target, fileData) {
|
|
1209
|
+
this.postMessage({
|
|
1210
|
+
type: 'appMessage',
|
|
1211
|
+
data,
|
|
1212
|
+
target,
|
|
1213
|
+
fileData,
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
async requestVitreSettings() {
|
|
1217
|
+
return await this.postRequest({ type: 'getVitreSettings' }, (msg, resolve, _reject) => {
|
|
1218
|
+
if (msg.type === 'vitreSettingsResponse') {
|
|
1219
|
+
resolve(msg);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
setVitreSettings(setters) {
|
|
1224
|
+
this.postMessage({ type: 'setVitreSettings', ...setters });
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Share a URL/data with the host, which routes it to a matching app.
|
|
1228
|
+
* @param owner Optional device id (`HostInformation.devicesInSpace[].id`) to
|
|
1229
|
+
* attribute the resulting shared content to. Drives the languette colour/info
|
|
1230
|
+
* and the content appears already-owned on every vitre. Default: opener.
|
|
1231
|
+
*/
|
|
1232
|
+
shareData(url, targetAppId, owner) {
|
|
1233
|
+
this.postMessage({
|
|
1234
|
+
type: 'shareData',
|
|
1235
|
+
url,
|
|
1236
|
+
targetAppId,
|
|
1237
|
+
owner,
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Share a file with the host, which routes it to a matching app.
|
|
1242
|
+
* @param owner Optional device id to attribute the share to. See {@link shareData}.
|
|
1243
|
+
*/
|
|
1244
|
+
shareFile(fileData, targetAppId, owner) {
|
|
1245
|
+
this.postMessage({
|
|
1246
|
+
type: 'shareFile',
|
|
1247
|
+
fileData,
|
|
1248
|
+
targetAppId,
|
|
1249
|
+
owner,
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
saveSettings(settings) {
|
|
1253
|
+
this.postMessage({
|
|
1254
|
+
type: 'saveSettings',
|
|
1255
|
+
settings,
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
changeTeamSpace(space) {
|
|
1259
|
+
this.postMessage({
|
|
1260
|
+
type: 'changeTeamSpace',
|
|
1261
|
+
space,
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
changeTeamSpaceGuest(space, teamDomain) {
|
|
1265
|
+
this.postMessage({
|
|
1266
|
+
type: 'changeTeamSpaceGuest',
|
|
1267
|
+
space,
|
|
1268
|
+
teamDomain,
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
showNotification(notification) {
|
|
1272
|
+
this.postMessage({
|
|
1273
|
+
...notification,
|
|
1274
|
+
type: 'showNotification',
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
hideNotification(notificationId) {
|
|
1278
|
+
this.postMessage({
|
|
1279
|
+
id: notificationId,
|
|
1280
|
+
type: 'hideNotification',
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
changePrivacy(privacy) {
|
|
1284
|
+
this.postMessage({
|
|
1285
|
+
type: 'changePrivacy',
|
|
1286
|
+
privacy,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
trackEvent(name, properties) {
|
|
1290
|
+
this.postMessage({
|
|
1291
|
+
type: 'trackEvent',
|
|
1292
|
+
name,
|
|
1293
|
+
properties,
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
startTrackEvent(name) {
|
|
1297
|
+
this.postMessage({
|
|
1298
|
+
type: 'startTrackEvent',
|
|
1299
|
+
name,
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
stopTrackEvent(name, properties) {
|
|
1303
|
+
this.postMessage({
|
|
1304
|
+
type: 'stopTrackEvent',
|
|
1305
|
+
name,
|
|
1306
|
+
properties,
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
getMainConnectorFrame() {
|
|
1310
|
+
try {
|
|
1311
|
+
const mainFrameId = `${this.appId}|${this.appId}`;
|
|
1312
|
+
return window.parent.frames[mainFrameId];
|
|
1313
|
+
}
|
|
1314
|
+
catch (_error) {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
getMainConnector() {
|
|
1319
|
+
const mainFrame = this.getMainConnectorFrame();
|
|
1320
|
+
return mainFrame?.mainConnector;
|
|
1321
|
+
}
|
|
1322
|
+
setBorderOptions(borderOptions) {
|
|
1323
|
+
this.postMessage({ type: 'setBorderOptions', ...borderOptions });
|
|
1324
|
+
}
|
|
1325
|
+
setVoiceActions(actions) {
|
|
1326
|
+
this.postMessage({
|
|
1327
|
+
type: 'setVoiceActions',
|
|
1328
|
+
actions,
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
async requestStreamCapture() {
|
|
1332
|
+
const requestId = uuid();
|
|
1333
|
+
return await this.postRequest({ type: 'streamFrameCaptureRequest', requestId }, (msg, resolve, reject) => {
|
|
1334
|
+
if (msg.type === 'streamFrameCapturedResponse' &&
|
|
1335
|
+
msg.requestId === requestId) {
|
|
1336
|
+
if (msg.response == null) {
|
|
1337
|
+
reject(msg.error ?? 'failed to get streamFrameCapturedResponse');
|
|
1338
|
+
}
|
|
1339
|
+
else {
|
|
1340
|
+
resolve(msg.response);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
async requestStats() {
|
|
1346
|
+
const requestId = uuid();
|
|
1347
|
+
return await this.postRequest({ type: 'getStats', requestId }, (msg, resolve, _reject) => {
|
|
1348
|
+
if (msg.type === 'statsResponse' && msg.requestId === requestId) {
|
|
1349
|
+
resolve(msg);
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
updateState(updates, forceApplyLocally = true) {
|
|
1354
|
+
updates.forEach((update) => {
|
|
1355
|
+
//Compat fix, add value for remove action
|
|
1356
|
+
if (update.action === 'remove') {
|
|
1357
|
+
;
|
|
1358
|
+
update.value = null;
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
this.postMessage({
|
|
1362
|
+
type: 'updateState',
|
|
1363
|
+
updates,
|
|
1364
|
+
});
|
|
1365
|
+
if (forceApplyLocally) {
|
|
1366
|
+
updates.forEach((update) => {
|
|
1367
|
+
if (update.action === 'add') {
|
|
1368
|
+
this.state[update.key] = update.value;
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
delete this.state[update.key];
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
export async function initializeFrame(init, createFrame) {
|
|
1378
|
+
return await new Promise((resolve) => {
|
|
1379
|
+
const channel = new MessageChannel();
|
|
1380
|
+
let frame = null;
|
|
1381
|
+
const messageHandler = (createPostMessage) => (e) => {
|
|
1382
|
+
switch (e.data.type) {
|
|
1383
|
+
case 'initialize':
|
|
1384
|
+
if (frame === null) {
|
|
1385
|
+
const initializeMsg = e.data;
|
|
1386
|
+
const options = init(initializeMsg.hostInfo, initializeMsg.initiator, initializeMsg.options, initializeMsg.state);
|
|
1387
|
+
frame = new (createFrame ?? Frame)(createPostMessage(initializeMsg.hostInfo.origin), initializeMsg, options, initializeMsg.state);
|
|
1388
|
+
resolve(frame);
|
|
1389
|
+
}
|
|
1390
|
+
break;
|
|
1391
|
+
default:
|
|
1392
|
+
frame?.raiseMessage(e.data);
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
channel.port1.onmessage = messageHandler((_origin) => (message, transfer) => {
|
|
1397
|
+
channel.port1.postMessage(message, transfer ?? []);
|
|
1398
|
+
});
|
|
1399
|
+
window.parent.postMessage({
|
|
1400
|
+
type: 'connectorInitializationRequest',
|
|
1401
|
+
version: apiVersion,
|
|
1402
|
+
}, '*', [channel.port2]);
|
|
1403
|
+
window.addEventListener('message', messageHandler((origin) => (message, transfer) => {
|
|
1404
|
+
window.parent.postMessage(message, origin, transfer);
|
|
1405
|
+
}), false);
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
//# sourceMappingURL=Frame.js.map
|