@lumencast/runtime 0.9.0 → 0.10.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 (90) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/app.d.ts +6 -1
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +3 -1
  5. package/dist/app.js.map +1 -1
  6. package/dist/{broadcast-ryjLRD5q.js → broadcast-L5wm2I6J.js} +3 -3
  7. package/dist/{broadcast-ryjLRD5q.js.map → broadcast-L5wm2I6J.js.map} +1 -1
  8. package/dist/{control-AgxbXOVS.js → control-eEUG7unp.js} +4 -4
  9. package/dist/{control-AgxbXOVS.js.map → control-eEUG7unp.js.map} +1 -1
  10. package/dist/index-Clrya_9l.js +1281 -0
  11. package/dist/index-Clrya_9l.js.map +1 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.html +1 -1
  15. package/dist/index.js +11 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/lumencast.js +18 -13
  18. package/dist/mount.d.ts.map +1 -1
  19. package/dist/mount.js +11 -0
  20. package/dist/mount.js.map +1 -1
  21. package/dist/overlay/runtime-context.d.ts +10 -0
  22. package/dist/overlay/runtime-context.d.ts.map +1 -1
  23. package/dist/overlay/runtime-context.js.map +1 -1
  24. package/dist/render/bundle.d.ts +1 -1
  25. package/dist/render/bundle.d.ts.map +1 -1
  26. package/dist/render/bundle.js.map +1 -1
  27. package/dist/render/primitives/capture.d.ts +13 -4
  28. package/dist/render/primitives/capture.d.ts.map +1 -1
  29. package/dist/render/primitives/capture.js +54 -22
  30. package/dist/render/primitives/capture.js.map +1 -1
  31. package/dist/render/primitives/index.d.ts.map +1 -1
  32. package/dist/render/primitives/index.js +4 -0
  33. package/dist/render/primitives/index.js.map +1 -1
  34. package/dist/render/primitives/live-peer-video.d.ts +27 -0
  35. package/dist/render/primitives/live-peer-video.d.ts.map +1 -0
  36. package/dist/render/primitives/live-peer-video.js +64 -0
  37. package/dist/render/primitives/live-peer-video.js.map +1 -0
  38. package/dist/render/primitives/media.d.ts +37 -12
  39. package/dist/render/primitives/media.d.ts.map +1 -1
  40. package/dist/render/primitives/media.js +43 -17
  41. package/dist/render/primitives/media.js.map +1 -1
  42. package/dist/render/primitives/meet-peer.d.ts +31 -0
  43. package/dist/render/primitives/meet-peer.d.ts.map +1 -0
  44. package/dist/render/primitives/meet-peer.js +46 -0
  45. package/dist/render/primitives/meet-peer.js.map +1 -0
  46. package/dist/render/prop-allowlist.d.ts.map +1 -1
  47. package/dist/render/prop-allowlist.js +27 -1
  48. package/dist/render/prop-allowlist.js.map +1 -1
  49. package/dist/render/tree.js +42 -8
  50. package/dist/render/tree.js.map +1 -1
  51. package/dist/{status-pill-BxCdj-KZ.js → status-pill-elORkMrh.js} +2 -2
  52. package/dist/{status-pill-BxCdj-KZ.js.map → status-pill-elORkMrh.js.map} +1 -1
  53. package/dist/{test-CaRHj_J6.js → test-7q_KJkdX.js} +4 -4
  54. package/dist/{test-CaRHj_J6.js.map → test-7q_KJkdX.js.map} +1 -1
  55. package/dist/{tree-BLIxJbD3.js → tree-BMxx5170.js} +522 -436
  56. package/dist/tree-BMxx5170.js.map +1 -0
  57. package/dist/types.d.ts +13 -0
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/webrtc/index.d.ts +76 -0
  60. package/dist/webrtc/index.d.ts.map +1 -0
  61. package/dist/webrtc/index.js +180 -0
  62. package/dist/webrtc/index.js.map +1 -0
  63. package/dist/webrtc/meet-viewer.d.ts +139 -0
  64. package/dist/webrtc/meet-viewer.d.ts.map +1 -0
  65. package/dist/webrtc/meet-viewer.js +379 -0
  66. package/dist/webrtc/meet-viewer.js.map +1 -0
  67. package/dist/webrtc/peer-stream-registry.d.ts +21 -0
  68. package/dist/webrtc/peer-stream-registry.d.ts.map +1 -0
  69. package/dist/webrtc/peer-stream-registry.js +77 -0
  70. package/dist/webrtc/peer-stream-registry.js.map +1 -0
  71. package/package.json +4 -4
  72. package/src/app.tsx +9 -0
  73. package/src/index.ts +35 -0
  74. package/src/mount.ts +11 -0
  75. package/src/overlay/runtime-context.tsx +10 -0
  76. package/src/render/bundle.ts +11 -1
  77. package/src/render/primitives/capture.tsx +73 -28
  78. package/src/render/primitives/index.ts +4 -0
  79. package/src/render/primitives/live-peer-video.tsx +90 -0
  80. package/src/render/primitives/media.tsx +66 -17
  81. package/src/render/primitives/meet-peer.tsx +57 -0
  82. package/src/render/prop-allowlist.ts +27 -1
  83. package/src/render/tree.tsx +44 -8
  84. package/src/types.ts +13 -0
  85. package/src/webrtc/index.ts +252 -0
  86. package/src/webrtc/meet-viewer.ts +497 -0
  87. package/src/webrtc/peer-stream-registry.ts +93 -0
  88. package/dist/index-DrXsLYhe.js +0 -903
  89. package/dist/index-DrXsLYhe.js.map +0 -1
  90. package/dist/tree-BLIxJbD3.js.map +0 -1
