@lavitre/apps 1.53.0 → 1.56.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.
Files changed (39) hide show
  1. package/README.md +180 -0
  2. package/dist/Common/AppSettings.d.ts +34 -0
  3. package/dist/Common/AppSettings.js +35 -0
  4. package/dist/Common/AppSettings.js.map +1 -0
  5. package/dist/Common/Common.Model.d.ts +271 -0
  6. package/dist/Common/Common.Model.js.map +1 -1
  7. package/dist/Common/PrivateStorage.d.ts +249 -0
  8. package/dist/Common/PrivateStorage.js +158 -0
  9. package/dist/Common/PrivateStorage.js.map +1 -0
  10. package/dist/Common/PublicStorage.d.ts +140 -0
  11. package/dist/Common/PublicStorage.js +88 -0
  12. package/dist/Common/PublicStorage.js.map +1 -0
  13. package/dist/Common/index.d.ts +3 -0
  14. package/dist/Common/index.js +3 -0
  15. package/dist/Common/index.js.map +1 -1
  16. package/dist/CompanionConnector/CompanionConnector.Model.d.ts +11 -3
  17. package/dist/CompanionConnector/CompanionConnector.Model.js.map +1 -1
  18. package/dist/CompanionConnector/CompanionConnector.d.ts +14 -0
  19. package/dist/CompanionConnector/CompanionConnector.js +122 -0
  20. package/dist/CompanionConnector/CompanionConnector.js.map +1 -1
  21. package/dist/CompanionFrame/CompanionFrame.d.ts +13 -2
  22. package/dist/CompanionFrame/CompanionFrame.js.map +1 -1
  23. package/dist/Connector/Connector.Model.d.ts +29 -1
  24. package/dist/Connector/Connector.Model.js.map +1 -1
  25. package/dist/Connector/Connector.d.ts +60 -1
  26. package/dist/Connector/Connector.js +280 -1
  27. package/dist/Connector/Connector.js.map +1 -1
  28. package/dist/Frame/Frame.Model.d.ts +36 -2
  29. package/dist/Frame/Frame.Model.js.map +1 -1
  30. package/dist/Frame/Frame.d.ts +68 -3
  31. package/dist/Frame/Frame.js +326 -3
  32. package/dist/Frame/Frame.js.map +1 -1
  33. package/dist/Frame/SharedStreamPeer.d.ts +16 -0
  34. package/dist/Frame/SharedStreamPeer.js +74 -0
  35. package/dist/Frame/SharedStreamPeer.js.map +1 -0
  36. package/dist/Version.d.ts +1 -1
  37. package/dist/Version.js +1 -1
  38. package/dist/Version.js.map +1 -1
  39. package/package.json +1 -1
