@lavitre/apps 1.52.0 → 1.55.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/README.md +123 -0
- package/dist/Common/AppSettings.d.ts +34 -0
- package/dist/Common/AppSettings.js +35 -0
- package/dist/Common/AppSettings.js.map +1 -0
- package/dist/Common/Common.Model.d.ts +146 -0
- package/dist/Common/Common.Model.js.map +1 -1
- package/dist/Common/PublicStorage.d.ts +140 -0
- package/dist/Common/PublicStorage.js +88 -0
- package/dist/Common/PublicStorage.js.map +1 -0
- package/dist/Common/index.d.ts +2 -0
- package/dist/Common/index.js +2 -0
- package/dist/Common/index.js.map +1 -1
- package/dist/Connector/Connector.Model.d.ts +17 -1
- package/dist/Connector/Connector.Model.js.map +1 -1
- package/dist/Connector/Connector.d.ts +48 -1
- package/dist/Connector/Connector.js +174 -1
- package/dist/Connector/Connector.js.map +1 -1
- package/dist/Frame/Frame.Model.d.ts +24 -2
- package/dist/Frame/Frame.Model.js.map +1 -1
- package/dist/Frame/Frame.d.ts +55 -3
- package/dist/Frame/Frame.js +219 -3
- package/dist/Frame/Frame.js.map +1 -1
- package/dist/Frame/SharedStreamPeer.d.ts +16 -0
- package/dist/Frame/SharedStreamPeer.js +74 -0
- package/dist/Frame/SharedStreamPeer.js.map +1 -0
- package/dist/Native/index.d.ts +17 -1
- package/dist/Native/index.js +7 -2
- package/dist/Native/index.js.map +1 -1
- package/dist/Version.d.ts +1 -1
- package/dist/Version.js +1 -1
- package/dist/Version.js.map +1 -1
- package/package.json +1 -1
package/dist/Frame/Frame.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type * as Y from 'yjs';
|
|
|
2
2
|
import { CrdtChannel } from '../Common/CrdtChannel.js';
|
|
3
3
|
import { BlobStore } from '../Common/BlobStore.js';
|
|
4
4
|
import { AiChannel } from '../Common/AiChannel.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { PublicStorageApi } from '../Common/PublicStorage.js';
|
|
6
|
+
import type { AppId, AppSettingsLevel, AppSettingsValue, BluetoothFromApp, BluetoothToApp, BorderOptions, CompanionInformation, ConnectedMediaDevice, Device, DeviceFrameReference, DeviceFullscreenUpdated, DeviceMessageReceived, DeviceScalingUpdated, Field, FileData, FramePeer, HostInformation, KnockKnock, LayoutPosition, LoadedFrame, MessageTarget, NotificationButtonClicked, NotificationInfo, PositionUpdated, SafeAreaInsets, SafeAreaInsetsUpdated, Privacy, Rect, ReplacedBy, RequestSerialPortAccess, RequestStreamSizeUpdate, SendKnockKnock, SendMessageTo, SendMessageToAll, SendToSerialPort, StatsResponse, StreamCapture, UpdatedStateEntry, UpdateStateEntry, Visibility, VisibilityChanged, VitreSettings, VitreSettingsSetter, VoiceAction, VoiceActionDetection } from '../Common/index.js';
|
|
6
7
|
import type { Connector, ShareStreamOptions } from '../Connector/index.js';
|
|
7
8
|
import type { MediaTrackInfo } from '../Connector/Connector.Model.js';
|
|
8
9
|
import type { ApplyStreamAdvancedConstraints, AvailableExportSource, ExportData, ExportRequest, FrameApiMessagesIn, FrameApiMessagesOut, FrameMenuEntry, IceServerConfig, InitFrameOptions, InitializeFrame, SharedStreamPlayState, ViewOptions } from './Frame.Model.js';
|
|
@@ -35,6 +36,13 @@ export declare class Frame {
|
|
|
35
36
|
onExportRequest?: (request: ExportRequest, resolve: (data: ExportData) => void, reject: (error: string) => void) => void;
|
|
36
37
|
onKnockKnock?: (knockKnock: KnockKnock) => void;
|
|
37
38
|
onSettingsUpdated?: (settings: any) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Pushed whenever the AppSettings value at a given level changes — see
|
|
41
|
+
* {@link getSettings} / {@link setSettings}. Fires for changes made by
|
|
42
|
+
* this app itself as well as by another vitre/app instance sharing the
|
|
43
|
+
* same team/space. Added 1.52.
|
|
44
|
+
*/
|
|
45
|
+
onSettingsChanged?: (change: AppSettingsValue) => void;
|
|
38
46
|
onVitreSettingsUpdated?: (settings: VitreSettings) => void;
|
|
39
47
|
onConnectionCodeUpdated?: (companionCode?: string) => void;
|
|
40
48
|
onNotificationDismissed?: (notificationId: string) => void;
|
|
@@ -85,8 +93,11 @@ export declare class Frame {
|
|
|
85
93
|
* `MediaStream` it owns INTO this frame (e.g. a received shared camera, or a
|
|
86
94
|
* companion stream routed to this frame for transformation). The stream is
|
|
87
95
|
* rebuilt locally via `MediaStreamTrackGenerator` from transferred readables
|
|
88
|
-
* — zero re-encode, same-site + Chromium only.
|
|
89
|
-
*
|
|
96
|
+
* — zero re-encode, same-site + Chromium only. Elsewhere (a web guest whose
|
|
97
|
+
* page is on another site than the app, Safari, Firefox) the host sends it
|
|
98
|
+
* over a local RTCPeerConnection instead; the callback is the same.
|
|
99
|
+
* `streamId` matches a later `onSharedStreamRemoved`. Inverse of
|
|
100
|
+
* {@link shareStream}.
|
|
90
101
|
*/
|
|
91
102
|
onSharedStream?: (streamId: string, stream: MediaStream) => void;
|
|
92
103
|
onSharedStreamRemoved?: (streamId: string) => void;
|
|
@@ -134,6 +145,14 @@ export declare class Frame {
|
|
|
134
145
|
* CRDT-backed blob store built on `crdt.attachSubdoc` — see Connector.blobs.
|
|
135
146
|
*/
|
|
136
147
|
readonly blobs: BlobStore;
|
|
148
|
+
/**
|
|
149
|
+
* Public, unauthenticated file storage scoped to the vitre's TEAM — see
|
|
150
|
+
* the README "Public storage" section for the full semantics (scopes,
|
|
151
|
+
* allowed file types, size cap, path rules). Files are readable by
|
|
152
|
+
* ANYONE at the returned URL — never put private data here. Only a
|
|
153
|
+
* Vitre-hosted frame has this — a companion frame cannot write.
|
|
154
|
+
*/
|
|
155
|
+
readonly publicStorage: PublicStorageApi;
|
|
137
156
|
/**
|
|
138
157
|
* AI tool channel — publish a catalog of tools the on-prem agent's LLM can call
|
|
139
158
|
* on this frame: `ai.registerTools([{ name, description, parameters, sensitive }],
|
|
@@ -148,6 +167,7 @@ export declare class Frame {
|
|
|
148
167
|
position: Rect;
|
|
149
168
|
zIndex: number;
|
|
150
169
|
private deviceStateListeners;
|
|
170
|
+
private sharedStreamPeers;
|
|
151
171
|
/**
|
|
152
172
|
* Called after any change of `hostInformation.device`,
|
|
153
173
|
* `hostInformation.devicesInSpace` or the available media devices (device
|
|
@@ -228,6 +248,11 @@ export declare class Frame {
|
|
|
228
248
|
* `Connector.canShareStream`.
|
|
229
249
|
*/
|
|
230
250
|
canShareStream(): boolean;
|
|
251
|
+
/** Normalize `publicStorage.put`'s payload to a plain `ArrayBuffer` —
|
|
252
|
+
* slicing out exactly a typed array's view (not its whole underlying
|
|
253
|
+
* buffer, in case it's a subarray) so the transferred bytes match the
|
|
254
|
+
* size the caller intended. */
|
|
255
|
+
private toPublicFileBuffer;
|
|
231
256
|
private toShareTracks;
|
|
232
257
|
/**
|
|
233
258
|
* Share a `MediaStream` the frame produced (e.g. a WebGL-transformed track,
|
|
@@ -317,6 +342,33 @@ export declare class Frame {
|
|
|
317
342
|
*/
|
|
318
343
|
shareFile(fileData: FileData, targetAppId: AppId, owner?: string): void;
|
|
319
344
|
saveSettings(settings: any): void;
|
|
345
|
+
/**
|
|
346
|
+
* Read the app's settings at one of the three levels — `vitre` (this
|
|
347
|
+
* vitre), `team` (the vitre's team), or `space` (the space the vitre is
|
|
348
|
+
* currently in). Every vitre/app instance of the team can read the same
|
|
349
|
+
* value; values are JSON objects capped at 64 KB — never store secrets.
|
|
350
|
+
*
|
|
351
|
+
* Distinct from the legacy `saveSettings`/`onSettingsUpdated` mechanism,
|
|
352
|
+
* which is a single vitre-scoped blob rendered by the host's settings
|
|
353
|
+
* form (see `Connector.setSettingsSchema`).
|
|
354
|
+
*
|
|
355
|
+
* Rejects with an {@link AppSettingsError} of code `'unsupported'` if the
|
|
356
|
+
* host doesn't answer within 10s — a vitre host older than this feature
|
|
357
|
+
* never responds to `getAppSettings`.
|
|
358
|
+
*/
|
|
359
|
+
getSettings(level: AppSettingsLevel): Promise<AppSettingsValue>;
|
|
360
|
+
/**
|
|
361
|
+
* Write the app's settings at `level`, with optimistic concurrency:
|
|
362
|
+
* `expectedVersion` must be the version last observed for that level (from
|
|
363
|
+
* {@link getSettings} or {@link onSettingsChanged}) — `0` if never
|
|
364
|
+
* written. A stale version rejects with an {@link AppSettingsError} of
|
|
365
|
+
* code `'conflict'`; re-read and retry. An oversized `value` (> 64 KB)
|
|
366
|
+
* rejects with `'tooLarge'`.
|
|
367
|
+
*
|
|
368
|
+
* Rejects with code `'unsupported'` if the host doesn't answer within
|
|
369
|
+
* 10s — see {@link getSettings}.
|
|
370
|
+
*/
|
|
371
|
+
setSettings(level: AppSettingsLevel, value: Record<string, unknown>, expectedVersion: number): Promise<AppSettingsValue>;
|
|
320
372
|
changeTeamSpace(space: string): void;
|
|
321
373
|
changeTeamSpaceGuest(space: string, teamDomain: string): void;
|
|
322
374
|
showNotification(notification: NotificationInfo): void;
|
package/dist/Frame/Frame.js
CHANGED
|
@@ -4,7 +4,10 @@ import { CrdtChannel, MIN_CRDT_HOST_VERSION } from '../Common/CrdtChannel.js';
|
|
|
4
4
|
import { BlobStore } from '../Common/BlobStore.js';
|
|
5
5
|
import { AiChannel, MIN_AI_HOST_VERSION } from '../Common/AiChannel.js';
|
|
6
6
|
import { isMinVersion } from '../Common/index.js';
|
|
7
|
+
import { AppSettingsError, APP_SETTINGS_TIMEOUT_MS } from '../Common/AppSettings.js';
|
|
8
|
+
import { PublicStorageError, PUBLIC_STORAGE_TIMEOUT_MS, PUBLIC_STORAGE_PUT_TIMEOUT_MS, MAX_PUBLIC_FILE_SIZE_BYTES, validateExpiresIn, putPublicFileExpiryField, withDownloadUrlFallback, } from '../Common/PublicStorage.js';
|
|
7
9
|
import { apiVersion } from '../Version.js';
|
|
10
|
+
import { acceptSharedStreamOffer, } from './SharedStreamPeer.js';
|
|
8
11
|
export class Frame {
|
|
9
12
|
/** @deprecated Use `crdt.doc`. See Connector.yjsDoc for the setter
|
|
10
13
|
* rationale (legacy field-assignment backward-compat). */
|
|
@@ -131,6 +134,18 @@ export class Frame {
|
|
|
131
134
|
writable: true,
|
|
132
135
|
value: void 0
|
|
133
136
|
});
|
|
137
|
+
/**
|
|
138
|
+
* Pushed whenever the AppSettings value at a given level changes — see
|
|
139
|
+
* {@link getSettings} / {@link setSettings}. Fires for changes made by
|
|
140
|
+
* this app itself as well as by another vitre/app instance sharing the
|
|
141
|
+
* same team/space. Added 1.52.
|
|
142
|
+
*/
|
|
143
|
+
Object.defineProperty(this, "onSettingsChanged", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
134
149
|
Object.defineProperty(this, "onVitreSettingsUpdated", {
|
|
135
150
|
enumerable: true,
|
|
136
151
|
configurable: true,
|
|
@@ -306,8 +321,11 @@ export class Frame {
|
|
|
306
321
|
* `MediaStream` it owns INTO this frame (e.g. a received shared camera, or a
|
|
307
322
|
* companion stream routed to this frame for transformation). The stream is
|
|
308
323
|
* rebuilt locally via `MediaStreamTrackGenerator` from transferred readables
|
|
309
|
-
* — zero re-encode, same-site + Chromium only.
|
|
310
|
-
*
|
|
324
|
+
* — zero re-encode, same-site + Chromium only. Elsewhere (a web guest whose
|
|
325
|
+
* page is on another site than the app, Safari, Firefox) the host sends it
|
|
326
|
+
* over a local RTCPeerConnection instead; the callback is the same.
|
|
327
|
+
* `streamId` matches a later `onSharedStreamRemoved`. Inverse of
|
|
328
|
+
* {@link shareStream}.
|
|
311
329
|
*/
|
|
312
330
|
Object.defineProperty(this, "onSharedStream", {
|
|
313
331
|
enumerable: true,
|
|
@@ -450,6 +468,72 @@ export class Frame {
|
|
|
450
468
|
writable: true,
|
|
451
469
|
value: void 0
|
|
452
470
|
});
|
|
471
|
+
/**
|
|
472
|
+
* Public, unauthenticated file storage scoped to the vitre's TEAM — see
|
|
473
|
+
* the README "Public storage" section for the full semantics (scopes,
|
|
474
|
+
* allowed file types, size cap, path rules). Files are readable by
|
|
475
|
+
* ANYONE at the returned URL — never put private data here. Only a
|
|
476
|
+
* Vitre-hosted frame has this — a companion frame cannot write.
|
|
477
|
+
*/
|
|
478
|
+
Object.defineProperty(this, "publicStorage", {
|
|
479
|
+
enumerable: true,
|
|
480
|
+
configurable: true,
|
|
481
|
+
writable: true,
|
|
482
|
+
value: {
|
|
483
|
+
put: async (path, data, contentType, scope = 'app', options) => {
|
|
484
|
+
validateExpiresIn(options?.expiresIn);
|
|
485
|
+
const buffer = await this.toPublicFileBuffer(data);
|
|
486
|
+
if (buffer.byteLength > MAX_PUBLIC_FILE_SIZE_BYTES) {
|
|
487
|
+
throw new PublicStorageError('tooLarge');
|
|
488
|
+
}
|
|
489
|
+
const requestId = randomUuid();
|
|
490
|
+
return await this.postRequest({
|
|
491
|
+
type: 'putPublicFile',
|
|
492
|
+
requestId,
|
|
493
|
+
scope,
|
|
494
|
+
path,
|
|
495
|
+
contentType,
|
|
496
|
+
data: buffer,
|
|
497
|
+
...putPublicFileExpiryField(options?.expiresIn),
|
|
498
|
+
}, (msg, resolve, reject) => {
|
|
499
|
+
if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
|
|
500
|
+
if (msg.ok) {
|
|
501
|
+
resolve(withDownloadUrlFallback(msg.file ?? { path, url: msg.url ?? '', size: buffer.byteLength }));
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
reject(new PublicStorageError(msg.error ?? 'failed'));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}, [buffer], { ms: PUBLIC_STORAGE_PUT_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
|
|
508
|
+
},
|
|
509
|
+
delete: async (path, scope = 'app') => {
|
|
510
|
+
const requestId = randomUuid();
|
|
511
|
+
await this.postRequest({ type: 'deletePublicFile', requestId, scope, path }, (msg, resolve, reject) => {
|
|
512
|
+
if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
|
|
513
|
+
if (msg.ok)
|
|
514
|
+
resolve(undefined);
|
|
515
|
+
else
|
|
516
|
+
reject(new PublicStorageError(msg.error ?? 'failed'));
|
|
517
|
+
}
|
|
518
|
+
}, undefined, { ms: PUBLIC_STORAGE_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
|
|
519
|
+
},
|
|
520
|
+
list: async (prefix, scope = 'app') => {
|
|
521
|
+
const requestId = randomUuid();
|
|
522
|
+
return await this.postRequest({ type: 'listPublicFiles', requestId, scope, prefix }, (msg, resolve, reject) => {
|
|
523
|
+
if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
|
|
524
|
+
if (msg.ok) {
|
|
525
|
+
resolve({
|
|
526
|
+
baseUrl: msg.baseUrl ?? '',
|
|
527
|
+
files: (msg.files ?? []).map(withDownloadUrlFallback),
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
else
|
|
531
|
+
reject(new PublicStorageError(msg.error ?? 'failed'));
|
|
532
|
+
}
|
|
533
|
+
}, undefined, { ms: PUBLIC_STORAGE_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
|
|
534
|
+
},
|
|
535
|
+
}
|
|
536
|
+
});
|
|
453
537
|
/**
|
|
454
538
|
* AI tool channel — publish a catalog of tools the on-prem agent's LLM can call
|
|
455
539
|
* on this frame: `ai.registerTools([{ name, description, parameters, sensitive }],
|
|
@@ -480,6 +564,12 @@ export class Frame {
|
|
|
480
564
|
writable: true,
|
|
481
565
|
value: new Set()
|
|
482
566
|
});
|
|
567
|
+
Object.defineProperty(this, "sharedStreamPeers", {
|
|
568
|
+
enumerable: true,
|
|
569
|
+
configurable: true,
|
|
570
|
+
writable: true,
|
|
571
|
+
value: new Map()
|
|
572
|
+
});
|
|
483
573
|
Object.defineProperty(this, "requestResolvers", {
|
|
484
574
|
enumerable: true,
|
|
485
575
|
configurable: true,
|
|
@@ -689,6 +779,15 @@ export class Frame {
|
|
|
689
779
|
};
|
|
690
780
|
this.onSettingsUpdated?.(msg.settings);
|
|
691
781
|
break;
|
|
782
|
+
case 'appSettingsResponse':
|
|
783
|
+
// Handled by requestResolvers (postRequest pattern)
|
|
784
|
+
break;
|
|
785
|
+
case 'appSettingsChanged':
|
|
786
|
+
this.onSettingsChanged?.(msg);
|
|
787
|
+
break;
|
|
788
|
+
case 'publicStorageResponse':
|
|
789
|
+
// Handled by requestResolvers (postRequest pattern)
|
|
790
|
+
break;
|
|
692
791
|
case 'vitreSettingsUpdated':
|
|
693
792
|
this.hostInformation = {
|
|
694
793
|
...this.hostInformation,
|
|
@@ -809,7 +908,17 @@ export class Frame {
|
|
|
809
908
|
this.onSharedStream?.(msg.streamId, new MediaStream(tracks));
|
|
810
909
|
break;
|
|
811
910
|
}
|
|
911
|
+
case 'sharedStreamOffer': {
|
|
912
|
+
this.sharedStreamPeers.get(msg.streamId)?.close();
|
|
913
|
+
const peer = acceptSharedStreamOffer(msg.port, (stream) => this.onSharedStream?.(msg.streamId, stream), () => {
|
|
914
|
+
if (this.sharedStreamPeers.get(msg.streamId) === peer)
|
|
915
|
+
this.sharedStreamPeers.delete(msg.streamId);
|
|
916
|
+
});
|
|
917
|
+
this.sharedStreamPeers.set(msg.streamId, peer);
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
812
920
|
case 'sharedStreamRemoved':
|
|
921
|
+
this.sharedStreamPeers.get(msg.streamId)?.close();
|
|
813
922
|
this.onSharedStreamRemoved?.(msg.streamId);
|
|
814
923
|
break;
|
|
815
924
|
case 'mediaDevicesChanged':
|
|
@@ -1093,6 +1202,17 @@ export class Frame {
|
|
|
1093
1202
|
canShareStream() {
|
|
1094
1203
|
return typeof MediaStreamTrackProcessor !== 'undefined';
|
|
1095
1204
|
}
|
|
1205
|
+
/** Normalize `publicStorage.put`'s payload to a plain `ArrayBuffer` —
|
|
1206
|
+
* slicing out exactly a typed array's view (not its whole underlying
|
|
1207
|
+
* buffer, in case it's a subarray) so the transferred bytes match the
|
|
1208
|
+
* size the caller intended. */
|
|
1209
|
+
async toPublicFileBuffer(data) {
|
|
1210
|
+
if (data instanceof ArrayBuffer)
|
|
1211
|
+
return data;
|
|
1212
|
+
if (data instanceof Blob)
|
|
1213
|
+
return await data.arrayBuffer();
|
|
1214
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1215
|
+
}
|
|
1096
1216
|
toShareTracks(stream) {
|
|
1097
1217
|
const tracks = [];
|
|
1098
1218
|
const transfer = [];
|
|
@@ -1237,15 +1357,26 @@ export class Frame {
|
|
|
1237
1357
|
}
|
|
1238
1358
|
});
|
|
1239
1359
|
}
|
|
1240
|
-
async postRequest(data, handler, transfer
|
|
1360
|
+
async postRequest(data, handler, transfer,
|
|
1361
|
+
// When set, rejects with `onTimeout()` if no matching response arrives
|
|
1362
|
+
// within `ms` — AND removes the pending resolver from
|
|
1363
|
+
// `requestResolvers`. Without that removal a host that never answers
|
|
1364
|
+
// (e.g. one that predates the message type) would leak the resolver
|
|
1365
|
+
// forever, since the only other removal path is a matching response.
|
|
1366
|
+
timeout) {
|
|
1241
1367
|
return await new Promise((resolve, reject) => {
|
|
1242
1368
|
let isHandled = false;
|
|
1369
|
+
let timer;
|
|
1243
1370
|
const handleAndResolve = (data) => {
|
|
1244
1371
|
isHandled = true;
|
|
1372
|
+
if (timer !== undefined)
|
|
1373
|
+
clearTimeout(timer);
|
|
1245
1374
|
resolve(data);
|
|
1246
1375
|
};
|
|
1247
1376
|
const handleAndReject = (error) => {
|
|
1248
1377
|
isHandled = true;
|
|
1378
|
+
if (timer !== undefined)
|
|
1379
|
+
clearTimeout(timer);
|
|
1249
1380
|
reject(error);
|
|
1250
1381
|
};
|
|
1251
1382
|
const resolver = {
|
|
@@ -1260,6 +1391,14 @@ export class Frame {
|
|
|
1260
1391
|
},
|
|
1261
1392
|
};
|
|
1262
1393
|
this.requestResolvers.push(resolver);
|
|
1394
|
+
if (timeout) {
|
|
1395
|
+
timer = setTimeout(() => {
|
|
1396
|
+
if (isHandled)
|
|
1397
|
+
return;
|
|
1398
|
+
this.requestResolvers = this.requestResolvers.filter((rr) => rr !== resolver);
|
|
1399
|
+
handleAndReject(timeout.onTimeout());
|
|
1400
|
+
}, timeout.ms);
|
|
1401
|
+
}
|
|
1263
1402
|
this.postMessage(data, transfer);
|
|
1264
1403
|
});
|
|
1265
1404
|
}
|
|
@@ -1340,6 +1479,61 @@ export class Frame {
|
|
|
1340
1479
|
settings,
|
|
1341
1480
|
});
|
|
1342
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Read the app's settings at one of the three levels — `vitre` (this
|
|
1484
|
+
* vitre), `team` (the vitre's team), or `space` (the space the vitre is
|
|
1485
|
+
* currently in). Every vitre/app instance of the team can read the same
|
|
1486
|
+
* value; values are JSON objects capped at 64 KB — never store secrets.
|
|
1487
|
+
*
|
|
1488
|
+
* Distinct from the legacy `saveSettings`/`onSettingsUpdated` mechanism,
|
|
1489
|
+
* which is a single vitre-scoped blob rendered by the host's settings
|
|
1490
|
+
* form (see `Connector.setSettingsSchema`).
|
|
1491
|
+
*
|
|
1492
|
+
* Rejects with an {@link AppSettingsError} of code `'unsupported'` if the
|
|
1493
|
+
* host doesn't answer within 10s — a vitre host older than this feature
|
|
1494
|
+
* never responds to `getAppSettings`.
|
|
1495
|
+
*/
|
|
1496
|
+
async getSettings(level) {
|
|
1497
|
+
const requestId = randomUuid();
|
|
1498
|
+
return await this.postRequest({ type: 'getAppSettings', requestId, level }, (msg, resolve, reject) => {
|
|
1499
|
+
if (msg.type === 'appSettingsResponse' && msg.requestId === requestId) {
|
|
1500
|
+
if (msg.ok) {
|
|
1501
|
+
resolve({ level: msg.level, value: msg.value ?? {}, version: msg.version ?? 0 });
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
reject(new AppSettingsError(msg.error ?? 'failed', level));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}, undefined, { ms: APP_SETTINGS_TIMEOUT_MS, onTimeout: () => new AppSettingsError('unsupported', level) });
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Write the app's settings at `level`, with optimistic concurrency:
|
|
1511
|
+
* `expectedVersion` must be the version last observed for that level (from
|
|
1512
|
+
* {@link getSettings} or {@link onSettingsChanged}) — `0` if never
|
|
1513
|
+
* written. A stale version rejects with an {@link AppSettingsError} of
|
|
1514
|
+
* code `'conflict'`; re-read and retry. An oversized `value` (> 64 KB)
|
|
1515
|
+
* rejects with `'tooLarge'`.
|
|
1516
|
+
*
|
|
1517
|
+
* Rejects with code `'unsupported'` if the host doesn't answer within
|
|
1518
|
+
* 10s — see {@link getSettings}.
|
|
1519
|
+
*/
|
|
1520
|
+
async setSettings(level, value, expectedVersion) {
|
|
1521
|
+
const requestId = randomUuid();
|
|
1522
|
+
return await this.postRequest({ type: 'setAppSettings', requestId, level, value, expectedVersion }, (msg, resolve, reject) => {
|
|
1523
|
+
if (msg.type === 'appSettingsResponse' && msg.requestId === requestId) {
|
|
1524
|
+
if (msg.ok) {
|
|
1525
|
+
resolve({
|
|
1526
|
+
level: msg.level,
|
|
1527
|
+
value: msg.value ?? value,
|
|
1528
|
+
version: msg.version ?? expectedVersion,
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
reject(new AppSettingsError(msg.error ?? 'failed', level));
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}, undefined, { ms: APP_SETTINGS_TIMEOUT_MS, onTimeout: () => new AppSettingsError('unsupported', level) });
|
|
1536
|
+
}
|
|
1343
1537
|
changeTeamSpace(space) {
|
|
1344
1538
|
this.postMessage({
|
|
1345
1539
|
type: 'changeTeamSpace',
|
|
@@ -1463,7 +1657,15 @@ export async function initializeFrame(init, createFrame) {
|
|
|
1463
1657
|
return await new Promise((resolve) => {
|
|
1464
1658
|
const channel = new MessageChannel();
|
|
1465
1659
|
let frame = null;
|
|
1660
|
+
// A shared stream can reach the frame before `initialize` (the host posts
|
|
1661
|
+
// it on the window while the init travels on the port). Keep those until the
|
|
1662
|
+
// app has had its turn to set `onSharedStream` after `await initializeFrame`.
|
|
1663
|
+
const earlyStreams = [];
|
|
1466
1664
|
const messageHandler = (createPostMessage) => (e) => {
|
|
1665
|
+
// Any script can post to this window, and a message whose payload
|
|
1666
|
+
// cannot be deserialized here arrives with `data === null`.
|
|
1667
|
+
if (e.data == null || typeof e.data !== 'object')
|
|
1668
|
+
return;
|
|
1467
1669
|
switch (e.data.type) {
|
|
1468
1670
|
case 'initialize':
|
|
1469
1671
|
if (frame === null) {
|
|
@@ -1471,8 +1673,22 @@ export async function initializeFrame(init, createFrame) {
|
|
|
1471
1673
|
const options = init(initializeMsg.hostInfo, initializeMsg.initiator, initializeMsg.options, initializeMsg.state);
|
|
1472
1674
|
frame = new (createFrame ?? Frame)(createPostMessage(initializeMsg.hostInfo.origin), initializeMsg, options, initializeMsg.state);
|
|
1473
1675
|
resolve(frame);
|
|
1676
|
+
if (earlyStreams.length > 0) {
|
|
1677
|
+
const created = frame;
|
|
1678
|
+
setTimeout(() => {
|
|
1679
|
+
for (const msg of earlyStreams.splice(0))
|
|
1680
|
+
created.raiseMessage(msg);
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1474
1683
|
}
|
|
1475
1684
|
break;
|
|
1685
|
+
case 'sharedStreamAvailable':
|
|
1686
|
+
case 'sharedStreamOffer':
|
|
1687
|
+
if (frame === null)
|
|
1688
|
+
earlyStreams.push(e.data);
|
|
1689
|
+
else
|
|
1690
|
+
frame.raiseMessage(e.data);
|
|
1691
|
+
break;
|
|
1476
1692
|
default:
|
|
1477
1693
|
frame?.raiseMessage(e.data);
|
|
1478
1694
|
break;
|