@@ -0,0 +1,1281 @@
1
+ import { batch as T, signal as v } from "@preact/signals-react";
2
+ import { createRoot as q } from "react-dom/client";
3
+ import { createContext as te, useContext as W, lazy as E, Suspense as se, createElement as ne, StrictMode as re } from "react";
4
+ import { jsx as m } from "react/jsx-runtime";
5
+ import { useSignals as ie } from "@preact/signals-react/runtime";
6
+ import { AnimatePresence as oe, motion as ae } from "framer-motion";
7
+ import { SequenceTracker as ce, encodeFrame as O, input as le, WS_SUBPROTOCOLS as ue, WS_SUBPROTOCOL_V1_1 as de, subscribe as he, decodeServerFrame as fe, LumencastError as L } from "@lumencast/protocol";
8
+ const I = te(null);
9
+ function z({
10
+ value: t,
11
+ children: e
12
+ }) {
13
+ return /* @__PURE__ */ m(I.Provider, { value: t, children: e });
14
+ }
15
+ function at() {
16
+ const t = W(I);
17
+ if (!t)
18
+ throw new Error(
19
+ "Lumencast overlay components must be rendered inside LumencastRuntimeProvider"
20
+ );
21
+ return t;
22
+ }
23
+ function ct() {
24
+ return W(I);
25
+ }
26
+ const me = E(
27
+ () => import("./broadcast-L5wm2I6J.js").then((t) => ({ default: t.BroadcastMode }))
28
+ ), pe = E(
29
+ () => import("./control-eEUG7unp.js").then((t) => ({ default: t.ControlMode }))
30
+ ), ge = E(() => import("./test-7q_KJkdX.js").then((t) => ({ default: t.TestMode })));
31
+ function ve({
32
+ mode: t,
33
+ store: e,
34
+ bundleSignal: s,
35
+ statusSignal: n,
36
+ crossfadeKeySignal: r,
37
+ sendInput: o,
38
+ resolveCaptureDevice: a,
39
+ resolvePeerStream: i,
40
+ subscribePeerStream: l
41
+ }) {
42
+ ie();
43
+ const c = s.value, d = n.value, h = r.value;
44
+ if (!c) return null;
45
+ const w = t === "broadcast" ? me : t === "control" ? pe : ge;
46
+ return /* @__PURE__ */ m(oe, { mode: "sync", children: /* @__PURE__ */ m(
47
+ ae.div,
48
+ {
49
+ initial: { opacity: 0 },
50
+ animate: { opacity: 1 },
51
+ exit: { opacity: 0 },
52
+ transition: { duration: 0.4, ease: "easeInOut" },
53
+ style: { position: "absolute", inset: 0 },
54
+ children: /* @__PURE__ */ m(
55
+ z,
56
+ {
57
+ value: {
58
+ mode: t,
59
+ store: e,
60
+ bundle: c,
61
+ status: d,
62
+ sendInput: o,
63
+ ...a !== void 0 ? { resolveCaptureDevice: a } : {},
64
+ ...i !== void 0 ? { resolvePeerStream: i } : {},
65
+ ...l !== void 0 ? { subscribePeerStream: l } : {}
66
+ },
67
+ children: /* @__PURE__ */ m(se, { fallback: null, children: /* @__PURE__ */ m(w, {}) })
68
+ }
69
+ )
70
+ },
71
+ h
72
+ ) });
73
+ }
74
+ const we = "<anon>", b = /* @__PURE__ */ new Set();
75
+ function B(t) {
76
+ return b.add(t), () => {
77
+ b.delete(t);
78
+ };
79
+ }
80
+ function H(t, e, s) {
81
+ const n = { nodeId: t ?? we, field: e, reason: s };
82
+ if (b.size > 0) {
83
+ for (const r of b)
84
+ try {
85
+ r(n);
86
+ } catch {
87
+ }
88
+ return;
89
+ }
90
+ }
91
+ const ye = 100, be = 4, ke = 64, Se = {
92
+ blur: ye,
93
+ brightness: be
94
+ };
95
+ function M(t, e) {
96
+ if (typeof e != "number" || !Number.isFinite(e) || e < 0 || Object.is(e, -0)) return null;
97
+ const s = Se[t];
98
+ return e > s ? s : e;
99
+ }
100
+ const Te = /^blur\((\d{1,7}(?:\.\d{1,4})?)px\) brightness\((\d{1,7}(?:\.\d{1,4})?)\)$/, lt = "blur(0px) brightness(1)";
101
+ function Ee(t) {
102
+ if (typeof t != "string" || t.length === 0 || t.length > ke) return null;
103
+ const e = Te.exec(t);
104
+ if (!e) return null;
105
+ const s = M("blur", Number(e[1])), n = M("brightness", Number(e[2]));
106
+ return s === null || n === null ? null : `blur(${s}px) brightness(${n})`;
107
+ }
108
+ function Ie(t, e) {
109
+ H(
110
+ e,
111
+ t,
112
+ "rejected unsafe filter value : outside the R8 caps or not a finite number >= 0"
113
+ );
114
+ }
115
+ const _e = { duration: 0 }, Re = {
116
+ linear: "linear",
117
+ "cubic-in": "easeIn",
118
+ "cubic-out": "easeOut",
119
+ "cubic-in-out": "easeInOut"
120
+ };
121
+ function ut(t) {
122
+ return !t || t.kind === "none" ? _e : t.kind === "tween" ? {
123
+ type: "tween",
124
+ duration: (t.duration_ms ?? 0) / 1e3,
125
+ ease: t.ease ? Re[t.ease] ?? "easeOut" : "easeOut"
126
+ } : t.kind === "spring" ? {
127
+ type: "spring",
128
+ ...t.stiffness !== void 0 ? { stiffness: t.stiffness } : {},
129
+ ...t.damping !== void 0 ? { damping: t.damping } : {},
130
+ ...t.mass !== void 0 ? { mass: t.mass } : {}
131
+ } : {
132
+ type: "tween",
133
+ duration: (t.duration_ms ?? 400) / 1e3,
134
+ ease: "easeInOut"
135
+ };
136
+ }
137
+ const Ae = {
138
+ opacity: 1,
139
+ scale: 1,
140
+ scaleX: 1,
141
+ scaleY: 1,
142
+ rotate: 0,
143
+ x: 0,
144
+ y: 0,
145
+ // LSML §6.1 filter identity — both functions are always present so
146
+ // framer interpolates between structurally-identical filter lists
147
+ // (the compiler emits the same two-function form, clamped per R8).
148
+ filter: "blur(0px) brightness(1)"
149
+ }, Pe = {
150
+ kind: "tween",
151
+ duration_ms: 400,
152
+ ease: "cubic-out"
153
+ };
154
+ function dt(t, e, s) {
155
+ for (const n of e) {
156
+ const r = t(n);
157
+ if (r !== void 0) return r;
158
+ }
159
+ if (s && Object.keys(s).length > 0) {
160
+ for (const n of Object.keys(s)) {
161
+ const r = t(n);
162
+ if (r !== void 0) return r;
163
+ }
164
+ return Pe;
165
+ }
166
+ }
167
+ function ht(t, e, s) {
168
+ if (!e || Object.keys(e).length === 0)
169
+ return { initial: t, animate: t };
170
+ let n = e;
171
+ if (e.filter !== void 0) {
172
+ const o = Ee(e.filter);
173
+ n = { ...e }, o === null ? (Ie("animate_initial.filter", s), delete n.filter) : n.filter = o;
174
+ }
175
+ const r = { ...t };
176
+ for (const o of Object.keys(n))
177
+ o in r || (r[o] = Ae[o] ?? 0);
178
+ return { initial: n, animate: r };
179
+ }
180
+ function Oe(t) {
181
+ if (typeof t != "object" || t === null) return;
182
+ const e = t, s = e.kind;
183
+ if (s === "snap")
184
+ return { kind: "none" };
185
+ if (s === "tween") {
186
+ const n = typeof e.duration_ms == "number" ? e.duration_ms : 0, r = Le[e.easing] ?? "cubic-out";
187
+ return { kind: "tween", duration_ms: n, ease: r };
188
+ }
189
+ if (s === "spring") {
190
+ const n = { kind: "spring" };
191
+ return typeof e.stiffness == "number" && (n.stiffness = e.stiffness), typeof e.damping == "number" && (n.damping = e.damping), typeof e.mass == "number" && (n.mass = e.mass), n;
192
+ }
193
+ }
194
+ const Le = {
195
+ linear: "linear",
196
+ "ease-in": "cubic-in",
197
+ "ease-out": "cubic-out",
198
+ "ease-in-out": "cubic-in-out"
199
+ };
200
+ function Me(t, e) {
201
+ T(() => {
202
+ for (const s of e.patches) {
203
+ const n = Oe(s.transition);
204
+ n !== void 0 ? t.setWithTransition(s.path, s.value, n) : t.set(s.path, s.value);
205
+ }
206
+ });
207
+ }
208
+ function Ce(t, e) {
209
+ t.reset(e.state);
210
+ }
211
+ class Ne {
212
+ signals = /* @__PURE__ */ new Map();
213
+ transitions = /* @__PURE__ */ new Map();
214
+ signal(e) {
215
+ let s = this.signals.get(e);
216
+ return s || (s = v(void 0), this.signals.set(e, s)), s;
217
+ }
218
+ transitionSignal(e) {
219
+ let s = this.transitions.get(e);
220
+ return s || (s = v(void 0), this.transitions.set(e, s)), s;
221
+ }
222
+ set(e, s) {
223
+ const n = this.signal(e);
224
+ S(n.peek(), s) || (n.value = s);
225
+ }
226
+ setWithTransition(e, s, n) {
227
+ T(() => {
228
+ const r = this.transitionSignal(e);
229
+ r.peek() !== n && (r.value = n);
230
+ const o = this.signal(e);
231
+ S(o.peek(), s) || (o.value = s);
232
+ });
233
+ }
234
+ reset(e) {
235
+ T(() => {
236
+ const s = /* @__PURE__ */ new Set();
237
+ for (const [n, r] of Object.entries(e)) {
238
+ s.add(n);
239
+ const o = this.signal(n);
240
+ S(o.peek(), r) || (o.value = r);
241
+ const a = this.transitions.get(n);
242
+ a && a.peek() !== void 0 && (a.value = void 0);
243
+ }
244
+ for (const n of this.signals.keys())
245
+ if (!s.has(n)) {
246
+ const r = this.signals.get(n);
247
+ r && r.peek() !== void 0 && (r.value = void 0);
248
+ }
249
+ });
250
+ }
251
+ toRecord() {
252
+ const e = {};
253
+ for (const [s, n] of this.signals.entries())
254
+ e[s] = n.peek();
255
+ return e;
256
+ }
257
+ }
258
+ function G() {
259
+ return new Ne();
260
+ }
261
+ function S(t, e) {
262
+ if (t === e) return !0;
263
+ if (t === null || e === null || typeof t != typeof e || typeof t != "object" || Array.isArray(t) !== Array.isArray(e)) return !1;
264
+ if (Array.isArray(t) && Array.isArray(e)) {
265
+ if (t.length !== e.length) return !1;
266
+ for (let a = 0; a < t.length; a++)
267
+ if (t[a] !== e[a]) return !1;
268
+ return !0;
269
+ }
270
+ const s = t, n = e, r = Object.keys(s), o = Object.keys(n);
271
+ if (r.length !== o.length) return !1;
272
+ for (const a of r)
273
+ if (s[a] !== n[a]) return !1;
274
+ return !0;
275
+ }
276
+ const xe = /* @__PURE__ */ new Set([
277
+ "x-lumencast.color-srgb-1.0",
278
+ // RFC-0001 / ADR 004 — this runtime ships the Zab capture plugin, so a
279
+ // bundle declaring `x-zab.capture/1` in `profiles[]` is compatible (it is
280
+ // NOT rejected as BUNDLE_INCOMPATIBLE, §17.3.1).
281
+ "x-zab.capture/1"
282
+ ]), je = /^x-[a-z0-9-]+(?:\.[a-z0-9-]+)*$/, De = /^(?:0|[1-9][0-9]*)$/, C = ".authoring";
283
+ function Ue(t) {
284
+ const e = t.indexOf("/");
285
+ if (e < 0) return !1;
286
+ const s = t.slice(0, e), n = t.slice(e + 1);
287
+ return !De.test(n) || !s.endsWith(C) ? !1 : je.test(s.slice(0, -C.length));
288
+ }
289
+ class N extends Error {
290
+ code = "BUNDLE_INCOMPATIBLE";
291
+ unsupportedProfiles;
292
+ constructor(e) {
293
+ super(
294
+ `BUNDLE_INCOMPATIBLE: profile(s) not supported by this runtime: ${e.join(
295
+ ", "
296
+ )}`
297
+ ), this.name = "BundleIncompatibleError", this.unsupportedProfiles = e;
298
+ }
299
+ }
300
+ function x(t, e = xe) {
301
+ const s = t.profiles;
302
+ if (!s) return;
303
+ if (!Array.isArray(s))
304
+ throw new N(["<malformed: profiles is not an array>"]);
305
+ if (s.length === 0) return;
306
+ const n = s.filter((r) => typeof r != "string" || !Ue(r) && !e.has(r)).map((r) => typeof r == "string" ? r : "<malformed: non-string profile entry>");
307
+ if (n.length > 0)
308
+ throw new N(n);
309
+ }
310
+ class $e {
311
+ cache = /* @__PURE__ */ new Map();
312
+ baseUrl;
313
+ pathPrefix;
314
+ resolveUrl;
315
+ getAuthToken;
316
+ fetchImpl;
317
+ constructor(e) {
318
+ this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.pathPrefix = (e.pathPrefix ?? "/lsdp/v1/scenes").replace(/\/$/, ""), this.resolveUrl = e.resolveUrl, this.getAuthToken = e.getAuthToken, this.fetchImpl = e.fetchImpl ?? globalThis.fetch.bind(globalThis);
319
+ }
320
+ /** Build the request init carrying the bearer token, if any. Returns
321
+ * `undefined` when no token is available — the fetch stays header-less,
322
+ * preserving v0.5.0 behaviour. */
323
+ async buildInit() {
324
+ if (!this.getAuthToken) return;
325
+ const e = await this.getAuthToken();
326
+ if (e)
327
+ return { headers: { Authorization: `Bearer ${e}` } };
328
+ }
329
+ buildUrl(e, s) {
330
+ return this.resolveUrl ? this.resolveUrl(e, s) : `${this.baseUrl}${this.pathPrefix}/${encodeURIComponent(e)}/bundle?v=${encodeURIComponent(s)}`;
331
+ }
332
+ preload(e) {
333
+ x(e), this.cache.set(e.scene_version, e);
334
+ }
335
+ async get(e, s) {
336
+ const n = this.cache.get(s);
337
+ if (n) return n;
338
+ const r = this.buildUrl(e, s), o = await this.buildInit(), a = o ? await this.fetchImpl(r, o) : await this.fetchImpl(r);
339
+ if (!a.ok)
340
+ throw new Error(`bundle fetch failed: ${a.status} ${a.statusText}`);
341
+ const i = await a.json();
342
+ if (i.scene_version !== s)
343
+ throw new Error(
344
+ `bundle scene_version mismatch: expected ${s}, got ${i.scene_version}`
345
+ );
346
+ return x(i), this.cache.set(s, i), i;
347
+ }
348
+ }
349
+ function Fe(t) {
350
+ return new $e(t);
351
+ }
352
+ const y = {
353
+ initial: 200,
354
+ max: 5e3,
355
+ factor: 2,
356
+ jitter: 0.2
357
+ };
358
+ class qe {
359
+ constructor(e, s) {
360
+ this.opts = e, this.random = s;
361
+ }
362
+ _attempt = 0;
363
+ get attempt() {
364
+ return this._attempt;
365
+ }
366
+ delayFor(e) {
367
+ if (!Number.isInteger(e) || e < 1)
368
+ throw new RangeError(`attempt must be a positive integer, got ${e}`);
369
+ this._attempt = e;
370
+ const s = Math.min(
371
+ this.opts.initial * Math.pow(this.opts.factor, e - 1),
372
+ this.opts.max
373
+ );
374
+ if (this.opts.jitter <= 0) return s;
375
+ const n = (this.random() * 2 - 1) * this.opts.jitter * s;
376
+ return Math.max(0, s + n);
377
+ }
378
+ reset() {
379
+ this._attempt = 0;
380
+ }
381
+ }
382
+ function We(t = {}) {
383
+ const e = {
384
+ initial: t.initial ?? y.initial,
385
+ max: t.max ?? y.max,
386
+ factor: t.factor ?? y.factor,
387
+ jitter: t.jitter ?? y.jitter
388
+ };
389
+ if (e.initial <= 0) throw new RangeError("initial must be > 0");
390
+ if (e.max < e.initial) throw new RangeError("max must be >= initial");
391
+ if (e.factor < 1) throw new RangeError("factor must be >= 1");
392
+ if (e.jitter < 0 || e.jitter > 1) throw new RangeError("jitter must be within [0, 1]");
393
+ return new qe(e, t.random ?? Math.random);
394
+ }
395
+ class p extends Error {
396
+ recoverable;
397
+ code;
398
+ cause;
399
+ constructor(e, s, n = "INTERNAL", r) {
400
+ super(e), this.name = "TransportError", this.recoverable = s, this.code = n, this.cause = r;
401
+ }
402
+ }
403
+ class ze {
404
+ status = "disconnected";
405
+ socket = null;
406
+ token;
407
+ url;
408
+ WebSocketCtor;
409
+ schedule;
410
+ seq = new ce();
411
+ opts;
412
+ scheduler;
413
+ reconnectTimer = null;
414
+ active = !0;
415
+ constructor(e) {
416
+ this.opts = e, this.url = e.url, this.token = e.token;
417
+ const s = e.webSocketImpl ?? globalThis.WebSocket;
418
+ if (!s)
419
+ throw new TypeError(
420
+ "Lumencast WsClient: no WebSocket implementation found in this environment"
421
+ );
422
+ this.WebSocketCtor = s, this.schedule = We(e.reconnect), this.scheduler = e.scheduler ?? {
423
+ setTimeout: globalThis.setTimeout.bind(globalThis),
424
+ clearTimeout: globalThis.clearTimeout.bind(globalThis)
425
+ };
426
+ }
427
+ /** Open and start the connection lifecycle. Idempotent. */
428
+ start() {
429
+ this.active && (this.socket || this.status === "connecting" || this.openSocket());
430
+ }
431
+ /** Resolve the current session token (the one used for the WS
432
+ * subscription). Mirrors `setToken` swaps. Used by the bundle fetcher to
433
+ * authenticate the render-bundle GET with the same credential. A
434
+ * `LumencastTokenProvider` is awaited. */
435
+ resolveCurrentToken() {
436
+ return j(this.token);
437
+ }
438
+ /** Send `input` patches to the server. No-op if not connected. */
439
+ sendInput(e) {
440
+ !this.socket || this.socket.readyState !== this.WebSocketCtor.OPEN || e.length !== 0 && this.socket.send(O(le(e)));
441
+ }
442
+ /** Replace the auth token. Closes and reopens with the new token. */
443
+ setToken(e) {
444
+ this.token = e, this.active && this.socket && (this.closeSocket(), this.scheduleReconnect(!0));
445
+ }
446
+ /** Tear down for good. No more reconnect attempts. */
447
+ close() {
448
+ this.active && (this.active = !1, this.cancelReconnect(), this.closeSocket(), this.setStatus("disconnected"));
449
+ }
450
+ // --- internals --------------------------------------------------
451
+ async openSocket() {
452
+ if (!this.active) return;
453
+ this.setStatus("connecting");
454
+ let e;
455
+ try {
456
+ e = await j(this.token);
457
+ } catch (n) {
458
+ this.opts.onTransportError?.(
459
+ new p(
460
+ `failed to resolve token: ${n.message}`,
461
+ !0,
462
+ "AUTH_DENIED",
463
+ n
464
+ )
465
+ ), this.scheduleReconnect();
466
+ return;
467
+ }
468
+ if (!this.active) return;
469
+ let s;
470
+ try {
471
+ s = new this.WebSocketCtor(this.url, [...ue]);
472
+ } catch (n) {
473
+ this.opts.onTransportError?.(
474
+ new p(
475
+ `failed to open WebSocket: ${n.message}`,
476
+ !0,
477
+ "INTERNAL",
478
+ n
479
+ )
480
+ ), this.scheduleReconnect();
481
+ return;
482
+ }
483
+ this.socket = s, s.onopen = () => this.handleOpen(e), s.onmessage = (n) => this.handleMessage(n), s.onerror = (n) => this.handleError(n), s.onclose = (n) => this.handleClose(n);
484
+ }
485
+ handleOpen(e) {
486
+ if (!this.socket) return;
487
+ const n = this.socket.protocol === de && this.seq.last > 0, r = n ? this.seq.last : void 0;
488
+ n || this.seq.reset();
489
+ const o = he({
490
+ token: e,
491
+ ...this.opts.scene !== void 0 ? { scene: this.opts.scene } : {},
492
+ ...this.opts.session !== void 0 ? { session: this.opts.session } : {},
493
+ ...r !== void 0 ? { since_sequence: r } : {}
494
+ });
495
+ this.socket.send(O(o));
496
+ }
497
+ handleMessage(e) {
498
+ const s = typeof e.data == "string" ? e.data : "";
499
+ if (!s) return;
500
+ let n;
501
+ try {
502
+ n = fe(s);
503
+ } catch (r) {
504
+ const o = (r instanceof L, r.message), a = r instanceof L ? r.code : "INTERNAL";
505
+ this.opts.onTransportError?.(new p(`codec: ${o}`, !0, a, r)), this.closeSocket(), this.scheduleReconnect();
506
+ return;
507
+ }
508
+ if (n !== null)
509
+ switch (n.type) {
510
+ case "snapshot": {
511
+ if (n.seq < 1) {
512
+ this.opts.onTransportError?.(
513
+ new p(`snapshot seq must be >= 1, got ${n.seq}`, !0, "VERSION_GAP")
514
+ ), this.closeSocket(), this.scheduleReconnect();
515
+ return;
516
+ }
517
+ this.seq.observeSnapshot(n.seq), this.schedule.reset(), this.setStatus("live"), this.opts.onSnapshot?.(n);
518
+ return;
519
+ }
520
+ case "delta": {
521
+ const r = this.seq.observe(n.seq);
522
+ if (r.kind === "gap") {
523
+ this.opts.onTransportError?.(
524
+ new p(
525
+ `sequence gap: expected ${this.seq.last + 1}, got ${n.seq}`,
526
+ !0,
527
+ "VERSION_GAP"
528
+ )
529
+ ), this.closeSocket(), this.scheduleReconnect();
530
+ return;
531
+ }
532
+ if (r.kind === "duplicate") return;
533
+ this.opts.onDelta?.(n);
534
+ return;
535
+ }
536
+ case "scene_changed": {
537
+ this.seq.reset(), this.opts.onSceneChanged?.(n);
538
+ return;
539
+ }
540
+ case "error": {
541
+ this.opts.onServerError?.(n), n.recoverable || this.close();
542
+ return;
543
+ }
544
+ case "pong":
545
+ return;
546
+ }
547
+ }
548
+ handleError(e) {
549
+ }
550
+ handleClose(e) {
551
+ if (this.socket = null, !this.active) {
552
+ this.setStatus("disconnected");
553
+ return;
554
+ }
555
+ if (e.code === 4401 || e.code === 4403 || e.code === 1008) {
556
+ this.opts.onTransportError?.(
557
+ new p(`server closed: ${e.code} ${e.reason}`, !1, "AUTH_DENIED")
558
+ ), this.close();
559
+ return;
560
+ }
561
+ this.scheduleReconnect();
562
+ }
563
+ scheduleReconnect(e = !1) {
564
+ if (!this.active) return;
565
+ this.cancelReconnect();
566
+ const s = (this.schedule.attempt || 0) + 1, n = e ? 0 : this.schedule.delayFor(s);
567
+ this.setStatus("disconnected"), this.reconnectTimer = this.scheduler.setTimeout(() => {
568
+ this.reconnectTimer = null, this.openSocket();
569
+ }, n);
570
+ }
571
+ cancelReconnect() {
572
+ this.reconnectTimer && (this.scheduler.clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
573
+ }
574
+ closeSocket() {
575
+ if (this.socket) {
576
+ try {
577
+ this.socket.close(1e3, "client closing");
578
+ } catch {
579
+ }
580
+ this.socket = null;
581
+ }
582
+ }
583
+ setStatus(e) {
584
+ this.status !== e && (this.status = e, this.opts.onStatus?.(e));
585
+ }
586
+ }
587
+ async function j(t) {
588
+ return typeof t == "string" ? t : await t.fetch();
589
+ }
590
+ function Be(t) {
591
+ if (!(t.target instanceof HTMLElement))
592
+ throw new TypeError("mount: `target` must be an HTMLElement");
593
+ if (typeof t.serverUrl != "string" || t.serverUrl.length === 0)
594
+ throw new TypeError("mount: `serverUrl` must be a non-empty string");
595
+ if (t.mode === "test") {
596
+ if (!t.testSession)
597
+ throw new TypeError("mount: `testSession` is required when mode === 'test'");
598
+ if (!t.scene)
599
+ throw new TypeError("mount: `scene` is required when mode === 'test'");
600
+ }
601
+ }
602
+ function ft(t) {
603
+ Be(t), t.onStatus?.("disconnected");
604
+ const e = G(), s = Ge(t.serverUrl), n = Fe({
605
+ baseUrl: s,
606
+ ...t.resolveBundleUrl !== void 0 ? { resolveUrl: t.resolveBundleUrl } : {},
607
+ getAuthToken: () => h.resolveCurrentToken()
608
+ }), r = v(null), o = v("disconnected"), a = v("__initial__"), i = (u) => {
609
+ o.value = u, t.onStatus?.(u);
610
+ }, l = (u) => {
611
+ t.onError?.(u);
612
+ };
613
+ let c = !0;
614
+ const d = t.onDiagnostic ? B(t.onDiagnostic) : void 0, h = new ze({
615
+ url: t.serverUrl,
616
+ token: t.token,
617
+ ...t.scene !== void 0 ? { scene: t.scene } : {},
618
+ ...t.testSession !== void 0 ? { session: t.testSession } : {},
619
+ onStatus: i,
620
+ onSnapshot: (u) => {
621
+ c && (J(
622
+ n,
623
+ r,
624
+ a,
625
+ u.scene_id,
626
+ u.scene_version,
627
+ () => Ce(e, u),
628
+ l
629
+ ), t.onMetric?.({
630
+ name: "snapshot_received",
631
+ scene_id: u.scene_id,
632
+ path_count: Object.keys(u.state).length
633
+ }));
634
+ },
635
+ onDelta: (u) => {
636
+ if (!c) return;
637
+ const k = performance.now();
638
+ Me(e, u), t.onMetric?.({
639
+ name: "delta_applied",
640
+ duration_ms: performance.now() - k
641
+ }), t.onMetric?.({ name: "delta_received", count: 1, path_count: u.patches.length });
642
+ },
643
+ onSceneChanged: (u) => {
644
+ c && t.onMetric?.({
645
+ name: "scene_changed",
646
+ from: r.value?.scene_version ?? null,
647
+ to: u.scene_version
648
+ });
649
+ },
650
+ onServerError: (u) => {
651
+ l({
652
+ code: u.code,
653
+ message: u.message,
654
+ recoverable: u.recoverable
655
+ });
656
+ },
657
+ onTransportError: (u) => {
658
+ l(He(u));
659
+ }
660
+ });
661
+ h.start();
662
+ const w = q(t.target);
663
+ return w.render(
664
+ ne(ve, {
665
+ mode: t.mode,
666
+ store: e,
667
+ bundleSignal: r,
668
+ statusSignal: o,
669
+ crossfadeKeySignal: a,
670
+ sendInput: (u) => h.sendInput(u),
671
+ // ADR 004 §A1.3 — thread the host capture resolver to the runtime context
672
+ // so the `x-zab.capture` primitive's ACQUIRE mode can pin a device.
673
+ ...t.resolveCaptureDevice !== void 0 ? { resolveCaptureDevice: t.resolveCaptureDevice } : {},
674
+ // ADR 006 #4 — thread the host peer-stream resolver (supplied by the
675
+ // WebRTC viewer #3) so the `media` primitive's LIVE mode can render a
676
+ // peer's MediaStream in `srcObject`.
677
+ ...t.resolvePeerStream !== void 0 ? { resolvePeerStream: t.resolvePeerStream } : {},
678
+ // ADR 006 #3 — reactive variant : the LIVE `media` node re-renders when a
679
+ // peer connects/leaves mid-show. `createPeerViewer()` supplies it.
680
+ ...t.subscribePeerStream !== void 0 ? { subscribePeerStream: t.subscribePeerStream } : {}
681
+ })
682
+ ), {
683
+ disconnect() {
684
+ c && (c = !1, d?.(), h.close(), w.unmount());
685
+ },
686
+ setToken(u) {
687
+ c && h.setToken(u);
688
+ }
689
+ };
690
+ async function J(u, k, Z, _, R, Q, ee) {
691
+ let A;
692
+ try {
693
+ A = await u.get(_, R);
694
+ } catch (P) {
695
+ ee({
696
+ code: "BUNDLE_FETCH_FAILED",
697
+ message: P instanceof Error ? P.message : "render bundle fetch failed",
698
+ recoverable: !0
699
+ });
700
+ return;
701
+ }
702
+ c && (Q(), k.value = A, Z.value = `${_}::${R}`);
703
+ }
704
+ }
705
+ function He(t) {
706
+ return {
707
+ code: t.code,
708
+ message: t.message,
709
+ recoverable: t.recoverable
710
+ };
711
+ }
712
+ function Ge(t) {
713
+ try {
714
+ const e = new URL(t);
715
+ return `${e.protocol === "wss:" ? "https:" : "http:"}//${e.host}`;
716
+ } catch {
717
+ return "";
718
+ }
719
+ }
720
+ const Ke = [
721
+ "visible",
722
+ "opacity",
723
+ "universal_opacity",
724
+ "rotation",
725
+ "sizing",
726
+ "x",
727
+ "y",
728
+ "width",
729
+ "height",
730
+ // ADR 002 §3.2 (D2 / #D) — `blendMode` is consumed universally by the
731
+ // wrapper (→ CSS `mix-blend-mode`) on every primitive.
732
+ "blendMode",
733
+ // ADR 002 §3.2 (#E) — a typed `mask` is lowered onto EVERY primitive by the
734
+ // compiler and consumed by the Tree (built into a `<mask>` SVG element).
735
+ "mask"
736
+ ];
737
+ function f(t) {
738
+ return /* @__PURE__ */ new Set([...Ke, ...t]);
739
+ }
740
+ const Xe = {
741
+ stack: f(["direction", "gap", "wrap", "crossGap", "align", "justify"]),
742
+ grid: f(["cols", "rows", "gap"]),
743
+ frame: f([
744
+ "x",
745
+ "y",
746
+ "width",
747
+ "height",
748
+ "scale",
749
+ "rotate",
750
+ "background",
751
+ "backgrounds",
752
+ "clipsContent"
753
+ ]),
754
+ text: f([
755
+ "value",
756
+ "size",
757
+ "font",
758
+ "weight",
759
+ "colour",
760
+ "align",
761
+ "lineHeight",
762
+ "letterSpacing",
763
+ "textTransform",
764
+ "textDecoration",
765
+ "fontStyle",
766
+ "maxLines"
767
+ ]),
768
+ image: f(["src", "alt", "fit", "position", "width", "height"]),
769
+ shape: f([
770
+ "geometry",
771
+ "kind",
772
+ "width",
773
+ "height",
774
+ "radius",
775
+ "fill",
776
+ "fills",
777
+ "stroke",
778
+ "stroke_width",
779
+ "strokes",
780
+ "pathData",
781
+ "paths",
782
+ "ariaLabel"
783
+ ]),
784
+ // `peerLabel` (ADR 006 #4) selects the live MediaStream mode : a node whose
785
+ // source is a `meet.peer.peer_label` is rendered in `srcObject` from a host
786
+ // resolver instead of `<video src>`. Listed so it is NOT flagged as a silent
787
+ // drop by the anti-drop audit when a scene carries a live source.
788
+ media: f(["src", "peerLabel", "loop", "mute", "autoplay", "fit"]),
789
+ // ADR 006 §3.3/§3.5 — the unified source kind. `peer_label` is the stream
790
+ // reference (resolved to a MediaStream → srcObject) ; `object_fit`/`muted`
791
+ // drive the video ; `x-zab.sourceKind` is advisory ; `metadata` carries the
792
+ // editor round-trip (figma). Geometry is universal as flat `x/y/width/height`,
793
+ // but an UNCOMPILED from-scene node carries the NESTED `position`/`size` shape
794
+ // (the Tree flattens it as a fallback) — listed so neither form is flagged as
795
+ // a silent drop by the anti-drop audit.
796
+ "meet.peer": f([
797
+ "peer_label",
798
+ "object_fit",
799
+ "muted",
800
+ "x-zab.sourceKind",
801
+ "metadata",
802
+ "position",
803
+ "size"
804
+ ]),
805
+ instance: f(["scene_id", "scene_version", "size", "position"]),
806
+ // RFC-0001 / ADR 004 — vendor capture placeholder. `width`/`height` are the
807
+ // flattened geometry (universal) ; the `x-zab.*` props are carried as
808
+ // metadata (the renderer reserves the box, ignores deviceRef). Listed so
809
+ // they are NOT flagged as silent drops by the anti-drop audit.
810
+ "x-zab.capture": f(["x-zab.sourceKind", "x-zab.deviceRef", "width", "height"]),
811
+ // ADR Blue 009 §3.1 (Amendment 2) — vendor meet-peer SLOT placeholder.
812
+ // `width`/`height` are the flattened geometry (universal) ; `x-zab.slotRef`
813
+ // is the logical slot identity carried as metadata (the runtime resolves
814
+ // `slotRef → peer_label` from stream-level ZabCam state). NO cam/peer
815
+ // identity is carried. Listed so they are NOT flagged as silent drops.
816
+ "x-zab.meet-peer": f(["x-zab.slotRef", "width", "height"]),
817
+ // `repeat` is dispatched specially by the tree ; its only consumed
818
+ // binding is `items`.
819
+ repeat: /* @__PURE__ */ new Set(["items"])
820
+ };
821
+ function Ve(t, e) {
822
+ const s = Xe[t];
823
+ return !!(s === void 0 || s.has(e) || t === "instance" && (e === "params" || e.startsWith("params.")));
824
+ }
825
+ const D = /* @__PURE__ */ new WeakSet();
826
+ function mt(t) {
827
+ if (D.has(t)) return;
828
+ D.add(t);
829
+ const e = /* @__PURE__ */ new Set([
830
+ ...Object.keys(t.props ?? {}),
831
+ ...Object.keys(t.bindings ?? {})
832
+ ]);
833
+ for (const s of e)
834
+ Ve(t.kind, s) || H(
835
+ t.id,
836
+ `${t.kind}.${s}`,
837
+ "is not consumed by this primitive's renderer ; the prop is ignored (anti-silent-drop, ADR 001 §3.4)"
838
+ );
839
+ }
840
+ class K {
841
+ constructor(e) {
842
+ this.options = e, this.deps = {
843
+ WebSocket: e.deps?.WebSocket ?? globalThis.WebSocket,
844
+ RTCPeerConnection: e.deps?.RTCPeerConnection ?? globalThis.RTCPeerConnection,
845
+ MediaStream: e.deps?.MediaStream ?? globalThis.MediaStream
846
+ };
847
+ }
848
+ ws = null;
849
+ remotes = /* @__PURE__ */ new Map();
850
+ iceServers = [];
851
+ selfId = null;
852
+ listeners = /* @__PURE__ */ new Map();
853
+ deps;
854
+ on(e, s) {
855
+ const n = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
856
+ return this.listeners.set(e, n), n.add(s), () => n.delete(s);
857
+ }
858
+ /** Join the room as a VIEWER (recvonly). No capture, no publish. */
859
+ join() {
860
+ return this.openSocket();
861
+ }
862
+ /** Leave and tear down every peer connection + aggregated stream. As the
863
+ * track owner, this is where the streams (and the device-side tracks) end. */
864
+ leave() {
865
+ this.send({ type: "leave" }), this.ws?.close(1e3, "viewer-leave");
866
+ }
867
+ /* ---- Socket ------------------------------------------------------- */
868
+ openSocket() {
869
+ const e = new URL(this.options.signalingUrl);
870
+ return e.searchParams.set("room", this.options.roomId), e.searchParams.set("token", this.options.token), new Promise((s, n) => {
871
+ const r = new this.deps.WebSocket(e.toString());
872
+ this.ws = r;
873
+ const o = () => {
874
+ r.removeEventListener("error", a), this.send({ type: "join", name: this.options.name, role: "viewer" }), s();
875
+ }, a = (i) => {
876
+ r.removeEventListener("open", o), n(i);
877
+ };
878
+ r.addEventListener("open", o, { once: !0 }), r.addEventListener("error", a, { once: !0 }), r.addEventListener("message", (i) => void this.onMessage(i.data)), r.addEventListener("close", (i) => {
879
+ this.tearDown(), this.emit("close", { code: i.code, reason: i.reason });
880
+ });
881
+ });
882
+ }
883
+ send(e) {
884
+ this.ws && this.ws.readyState === this.deps.WebSocket.OPEN && this.ws.send(JSON.stringify(e));
885
+ }
886
+ tearDown() {
887
+ for (const e of this.remotes.values()) e.pc.close();
888
+ this.remotes.clear();
889
+ }
890
+ /* ---- Protocol ----------------------------------------------------- */
891
+ async onMessage(e) {
892
+ let s;
893
+ try {
894
+ s = JSON.parse(String(e));
895
+ } catch {
896
+ return;
897
+ }
898
+ switch (s.type) {
899
+ case "joined": {
900
+ this.selfId = s.peerId, this.iceServers = s.turn.urls.map((n) => ({
901
+ urls: n,
902
+ username: s.turn.username,
903
+ credential: s.turn.credential
904
+ })), this.emit("joined", { peerId: s.peerId, peers: s.peers });
905
+ for (const n of s.peers) this.ensureRemote(n);
906
+ break;
907
+ }
908
+ case "peer-joined": {
909
+ this.emit("peer-joined", s.peer), this.ensureRemote(s.peer);
910
+ break;
911
+ }
912
+ case "peer-left": {
913
+ const n = this.remotes.get(s.peerId);
914
+ n && (n.pc.close(), this.remotes.delete(s.peerId), this.emit("peer-left", { peerId: s.peerId, peerName: n.info.name }));
915
+ break;
916
+ }
917
+ case "signal": {
918
+ await this.handleSignal(s.from, s.payload);
919
+ break;
920
+ }
921
+ case "error": {
922
+ this.emit("error", { code: s.code, message: s.message });
923
+ break;
924
+ }
925
+ }
926
+ }
927
+ async handleSignal(e, s) {
928
+ let n = this.remotes.get(e);
929
+ n || (n = this.ensureRemote({ id: e, name: e.slice(0, 8), role: "publisher" }));
930
+ const { pc: r } = n;
931
+ if (s.kind === "sdp") {
932
+ const o = s.description, a = o.type === "offer" && (n.makingOffer || r.signalingState !== "stable");
933
+ if (n.ignoreOffer = !this.isPolite(e) && a, n.ignoreOffer) return;
934
+ await r.setRemoteDescription(o);
935
+ for (const i of n.pendingCandidates)
936
+ try {
937
+ await r.addIceCandidate(i);
938
+ } catch {
939
+ }
940
+ n.pendingCandidates = [], o.type === "offer" && (await r.setLocalDescription(), r.localDescription && this.sendSignal(e, {
941
+ kind: "sdp",
942
+ description: {
943
+ type: r.localDescription.type,
944
+ sdp: r.localDescription.sdp
945
+ }
946
+ }));
947
+ return;
948
+ }
949
+ if (s.kind === "ice") {
950
+ const o = s.candidate;
951
+ if (r.remoteDescription)
952
+ try {
953
+ await r.addIceCandidate(o);
954
+ } catch (a) {
955
+ if (!n.ignoreOffer) throw a;
956
+ }
957
+ else
958
+ n.pendingCandidates.push(o);
959
+ return;
960
+ }
961
+ }
962
+ /* ---- Peer setup --------------------------------------------------- */
963
+ ensureRemote(e) {
964
+ const s = this.remotes.get(e.id);
965
+ if (s) return s;
966
+ const n = new this.deps.RTCPeerConnection({
967
+ iceServers: this.iceServers,
968
+ iceTransportPolicy: "relay"
969
+ }), r = new this.deps.MediaStream(), o = n.addTransceiver("audio", { direction: "recvonly" }), a = n.addTransceiver("video", { direction: "recvonly" });
970
+ Ye(o, a);
971
+ const i = {
972
+ info: e,
973
+ pc: n,
974
+ stream: r,
975
+ makingOffer: !1,
976
+ ignoreOffer: !1,
977
+ pendingCandidates: []
978
+ };
979
+ return n.addEventListener("negotiationneeded", () => {
980
+ (async () => {
981
+ try {
982
+ i.makingOffer = !0, await n.setLocalDescription(), n.localDescription && this.sendSignal(e.id, {
983
+ kind: "sdp",
984
+ description: {
985
+ type: n.localDescription.type,
986
+ sdp: n.localDescription.sdp
987
+ }
988
+ });
989
+ } catch {
990
+ } finally {
991
+ i.makingOffer = !1;
992
+ }
993
+ })();
994
+ }), n.addEventListener("icecandidate", (l) => {
995
+ const c = l.candidate;
996
+ c && this.sendSignal(e.id, {
997
+ kind: "ice",
998
+ candidate: {
999
+ candidate: c.candidate,
1000
+ sdpMid: c.sdpMid,
1001
+ sdpMLineIndex: c.sdpMLineIndex,
1002
+ usernameFragment: c.usernameFragment
1003
+ }
1004
+ });
1005
+ }), n.addEventListener("track", (l) => {
1006
+ const c = l.track;
1007
+ i.stream.getTracks().includes(c) || i.stream.addTrack(c), c.addEventListener("ended", () => {
1008
+ i.stream.removeTrack(c);
1009
+ }), this.emit("remote-track", {
1010
+ peerId: e.id,
1011
+ peerName: e.name,
1012
+ stream: i.stream
1013
+ });
1014
+ }), n.addEventListener("connectionstatechange", () => {
1015
+ this.emit("connection-state", { peerId: e.id, state: n.connectionState }), (n.connectionState === "failed" || n.connectionState === "closed") && (this.remotes.delete(e.id), this.emit("peer-left", { peerId: e.id, peerName: e.name }));
1016
+ }), this.remotes.set(e.id, i), i;
1017
+ }
1018
+ /* ---- Helpers ------------------------------------------------------ */
1019
+ isPolite(e) {
1020
+ return this.selfId ? this.selfId > e : !1;
1021
+ }
1022
+ sendSignal(e, s) {
1023
+ this.send({ type: "signal", to: e, payload: s });
1024
+ }
1025
+ emit(e, s) {
1026
+ const n = this.listeners.get(e);
1027
+ if (n)
1028
+ for (const r of n) r(s);
1029
+ }
1030
+ }
1031
+ function Ye(t, e) {
1032
+ const s = globalThis.RTCRtpReceiver?.getCapabilities;
1033
+ typeof s == "function" && (U(e, s("video"), (n) => {
1034
+ const r = n.toLowerCase();
1035
+ return r === "video/h264" || r === "video/rtx";
1036
+ }), U(t, s("audio"), (n) => {
1037
+ const r = n.toLowerCase();
1038
+ return r === "audio/opus" || r === "audio/telephone-event";
1039
+ }));
1040
+ }
1041
+ function U(t, e, s) {
1042
+ const n = t?.setCodecPreferences;
1043
+ if (typeof n != "function" || !e) return;
1044
+ const r = e.codecs.filter((o) => s(o.mimeType));
1045
+ if (r.length !== 0)
1046
+ try {
1047
+ n.call(t, r);
1048
+ } catch {
1049
+ }
1050
+ }
1051
+ function X() {
1052
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
1053
+ function s(n) {
1054
+ const r = e.get(n);
1055
+ if (r === void 0) return;
1056
+ const o = t.get(n) ?? null;
1057
+ for (const a of r) a(o);
1058
+ }
1059
+ return {
1060
+ resolve(n) {
1061
+ return t.get(n) ?? null;
1062
+ },
1063
+ subscribe(n, r) {
1064
+ let o = e.get(n);
1065
+ return o === void 0 && (o = /* @__PURE__ */ new Set(), e.set(n, o)), o.add(r), r(t.get(n) ?? null), () => {
1066
+ const a = e.get(n);
1067
+ a !== void 0 && (a.delete(r), a.size === 0 && e.delete(n));
1068
+ };
1069
+ },
1070
+ set(n, r) {
1071
+ t.get(n) !== r && (t.set(n, r), s(n));
1072
+ },
1073
+ remove(n) {
1074
+ t.has(n) && (t.delete(n), s(n));
1075
+ },
1076
+ clear() {
1077
+ const n = [...t.keys()];
1078
+ t.clear();
1079
+ for (const r of n) s(r);
1080
+ }
1081
+ };
1082
+ }
1083
+ function g(t) {
1084
+ return t.toLowerCase().replace(/[^a-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "");
1085
+ }
1086
+ function V(t, e, s) {
1087
+ t.on("remote-track", (n) => {
1088
+ const r = g(n.peerName);
1089
+ s.acquire(r, t) && e.set(r, n.stream);
1090
+ }), t.on("peer-left", (n) => {
1091
+ const r = g(n.peerName);
1092
+ s.acquire(r, t) && (e.remove(r), s.release(r, t));
1093
+ });
1094
+ }
1095
+ const Je = {
1096
+ acquire: () => !0,
1097
+ release: () => {
1098
+ }
1099
+ };
1100
+ function pt(t) {
1101
+ const e = X(), s = new K(t);
1102
+ return V(s, e, Je), {
1103
+ join: () => s.join(),
1104
+ leave: () => {
1105
+ s.leave(), e.clear();
1106
+ },
1107
+ resolvePeerStream: (n) => e.resolve(g(n)),
1108
+ subscribePeerStream: (n, r) => e.subscribe(g(n), r),
1109
+ registry: e,
1110
+ viewer: s
1111
+ };
1112
+ }
1113
+ function $(t) {
1114
+ const e = X(), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = {
1115
+ acquire: (i, l) => {
1116
+ const c = n.get(i);
1117
+ return c === void 0 ? (n.set(i, l), !0) : c === l;
1118
+ },
1119
+ release: (i, l) => {
1120
+ n.get(i) === l && n.delete(i);
1121
+ }
1122
+ };
1123
+ function o(i) {
1124
+ if (s.has(i.roomId)) return;
1125
+ const l = new K({
1126
+ name: i.name ?? "solar-viewer",
1127
+ ...i,
1128
+ ...t.deps !== void 0 && i.deps === void 0 ? { deps: t.deps } : {}
1129
+ });
1130
+ V(l, e, r), s.set(i.roomId, { viewer: l });
1131
+ }
1132
+ function a(i) {
1133
+ const l = s.get(i);
1134
+ if (l !== void 0) {
1135
+ for (const [c, d] of [...n.entries()])
1136
+ d === l.viewer && (e.remove(c), n.delete(c));
1137
+ l.viewer.leave(), s.delete(i);
1138
+ }
1139
+ }
1140
+ for (const i of t.rooms) o(i);
1141
+ return {
1142
+ join: async () => {
1143
+ await Promise.all([...s.values()].map((i) => i.viewer.join()));
1144
+ },
1145
+ leave: () => {
1146
+ for (const i of [...s.keys()]) a(i);
1147
+ e.clear();
1148
+ },
1149
+ setRooms: async (i) => {
1150
+ const l = new Set(i.map((d) => d.roomId));
1151
+ for (const d of [...s.keys()])
1152
+ l.has(d) || a(d);
1153
+ const c = [];
1154
+ for (const d of i)
1155
+ if (!s.has(d.roomId)) {
1156
+ o(d);
1157
+ const h = s.get(d.roomId);
1158
+ h && c.push(h.viewer);
1159
+ }
1160
+ await Promise.all(c.map((d) => d.join()));
1161
+ },
1162
+ resolvePeerStream: (i) => e.resolve(g(i)),
1163
+ subscribePeerStream: (i, l) => e.subscribe(g(i), l),
1164
+ registry: e
1165
+ };
1166
+ }
1167
+ function gt(t) {
1168
+ if ("rooms" in t && Array.isArray(t.rooms))
1169
+ return $(t);
1170
+ const { name: e, deps: s, ...n } = t;
1171
+ return $({
1172
+ rooms: [{ ...n, ...e !== void 0 ? { name: e } : {} }],
1173
+ ...s !== void 0 ? { deps: s } : {}
1174
+ });
1175
+ }
1176
+ const Ze = { width: 1920, height: 1080 }, Qe = () => {
1177
+ };
1178
+ function vt(t) {
1179
+ const e = t.stage ?? Ze, s = t.target;
1180
+ s.style.position ||= "relative", s.style.width = `${e.width}px`, s.style.height = `${e.height}px`, s.style.overflow = "hidden";
1181
+ const n = t.onDiagnostic ? B(t.onDiagnostic) : void 0, r = G();
1182
+ r.reset(t.defaults ?? {});
1183
+ const o = q(s);
1184
+ return {
1185
+ ready: new Promise((i) => {
1186
+ import("./broadcast-L5wm2I6J.js").then(({ BroadcastMode: l }) => {
1187
+ o.render(
1188
+ /* @__PURE__ */ m(re, { children: /* @__PURE__ */ m(
1189
+ z,
1190
+ {
1191
+ value: {
1192
+ mode: "broadcast",
1193
+ store: r,
1194
+ bundle: t.bundle,
1195
+ status: "live",
1196
+ sendInput: Qe
1197
+ },
1198
+ children: /* @__PURE__ */ m(l, {})
1199
+ }
1200
+ ) })
1201
+ );
1202
+ const c = new Promise((h) => {
1203
+ requestAnimationFrame(() => requestAnimationFrame(() => h()));
1204
+ }), d = typeof document < "u" && document.fonts ? document.fonts.ready.then(() => {
1205
+ }) : Promise.resolve();
1206
+ Promise.all([c, d]).then(() => i());
1207
+ });
1208
+ }),
1209
+ unmount() {
1210
+ n?.(), o.unmount();
1211
+ }
1212
+ };
1213
+ }
1214
+ function Y(t, e) {
1215
+ if (typeof t != "string") return t;
1216
+ if (e[t]) return e[t];
1217
+ const s = /^assets\/([A-Za-z0-9]+)\.[A-Za-z0-9]+$/.exec(t);
1218
+ return s && s[1] !== void 0 && e[s[1]] ? e[s[1]] : t;
1219
+ }
1220
+ function F(t, e) {
1221
+ if (t === null || typeof t != "object") return;
1222
+ if (Array.isArray(t)) {
1223
+ for (const n of t) F(n, e);
1224
+ return;
1225
+ }
1226
+ const s = t;
1227
+ "src" in s && (s.src = Y(s.src, e));
1228
+ for (const n of Object.values(s))
1229
+ n && typeof n == "object" && F(n, e);
1230
+ }
1231
+ function wt(t, e) {
1232
+ const s = { ...t };
1233
+ for (const [n, r] of Object.entries(s))
1234
+ n.startsWith("__lit.image.") && (s[n] = Y(r, e));
1235
+ return s;
1236
+ }
1237
+ async function yt(t) {
1238
+ const e = [];
1239
+ for (const s of t)
1240
+ try {
1241
+ const n = new FontFace(s.family, s.src, {
1242
+ weight: String(s.weight),
1243
+ style: s.style ?? "normal"
1244
+ });
1245
+ await n.load(), document.fonts.add(n), e.push(s.family);
1246
+ } catch {
1247
+ }
1248
+ return e;
1249
+ }
1250
+ export {
1251
+ we as A,
1252
+ N as B,
1253
+ lt as F,
1254
+ K as M,
1255
+ Xe as P,
1256
+ xe as S,
1257
+ ct as a,
1258
+ mt as b,
1259
+ M as c,
1260
+ B as d,
1261
+ H as e,
1262
+ $ as f,
1263
+ X as g,
1264
+ pt as h,
1265
+ gt as i,
1266
+ yt as j,
1267
+ Ue as k,
1268
+ ft as l,
1269
+ ht as m,
1270
+ vt as n,
1271
+ Y as o,
1272
+ wt as p,
1273
+ F as q,
1274
+ dt as r,
1275
+ Ee as s,
1276
+ ut as t,
1277
+ at as u,
1278
+ x as v,
1279
+ Ie as w
1280
+ };
1281
+ //# sourceMappingURL=index-Clrya_9l.js.map