@@ -2,7 +2,9 @@ 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 { AppId, 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';
5
+ import type { PublicStorageApi } from '../Common/PublicStorage.js';
6
+ import type { PrivateStorageApi } from '../Common/PrivateStorage.js';
7
+ 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
8
  import type { Connector, ShareStreamOptions } from '../Connector/index.js';
7
9
  import type { MediaTrackInfo } from '../Connector/Connector.Model.js';
8
10
  import type { ApplyStreamAdvancedConstraints, AvailableExportSource, ExportData, ExportRequest, FrameApiMessagesIn, FrameApiMessagesOut, FrameMenuEntry, IceServerConfig, InitFrameOptions, InitializeFrame, SharedStreamPlayState, ViewOptions } from './Frame.Model.js';
@@ -35,6 +37,13 @@ export declare class Frame {
35
37
  onExportRequest?: (request: ExportRequest, resolve: (data: ExportData) => void, reject: (error: string) => void) => void;
36
38
  onKnockKnock?: (knockKnock: KnockKnock) => void;
37
39
  onSettingsUpdated?: (settings: any) => void;
40
+ /**
41
+ * Pushed whenever the AppSettings value at a given level changes — see
42
+ * {@link getSettings} / {@link setSettings}. Fires for changes made by
43
+ * this app itself as well as by another vitre/app instance sharing the
44
+ * same team/space. Added 1.52.
45
+ */
46
+ onSettingsChanged?: (change: AppSettingsValue) => void;
38
47
  onVitreSettingsUpdated?: (settings: VitreSettings) => void;
39
48
  onConnectionCodeUpdated?: (companionCode?: string) => void;
40
49
  onNotificationDismissed?: (notificationId: string) => void;
@@ -85,8 +94,11 @@ export declare class Frame {
85
94
  * `MediaStream` it owns INTO this frame (e.g. a received shared camera, or a
86
95
  * companion stream routed to this frame for transformation). The stream is
87
96
  * rebuilt locally via `MediaStreamTrackGenerator` from transferred readables
88
- * — zero re-encode, same-site + Chromium only. `streamId` matches a later
89
- * `onSharedStreamRemoved`. Inverse of {@link shareStream}.
97
+ * — zero re-encode, same-site + Chromium only. Elsewhere (a web guest whose
98
+ * page is on another site than the app, Safari, Firefox) the host sends it
99
+ * over a local RTCPeerConnection instead; the callback is the same.
100
+ * `streamId` matches a later `onSharedStreamRemoved`. Inverse of
101
+ * {@link shareStream}.
90
102
  */
91
103
  onSharedStream?: (streamId: string, stream: MediaStream) => void;
92
104
  onSharedStreamRemoved?: (streamId: string) => void;
@@ -134,6 +146,24 @@ export declare class Frame {
134
146
  * CRDT-backed blob store built on `crdt.attachSubdoc` — see Connector.blobs.
135
147
  */
136
148
  readonly blobs: BlobStore;
149
+ /**
150
+ * Public, unauthenticated file storage scoped to the vitre's TEAM — see
151
+ * the README "Public storage" section for the full semantics (scopes,
152
+ * allowed file types, size cap, path rules). Files are readable by
153
+ * ANYONE at the returned URL — never put private data here. Only a
154
+ * Vitre-hosted frame has this — a companion frame cannot write.
155
+ */
156
+ readonly publicStorage: PublicStorageApi;
157
+ /**
158
+ * Private file storage scoped to the vitre's TEAM — see the README
159
+ * "Private storage" section for the full semantics. Unlike
160
+ * `publicStorage`, files here have no public link: readable by any
161
+ * vitre or companion of the team via `get` or a temporary `getLink`
162
+ * signed link, never by an anonymous visitor. Full (put/delete/list/
163
+ * get/getLink) on a Vitre-hosted frame; a companion frame only has
164
+ * `list`/`get`/`getLink` (see the `CompanionFrame` exported type).
165
+ */
166
+ readonly privateStorage: PrivateStorageApi;
137
167
  /**
138
168
  * AI tool channel — publish a catalog of tools the on-prem agent's LLM can call
139
169
  * on this frame: `ai.registerTools([{ name, description, parameters, sensitive }],
@@ -148,6 +178,7 @@ export declare class Frame {
148
178
  position: Rect;
149
179
  zIndex: number;
150
180
  private deviceStateListeners;
181
+ private sharedStreamPeers;
151
182
  /**
152
183
  * Called after any change of `hostInformation.device`,
153
184
  * `hostInformation.devicesInSpace` or the available media devices (device
@@ -228,6 +259,13 @@ export declare class Frame {
228
259
  * `Connector.canShareStream`.
229
260
  */
230
261
  canShareStream(): boolean;
262
+ /** Normalize `publicStorage.put`'s payload to a plain `ArrayBuffer` —
263
+ * slicing out exactly a typed array's view (not its whole underlying
264
+ * buffer, in case it's a subarray) so the transferred bytes match the
265
+ * size the caller intended. */
266
+ private toPublicFileBuffer;
267
+ /** Same normalization as {@link toPublicFileBuffer}, for `privateStorage.put`. */
268
+ private toPrivateFileBuffer;
231
269
  private toShareTracks;
232
270
  /**
233
271
  * Share a `MediaStream` the frame produced (e.g. a WebGL-transformed track,
@@ -317,6 +355,33 @@ export declare class Frame {
317
355
  */
318
356
  shareFile(fileData: FileData, targetAppId: AppId, owner?: string): void;
319
357
  saveSettings(settings: any): void;
358
+ /**
359
+ * Read the app's settings at one of the three levels — `vitre` (this
360
+ * vitre), `team` (the vitre's team), or `space` (the space the vitre is
361
+ * currently in). Every vitre/app instance of the team can read the same
362
+ * value; values are JSON objects capped at 64 KB — never store secrets.
363
+ *
364
+ * Distinct from the legacy `saveSettings`/`onSettingsUpdated` mechanism,
365
+ * which is a single vitre-scoped blob rendered by the host's settings
366
+ * form (see `Connector.setSettingsSchema`).
367
+ *
368
+ * Rejects with an {@link AppSettingsError} of code `'unsupported'` if the
369
+ * host doesn't answer within 10s — a vitre host older than this feature
370
+ * never responds to `getAppSettings`.
371
+ */
372
+ getSettings(level: AppSettingsLevel): Promise<AppSettingsValue>;
373
+ /**
374
+ * Write the app's settings at `level`, with optimistic concurrency:
375
+ * `expectedVersion` must be the version last observed for that level (from
376
+ * {@link getSettings} or {@link onSettingsChanged}) — `0` if never
377
+ * written. A stale version rejects with an {@link AppSettingsError} of
378
+ * code `'conflict'`; re-read and retry. An oversized `value` (> 64 KB)
379
+ * rejects with `'tooLarge'`.
380
+ *
381
+ * Rejects with code `'unsupported'` if the host doesn't answer within
382
+ * 10s — see {@link getSettings}.
383
+ */
384
+ setSettings(level: AppSettingsLevel, value: Record<string, unknown>, expectedVersion: number): Promise<AppSettingsValue>;
320
385
  changeTeamSpace(space: string): void;
321
386
  changeTeamSpaceGuest(space: string, teamDomain: string): void;
322
387
  showNotification(notification: NotificationInfo): void;
@@ -4,7 +4,11 @@ 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';
9
+ import { PrivateStorageError, PRIVATE_STORAGE_TIMEOUT_MS, PRIVATE_STORAGE_PUT_TIMEOUT_MS, PRIVATE_STORAGE_GET_TIMEOUT_MS, MAX_PRIVATE_FILE_SIZE_BYTES, validatePrivatePath, validatePrivateExpiresIn, validateLinkExpiresIn, privateFileExpiryField, } from '../Common/PrivateStorage.js';
7
10
  import { apiVersion } from '../Version.js';
11
+ import { acceptSharedStreamOffer, } from './SharedStreamPeer.js';
8
12
  export class Frame {
9
13
  /** @deprecated Use `crdt.doc`. See Connector.yjsDoc for the setter
10
14
  * rationale (legacy field-assignment backward-compat). */
@@ -131,6 +135,18 @@ export class Frame {
131
135
  writable: true,
132
136
  value: void 0
133
137
  });
138
+ /**
139
+ * Pushed whenever the AppSettings value at a given level changes — see
140
+ * {@link getSettings} / {@link setSettings}. Fires for changes made by
141
+ * this app itself as well as by another vitre/app instance sharing the
142
+ * same team/space. Added 1.52.
143
+ */
144
+ Object.defineProperty(this, "onSettingsChanged", {
145
+ enumerable: true,
146
+ configurable: true,
147
+ writable: true,
148
+ value: void 0
149
+ });
134
150
  Object.defineProperty(this, "onVitreSettingsUpdated", {
135
151
  enumerable: true,
136
152
  configurable: true,
@@ -306,8 +322,11 @@ export class Frame {
306
322
  * `MediaStream` it owns INTO this frame (e.g. a received shared camera, or a
307
323
  * companion stream routed to this frame for transformation). The stream is
308
324
  * rebuilt locally via `MediaStreamTrackGenerator` from transferred readables
309
- * — zero re-encode, same-site + Chromium only. `streamId` matches a later
310
- * `onSharedStreamRemoved`. Inverse of {@link shareStream}.
325
+ * — zero re-encode, same-site + Chromium only. Elsewhere (a web guest whose
326
+ * page is on another site than the app, Safari, Firefox) the host sends it
327
+ * over a local RTCPeerConnection instead; the callback is the same.
328
+ * `streamId` matches a later `onSharedStreamRemoved`. Inverse of
329
+ * {@link shareStream}.
311
330
  */
312
331
  Object.defineProperty(this, "onSharedStream", {
313
332
  enumerable: true,
@@ -450,6 +469,167 @@ export class Frame {
450
469
  writable: true,
451
470
  value: void 0
452
471
  });
472
+ /**
473
+ * Public, unauthenticated file storage scoped to the vitre's TEAM — see
474
+ * the README "Public storage" section for the full semantics (scopes,
475
+ * allowed file types, size cap, path rules). Files are readable by
476
+ * ANYONE at the returned URL — never put private data here. Only a
477
+ * Vitre-hosted frame has this — a companion frame cannot write.
478
+ */
479
+ Object.defineProperty(this, "publicStorage", {
480
+ enumerable: true,
481
+ configurable: true,
482
+ writable: true,
483
+ value: {
484
+ put: async (path, data, contentType, scope = 'app', options) => {
485
+ validateExpiresIn(options?.expiresIn);
486
+ const buffer = await this.toPublicFileBuffer(data);
487
+ if (buffer.byteLength > MAX_PUBLIC_FILE_SIZE_BYTES) {
488
+ throw new PublicStorageError('tooLarge');
489
+ }
490
+ const requestId = randomUuid();
491
+ return await this.postRequest({
492
+ type: 'putPublicFile',
493
+ requestId,
494
+ scope,
495
+ path,
496
+ contentType,
497
+ data: buffer,
498
+ ...putPublicFileExpiryField(options?.expiresIn),
499
+ }, (msg, resolve, reject) => {
500
+ if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
501
+ if (msg.ok) {
502
+ resolve(withDownloadUrlFallback(msg.file ?? { path, url: msg.url ?? '', size: buffer.byteLength }));
503
+ }
504
+ else {
505
+ reject(new PublicStorageError(msg.error ?? 'failed'));
506
+ }
507
+ }
508
+ }, [buffer], { ms: PUBLIC_STORAGE_PUT_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
509
+ },
510
+ delete: async (path, scope = 'app') => {
511
+ const requestId = randomUuid();
512
+ await this.postRequest({ type: 'deletePublicFile', requestId, scope, path }, (msg, resolve, reject) => {
513
+ if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
514
+ if (msg.ok)
515
+ resolve(undefined);
516
+ else
517
+ reject(new PublicStorageError(msg.error ?? 'failed'));
518
+ }
519
+ }, undefined, { ms: PUBLIC_STORAGE_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
520
+ },
521
+ list: async (prefix, scope = 'app') => {
522
+ const requestId = randomUuid();
523
+ return await this.postRequest({ type: 'listPublicFiles', requestId, scope, prefix }, (msg, resolve, reject) => {
524
+ if (msg.type === 'publicStorageResponse' && msg.requestId === requestId) {
525
+ if (msg.ok) {
526
+ resolve({
527
+ baseUrl: msg.baseUrl ?? '',
528
+ files: (msg.files ?? []).map(withDownloadUrlFallback),
529
+ });
530
+ }
531
+ else
532
+ reject(new PublicStorageError(msg.error ?? 'failed'));
533
+ }
534
+ }, undefined, { ms: PUBLIC_STORAGE_TIMEOUT_MS, onTimeout: () => new PublicStorageError('unsupported') });
535
+ },
536
+ }
537
+ });
538
+ /**
539
+ * Private file storage scoped to the vitre's TEAM — see the README
540
+ * "Private storage" section for the full semantics. Unlike
541
+ * `publicStorage`, files here have no public link: readable by any
542
+ * vitre or companion of the team via `get` or a temporary `getLink`
543
+ * signed link, never by an anonymous visitor. Full (put/delete/list/
544
+ * get/getLink) on a Vitre-hosted frame; a companion frame only has
545
+ * `list`/`get`/`getLink` (see the `CompanionFrame` exported type).
546
+ */
547
+ Object.defineProperty(this, "privateStorage", {
548
+ enumerable: true,
549
+ configurable: true,
550
+ writable: true,
551
+ value: {
552
+ put: async (path, data, contentType, scope = 'app', options) => {
553
+ validatePrivatePath(path);
554
+ validatePrivateExpiresIn(options?.expiresIn);
555
+ const buffer = await this.toPrivateFileBuffer(data);
556
+ if (buffer.byteLength > MAX_PRIVATE_FILE_SIZE_BYTES) {
557
+ throw new PrivateStorageError('tooLarge');
558
+ }
559
+ const requestId = randomUuid();
560
+ return await this.postRequest({
561
+ type: 'putPrivateFile',
562
+ requestId,
563
+ scope,
564
+ path,
565
+ contentType,
566
+ data: buffer,
567
+ ...privateFileExpiryField(options?.expiresIn),
568
+ }, (msg, resolve, reject) => {
569
+ if (msg.type === 'privateStorageResponse' && msg.requestId === requestId) {
570
+ if (msg.ok) {
571
+ resolve(msg.file ?? { path, size: buffer.byteLength, contentType });
572
+ }
573
+ else {
574
+ reject(new PrivateStorageError(msg.error ?? 'failed'));
575
+ }
576
+ }
577
+ }, [buffer], { ms: PRIVATE_STORAGE_PUT_TIMEOUT_MS, onTimeout: () => new PrivateStorageError('unsupported') });
578
+ },
579
+ delete: async (path, scope = 'app') => {
580
+ const requestId = randomUuid();
581
+ await this.postRequest({ type: 'deletePrivateFile', requestId, scope, path }, (msg, resolve, reject) => {
582
+ if (msg.type === 'privateStorageResponse' && msg.requestId === requestId) {
583
+ if (msg.ok)
584
+ resolve(undefined);
585
+ else
586
+ reject(new PrivateStorageError(msg.error ?? 'failed'));
587
+ }
588
+ }, undefined, { ms: PRIVATE_STORAGE_TIMEOUT_MS, onTimeout: () => new PrivateStorageError('unsupported') });
589
+ },
590
+ list: async (prefix, scope = 'app') => {
591
+ const requestId = randomUuid();
592
+ return await this.postRequest({ type: 'listPrivateFiles', requestId, scope, prefix }, (msg, resolve, reject) => {
593
+ if (msg.type === 'privateStorageResponse' && msg.requestId === requestId) {
594
+ if (msg.ok)
595
+ resolve({ scope, files: msg.files ?? [] });
596
+ else
597
+ reject(new PrivateStorageError(msg.error ?? 'failed'));
598
+ }
599
+ }, undefined, { ms: PRIVATE_STORAGE_TIMEOUT_MS, onTimeout: () => new PrivateStorageError('unsupported') });
600
+ },
601
+ get: async (path, scope = 'app') => {
602
+ const requestId = randomUuid();
603
+ return await this.postRequest({ type: 'getPrivateFile', requestId, scope, path }, (msg, resolve, reject) => {
604
+ if (msg.type === 'privateStorageResponse' && msg.requestId === requestId) {
605
+ if (msg.ok && msg.data)
606
+ resolve({ data: msg.data, contentType: msg.contentType ?? '' });
607
+ else
608
+ reject(new PrivateStorageError(msg.error ?? 'failed'));
609
+ }
610
+ }, undefined, { ms: PRIVATE_STORAGE_GET_TIMEOUT_MS, onTimeout: () => new PrivateStorageError('unsupported') });
611
+ },
612
+ getLink: async (path, options) => {
613
+ validateLinkExpiresIn(options?.expiresIn);
614
+ const scope = options?.scope ?? 'app';
615
+ const requestId = randomUuid();
616
+ return await this.postRequest({
617
+ type: 'getPrivateFileLink',
618
+ requestId,
619
+ scope,
620
+ path,
621
+ ...privateFileExpiryField(options?.expiresIn),
622
+ }, (msg, resolve, reject) => {
623
+ if (msg.type === 'privateStorageResponse' && msg.requestId === requestId) {
624
+ if (msg.ok && msg.link)
625
+ resolve(msg.link);
626
+ else
627
+ reject(new PrivateStorageError(msg.error ?? 'failed'));
628
+ }
629
+ }, undefined, { ms: PRIVATE_STORAGE_TIMEOUT_MS, onTimeout: () => new PrivateStorageError('unsupported') });
630
+ },
631
+ }
632
+ });
453
633
  /**
454
634
  * AI tool channel — publish a catalog of tools the on-prem agent's LLM can call
455
635
  * on this frame: `ai.registerTools([{ name, description, parameters, sensitive }],
@@ -480,6 +660,12 @@ export class Frame {
480
660
  writable: true,
481
661
  value: new Set()
482
662
  });
663
+ Object.defineProperty(this, "sharedStreamPeers", {
664
+ enumerable: true,
665
+ configurable: true,
666
+ writable: true,
667
+ value: new Map()
668
+ });
483
669
  Object.defineProperty(this, "requestResolvers", {
484
670
  enumerable: true,
485
671
  configurable: true,
@@ -689,6 +875,18 @@ export class Frame {
689
875
  };
690
876
  this.onSettingsUpdated?.(msg.settings);
691
877
  break;
878
+ case 'appSettingsResponse':
879
+ // Handled by requestResolvers (postRequest pattern)
880
+ break;
881
+ case 'appSettingsChanged':
882
+ this.onSettingsChanged?.(msg);
883
+ break;
884
+ case 'publicStorageResponse':
885
+ // Handled by requestResolvers (postRequest pattern)
886
+ break;
887
+ case 'privateStorageResponse':
888
+ // Handled by requestResolvers (postRequest pattern)
889
+ break;
692
890
  case 'vitreSettingsUpdated':
693
891
  this.hostInformation = {
694
892
  ...this.hostInformation,
@@ -809,7 +1007,17 @@ export class Frame {
809
1007
  this.onSharedStream?.(msg.streamId, new MediaStream(tracks));
810
1008
  break;
811
1009
  }
1010
+ case 'sharedStreamOffer': {
1011
+ this.sharedStreamPeers.get(msg.streamId)?.close();
1012
+ const peer = acceptSharedStreamOffer(msg.port, (stream) => this.onSharedStream?.(msg.streamId, stream), () => {
1013
+ if (this.sharedStreamPeers.get(msg.streamId) === peer)
1014
+ this.sharedStreamPeers.delete(msg.streamId);
1015
+ });
1016
+ this.sharedStreamPeers.set(msg.streamId, peer);
1017
+ break;
1018
+ }
812
1019
  case 'sharedStreamRemoved':
1020
+ this.sharedStreamPeers.get(msg.streamId)?.close();
813
1021
  this.onSharedStreamRemoved?.(msg.streamId);
814
1022
  break;
815
1023
  case 'mediaDevicesChanged':
@@ -1093,6 +1301,25 @@ export class Frame {
1093
1301
  canShareStream() {
1094
1302
  return typeof MediaStreamTrackProcessor !== 'undefined';
1095
1303
  }
1304
+ /** Normalize `publicStorage.put`'s payload to a plain `ArrayBuffer` —
1305
+ * slicing out exactly a typed array's view (not its whole underlying
1306
+ * buffer, in case it's a subarray) so the transferred bytes match the
1307
+ * size the caller intended. */
1308
+ async toPublicFileBuffer(data) {
1309
+ if (data instanceof ArrayBuffer)
1310
+ return data;
1311
+ if (data instanceof Blob)
1312
+ return await data.arrayBuffer();
1313
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
1314
+ }
1315
+ /** Same normalization as {@link toPublicFileBuffer}, for `privateStorage.put`. */
1316
+ async toPrivateFileBuffer(data) {
1317
+ if (data instanceof ArrayBuffer)
1318
+ return data;
1319
+ if (data instanceof Blob)
1320
+ return await data.arrayBuffer();
1321
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
1322
+ }
1096
1323
  toShareTracks(stream) {
1097
1324
  const tracks = [];
1098
1325
  const transfer = [];
@@ -1237,15 +1464,26 @@ export class Frame {
1237
1464
  }
1238
1465
  });
1239
1466
  }
1240
- async postRequest(data, handler, transfer) {
1467
+ async postRequest(data, handler, transfer,
1468
+ // When set, rejects with `onTimeout()` if no matching response arrives
1469
+ // within `ms` — AND removes the pending resolver from
1470
+ // `requestResolvers`. Without that removal a host that never answers
1471
+ // (e.g. one that predates the message type) would leak the resolver
1472
+ // forever, since the only other removal path is a matching response.
1473
+ timeout) {
1241
1474
  return await new Promise((resolve, reject) => {
1242
1475
  let isHandled = false;
1476
+ let timer;
1243
1477
  const handleAndResolve = (data) => {
1244
1478
  isHandled = true;
1479
+ if (timer !== undefined)
1480
+ clearTimeout(timer);
1245
1481
  resolve(data);
1246
1482
  };
1247
1483
  const handleAndReject = (error) => {
1248
1484
  isHandled = true;
1485
+ if (timer !== undefined)
1486
+ clearTimeout(timer);
1249
1487
  reject(error);
1250
1488
  };
1251
1489
  const resolver = {
@@ -1260,6 +1498,14 @@ export class Frame {
1260
1498
  },
1261
1499
  };
1262
1500
  this.requestResolvers.push(resolver);
1501
+ if (timeout) {
1502
+ timer = setTimeout(() => {
1503
+ if (isHandled)
1504
+ return;
1505
+ this.requestResolvers = this.requestResolvers.filter((rr) => rr !== resolver);
1506
+ handleAndReject(timeout.onTimeout());
1507
+ }, timeout.ms);
1508
+ }
1263
1509
  this.postMessage(data, transfer);
1264
1510
  });
1265
1511
  }
@@ -1340,6 +1586,61 @@ export class Frame {
1340
1586
  settings,
1341
1587
  });
1342
1588
  }
1589
+ /**
1590
+ * Read the app's settings at one of the three levels — `vitre` (this
1591
+ * vitre), `team` (the vitre's team), or `space` (the space the vitre is
1592
+ * currently in). Every vitre/app instance of the team can read the same
1593
+ * value; values are JSON objects capped at 64 KB — never store secrets.
1594
+ *
1595
+ * Distinct from the legacy `saveSettings`/`onSettingsUpdated` mechanism,
1596
+ * which is a single vitre-scoped blob rendered by the host's settings
1597
+ * form (see `Connector.setSettingsSchema`).
1598
+ *
1599
+ * Rejects with an {@link AppSettingsError} of code `'unsupported'` if the
1600
+ * host doesn't answer within 10s — a vitre host older than this feature
1601
+ * never responds to `getAppSettings`.
1602
+ */
1603
+ async getSettings(level) {
1604
+ const requestId = randomUuid();
1605
+ return await this.postRequest({ type: 'getAppSettings', requestId, level }, (msg, resolve, reject) => {
1606
+ if (msg.type === 'appSettingsResponse' && msg.requestId === requestId) {
1607
+ if (msg.ok) {
1608
+ resolve({ level: msg.level, value: msg.value ?? {}, version: msg.version ?? 0 });
1609
+ }
1610
+ else {
1611
+ reject(new AppSettingsError(msg.error ?? 'failed', level));
1612
+ }
1613
+ }
1614
+ }, undefined, { ms: APP_SETTINGS_TIMEOUT_MS, onTimeout: () => new AppSettingsError('unsupported', level) });
1615
+ }
1616
+ /**
1617
+ * Write the app's settings at `level`, with optimistic concurrency:
1618
+ * `expectedVersion` must be the version last observed for that level (from
1619
+ * {@link getSettings} or {@link onSettingsChanged}) — `0` if never
1620
+ * written. A stale version rejects with an {@link AppSettingsError} of
1621
+ * code `'conflict'`; re-read and retry. An oversized `value` (> 64 KB)
1622
+ * rejects with `'tooLarge'`.
1623
+ *
1624
+ * Rejects with code `'unsupported'` if the host doesn't answer within
1625
+ * 10s — see {@link getSettings}.
1626
+ */
1627
+ async setSettings(level, value, expectedVersion) {
1628
+ const requestId = randomUuid();
1629
+ return await this.postRequest({ type: 'setAppSettings', requestId, level, value, expectedVersion }, (msg, resolve, reject) => {
1630
+ if (msg.type === 'appSettingsResponse' && msg.requestId === requestId) {
1631
+ if (msg.ok) {
1632
+ resolve({
1633
+ level: msg.level,
1634
+ value: msg.value ?? value,
1635
+ version: msg.version ?? expectedVersion,
1636
+ });
1637
+ }
1638
+ else {
1639
+ reject(new AppSettingsError(msg.error ?? 'failed', level));
1640
+ }
1641
+ }
1642
+ }, undefined, { ms: APP_SETTINGS_TIMEOUT_MS, onTimeout: () => new AppSettingsError('unsupported', level) });
1643
+ }
1343
1644
  changeTeamSpace(space) {
1344
1645
  this.postMessage({
1345
1646
  type: 'changeTeamSpace',
@@ -1463,7 +1764,15 @@ export async function initializeFrame(init, createFrame) {
1463
1764
  return await new Promise((resolve) => {
1464
1765
  const channel = new MessageChannel();
1465
1766
  let frame = null;
1767
+ // A shared stream can reach the frame before `initialize` (the host posts
1768
+ // it on the window while the init travels on the port). Keep those until the
1769
+ // app has had its turn to set `onSharedStream` after `await initializeFrame`.
1770
+ const earlyStreams = [];
1466
1771
  const messageHandler = (createPostMessage) => (e) => {
1772
+ // Any script can post to this window, and a message whose payload
1773
+ // cannot be deserialized here arrives with `data === null`.
1774
+ if (e.data == null || typeof e.data !== 'object')
1775
+ return;
1467
1776
  switch (e.data.type) {
1468
1777
  case 'initialize':
1469
1778
  if (frame === null) {
@@ -1471,8 +1780,22 @@ export async function initializeFrame(init, createFrame) {
1471
1780
  const options = init(initializeMsg.hostInfo, initializeMsg.initiator, initializeMsg.options, initializeMsg.state);
1472
1781
  frame = new (createFrame ?? Frame)(createPostMessage(initializeMsg.hostInfo.origin), initializeMsg, options, initializeMsg.state);
1473
1782
  resolve(frame);
1783
+ if (earlyStreams.length > 0) {
1784
+ const created = frame;
1785
+ setTimeout(() => {
1786
+ for (const msg of earlyStreams.splice(0))
1787
+ created.raiseMessage(msg);
1788
+ });
1789
+ }
1474
1790
  }
1475
1791
  break;
1792
+ case 'sharedStreamAvailable':
1793
+ case 'sharedStreamOffer':
1794
+ if (frame === null)
1795
+ earlyStreams.push(e.data);
1796
+ else
1797
+ frame.raiseMessage(e.data);
1798
+ break;
1476
1799
  default:
1477
1800
  frame?.raiseMessage(e.data);
1478
1801
  break;