@moq/watch 0.2.13 → 0.2.15

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 (49) hide show
  1. package/README.md +10 -9
  2. package/audio/source.d.ts.map +1 -1
  3. package/broadcast-jtLUfuyL.js +4291 -0
  4. package/broadcast-jtLUfuyL.js.map +1 -0
  5. package/broadcast.d.ts.map +1 -1
  6. package/dom-Yz3UT5ap.js +29 -0
  7. package/dom-Yz3UT5ap.js.map +1 -0
  8. package/element.js +162 -178
  9. package/element.js.map +1 -1
  10. package/index.d.ts +1 -3
  11. package/index.d.ts.map +1 -1
  12. package/index.js +5 -254
  13. package/libav-opus-af-CzuaKpJb.js +252 -0
  14. package/libav-opus-af-CzuaKpJb.js.map +1 -0
  15. package/main-bFFHfuX4.js +1999 -0
  16. package/main-bFFHfuX4.js.map +1 -0
  17. package/package.json +5 -4
  18. package/support/element.js +122 -172
  19. package/support/element.js.map +1 -1
  20. package/support/index.js +52 -53
  21. package/support/index.js.map +1 -1
  22. package/ui/element.js +335 -359
  23. package/ui/element.js.map +1 -1
  24. package/video/source.d.ts.map +1 -1
  25. package/broadcast-CLjMphZS.js +0 -5000
  26. package/broadcast-CLjMphZS.js.map +0 -1
  27. package/chat/index.d.ts +0 -17
  28. package/chat/index.d.ts.map +0 -1
  29. package/chat/message.d.ts +0 -16
  30. package/chat/message.d.ts.map +0 -1
  31. package/chat/typing.d.ts +0 -16
  32. package/chat/typing.d.ts.map +0 -1
  33. package/dom-BsFrLb_F.js +0 -35
  34. package/dom-BsFrLb_F.js.map +0 -1
  35. package/index.js.map +0 -1
  36. package/libav-opus-af-BlMWboA7.js +0 -368
  37. package/libav-opus-af-BlMWboA7.js.map +0 -1
  38. package/location/index.d.ts +0 -17
  39. package/location/index.d.ts.map +0 -1
  40. package/location/peers.d.ts +0 -16
  41. package/location/peers.d.ts.map +0 -1
  42. package/location/window.d.ts +0 -17
  43. package/location/window.d.ts.map +0 -1
  44. package/main-DGBFe0O7.js +0 -2301
  45. package/main-DGBFe0O7.js.map +0 -1
  46. package/preview.d.ts +0 -23
  47. package/preview.d.ts.map +0 -1
  48. package/user.d.ts +0 -17
  49. package/user.d.ts.map +0 -1
@@ -1,5000 +0,0 @@
1
- import * as A from "@moq/net";
2
- import { Time as g, Path as en } from "@moq/net";
3
- import { Signal as h, Effect as E } from "@moq/signals";
4
- function y(t, e, n) {
5
- function s(c, a) {
6
- if (c._zod || Object.defineProperty(c, "_zod", {
7
- value: {
8
- def: a,
9
- constr: o,
10
- traits: /* @__PURE__ */ new Set()
11
- },
12
- enumerable: !1
13
- }), c._zod.traits.has(t))
14
- return;
15
- c._zod.traits.add(t), e(c, a);
16
- const u = o.prototype, l = Object.keys(u);
17
- for (let d = 0; d < l.length; d++) {
18
- const f = l[d];
19
- f in c || (c[f] = u[f].bind(c));
20
- }
21
- }
22
- const i = n?.Parent ?? Object;
23
- class r extends i {
24
- }
25
- Object.defineProperty(r, "name", { value: t });
26
- function o(c) {
27
- var a;
28
- const u = n?.Parent ? new r() : this;
29
- s(u, c), (a = u._zod).deferred ?? (a.deferred = []);
30
- for (const l of u._zod.deferred)
31
- l();
32
- return u;
33
- }
34
- return Object.defineProperty(o, "init", { value: s }), Object.defineProperty(o, Symbol.hasInstance, {
35
- value: (c) => n?.Parent && c instanceof n.Parent ? !0 : c?._zod?.traits?.has(t)
36
- }), Object.defineProperty(o, "name", { value: t }), o;
37
- }
38
- class ee extends Error {
39
- constructor() {
40
- super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
41
- }
42
- }
43
- class tn extends Error {
44
- constructor(e) {
45
- super(`Encountered unidirectional transform during encode: ${e}`), this.name = "ZodEncodeError";
46
- }
47
- }
48
- const nn = {};
49
- function ie(t) {
50
- return nn;
51
- }
52
- function sn(t) {
53
- const e = Object.values(t).filter((s) => typeof s == "number");
54
- return Object.entries(t).filter(([s, i]) => e.indexOf(+s) === -1).map(([s, i]) => i);
55
- }
56
- function rn(t, e) {
57
- return typeof e == "bigint" ? e.toString() : e;
58
- }
59
- function lt(t) {
60
- return {
61
- get value() {
62
- {
63
- const e = t();
64
- return Object.defineProperty(this, "value", { value: e }), e;
65
- }
66
- }
67
- };
68
- }
69
- function dt(t) {
70
- const e = t.startsWith("^") ? 1 : 0, n = t.endsWith("$") ? t.length - 1 : t.length;
71
- return t.slice(e, n);
72
- }
73
- const Ze = /* @__PURE__ */ Symbol("evaluating");
74
- function B(t, e, n) {
75
- let s;
76
- Object.defineProperty(t, e, {
77
- get() {
78
- if (s !== Ze)
79
- return s === void 0 && (s = Ze, s = n()), s;
80
- },
81
- set(i) {
82
- Object.defineProperty(t, e, {
83
- value: i
84
- // configurable: true,
85
- });
86
- },
87
- configurable: !0
88
- });
89
- }
90
- const ht = "captureStackTrace" in Error ? Error.captureStackTrace : (...t) => {
91
- };
92
- function be(t) {
93
- return typeof t == "object" && t !== null && !Array.isArray(t);
94
- }
95
- function ft(t) {
96
- if (be(t) === !1)
97
- return !1;
98
- const e = t.constructor;
99
- if (e === void 0 || typeof e != "function")
100
- return !0;
101
- const n = e.prototype;
102
- return !(be(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
103
- }
104
- function on(t) {
105
- return ft(t) ? { ...t } : Array.isArray(t) ? [...t] : t;
106
- }
107
- const an = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
108
- function Ce(t) {
109
- return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
110
- }
111
- function cn(t, e, n) {
112
- const s = new t._zod.constr(e ?? t._zod.def);
113
- return (!e || n?.parent) && (s._zod.parent = t), s;
114
- }
115
- function C(t) {
116
- return {};
117
- }
118
- function un(t) {
119
- return Object.keys(t).filter((e) => t[e]._zod.optin === "optional" && t[e]._zod.optout === "optional");
120
- }
121
- const ln = {
122
- safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
123
- int32: [-2147483648, 2147483647],
124
- uint32: [0, 4294967295],
125
- float32: [-34028234663852886e22, 34028234663852886e22],
126
- float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
127
- };
128
- function le(t, e = 0) {
129
- if (t.aborted === !0)
130
- return !0;
131
- for (let n = e; n < t.issues.length; n++)
132
- if (t.issues[n]?.continue !== !0)
133
- return !0;
134
- return !1;
135
- }
136
- function Q(t, e) {
137
- return e.map((n) => {
138
- var s;
139
- return (s = n).path ?? (s.path = []), n.path.unshift(t), n;
140
- });
141
- }
142
- function ge(t) {
143
- return typeof t == "string" ? t : t?.message;
144
- }
145
- function re(t, e, n) {
146
- const s = { ...t, path: t.path ?? [] };
147
- if (!t.message) {
148
- const i = ge(t.inst?._zod.def?.error?.(t)) ?? ge(e?.error?.(t)) ?? ge(n.customError?.(t)) ?? ge(n.localeError?.(t)) ?? "Invalid input";
149
- s.message = i;
150
- }
151
- return delete s.inst, delete s.continue, e?.reportInput || delete s.input, s;
152
- }
153
- const mt = (t, e) => {
154
- t.name = "$ZodError", Object.defineProperty(t, "_zod", {
155
- value: t._zod,
156
- enumerable: !1
157
- }), Object.defineProperty(t, "issues", {
158
- value: e,
159
- enumerable: !1
160
- }), t.message = JSON.stringify(e, rn, 2), Object.defineProperty(t, "toString", {
161
- value: () => t.message,
162
- enumerable: !1
163
- });
164
- }, dn = y("$ZodError", mt), _e = y("$ZodError", mt, { Parent: Error }), hn = (t) => (e, n, s, i) => {
165
- const r = s ? Object.assign(s, { async: !1 }) : { async: !1 }, o = e._zod.run({ value: n, issues: [] }, r);
166
- if (o instanceof Promise)
167
- throw new ee();
168
- if (o.issues.length) {
169
- const c = new (i?.Err ?? t)(o.issues.map((a) => re(a, r, ie())));
170
- throw ht(c, i?.callee), c;
171
- }
172
- return o.value;
173
- }, fn = /* @__PURE__ */ hn(_e), mn = (t) => async (e, n, s, i) => {
174
- const r = s ? Object.assign(s, { async: !0 }) : { async: !0 };
175
- let o = e._zod.run({ value: n, issues: [] }, r);
176
- if (o instanceof Promise && (o = await o), o.issues.length) {
177
- const c = new (i?.Err ?? t)(o.issues.map((a) => re(a, r, ie())));
178
- throw ht(c, i?.callee), c;
179
- }
180
- return o.value;
181
- }, pn = /* @__PURE__ */ mn(_e), gn = (t) => (e, n, s) => {
182
- const i = s ? { ...s, async: !1 } : { async: !1 }, r = e._zod.run({ value: n, issues: [] }, i);
183
- if (r instanceof Promise)
184
- throw new ee();
185
- return r.issues.length ? {
186
- success: !1,
187
- error: new (t ?? dn)(r.issues.map((o) => re(o, i, ie())))
188
- } : { success: !0, data: r.value };
189
- }, pt = /* @__PURE__ */ gn(_e), wn = (t) => async (e, n, s) => {
190
- const i = s ? Object.assign(s, { async: !0 }) : { async: !0 };
191
- let r = e._zod.run({ value: n, issues: [] }, i);
192
- return r instanceof Promise && (r = await r), r.issues.length ? {
193
- success: !1,
194
- error: new t(r.issues.map((o) => re(o, i, ie())))
195
- } : { success: !0, data: r.value };
196
- }, gt = /* @__PURE__ */ wn(_e), yn = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, bn = (t) => {
197
- const e = t ? `[\\s\\S]{${t?.minimum ?? 0},${t?.maximum ?? ""}}` : "[\\s\\S]*";
198
- return new RegExp(`^${e}$`);
199
- }, vn = /^-?\d+$/, wt = /^-?\d+(?:\.\d+)?$/, Sn = /^(?:true|false)$/i, ze = /* @__PURE__ */ y("$ZodCheck", (t, e) => {
200
- var n;
201
- t._zod ?? (t._zod = {}), t._zod.def = e, (n = t._zod).onattach ?? (n.onattach = []);
202
- }), yt = {
203
- number: "number",
204
- bigint: "bigint",
205
- object: "date"
206
- }, An = /* @__PURE__ */ y("$ZodCheckLessThan", (t, e) => {
207
- ze.init(t, e);
208
- const n = yt[typeof e.value];
209
- t._zod.onattach.push((s) => {
210
- const i = s._zod.bag, r = (e.inclusive ? i.maximum : i.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
211
- e.value < r && (e.inclusive ? i.maximum = e.value : i.exclusiveMaximum = e.value);
212
- }), t._zod.check = (s) => {
213
- (e.inclusive ? s.value <= e.value : s.value < e.value) || s.issues.push({
214
- origin: n,
215
- code: "too_big",
216
- maximum: typeof e.value == "object" ? e.value.getTime() : e.value,
217
- input: s.value,
218
- inclusive: e.inclusive,
219
- inst: t,
220
- continue: !e.abort
221
- });
222
- };
223
- }), _n = /* @__PURE__ */ y("$ZodCheckGreaterThan", (t, e) => {
224
- ze.init(t, e);
225
- const n = yt[typeof e.value];
226
- t._zod.onattach.push((s) => {
227
- const i = s._zod.bag, r = (e.inclusive ? i.minimum : i.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
228
- e.value > r && (e.inclusive ? i.minimum = e.value : i.exclusiveMinimum = e.value);
229
- }), t._zod.check = (s) => {
230
- (e.inclusive ? s.value >= e.value : s.value > e.value) || s.issues.push({
231
- origin: n,
232
- code: "too_small",
233
- minimum: typeof e.value == "object" ? e.value.getTime() : e.value,
234
- input: s.value,
235
- inclusive: e.inclusive,
236
- inst: t,
237
- continue: !e.abort
238
- });
239
- };
240
- }), zn = /* @__PURE__ */ y("$ZodCheckNumberFormat", (t, e) => {
241
- ze.init(t, e), e.format = e.format || "float64";
242
- const n = e.format?.includes("int"), s = n ? "int" : "number", [i, r] = ln[e.format];
243
- t._zod.onattach.push((o) => {
244
- const c = o._zod.bag;
245
- c.format = e.format, c.minimum = i, c.maximum = r, n && (c.pattern = vn);
246
- }), t._zod.check = (o) => {
247
- const c = o.value;
248
- if (n) {
249
- if (!Number.isInteger(c)) {
250
- o.issues.push({
251
- expected: s,
252
- format: e.format,
253
- code: "invalid_type",
254
- continue: !1,
255
- input: c,
256
- inst: t
257
- });
258
- return;
259
- }
260
- if (!Number.isSafeInteger(c)) {
261
- c > 0 ? o.issues.push({
262
- input: c,
263
- code: "too_big",
264
- maximum: Number.MAX_SAFE_INTEGER,
265
- note: "Integers must be within the safe integer range.",
266
- inst: t,
267
- origin: s,
268
- inclusive: !0,
269
- continue: !e.abort
270
- }) : o.issues.push({
271
- input: c,
272
- code: "too_small",
273
- minimum: Number.MIN_SAFE_INTEGER,
274
- note: "Integers must be within the safe integer range.",
275
- inst: t,
276
- origin: s,
277
- inclusive: !0,
278
- continue: !e.abort
279
- });
280
- return;
281
- }
282
- }
283
- c < i && o.issues.push({
284
- origin: "number",
285
- input: c,
286
- code: "too_small",
287
- minimum: i,
288
- inclusive: !0,
289
- inst: t,
290
- continue: !e.abort
291
- }), c > r && o.issues.push({
292
- origin: "number",
293
- input: c,
294
- code: "too_big",
295
- maximum: r,
296
- inclusive: !0,
297
- inst: t,
298
- continue: !e.abort
299
- });
300
- };
301
- }), Mn = /* @__PURE__ */ y("$ZodCheckStringFormat", (t, e) => {
302
- var n, s;
303
- ze.init(t, e), t._zod.onattach.push((i) => {
304
- const r = i._zod.bag;
305
- r.format = e.format, e.pattern && (r.patterns ?? (r.patterns = /* @__PURE__ */ new Set()), r.patterns.add(e.pattern));
306
- }), e.pattern ? (n = t._zod).check ?? (n.check = (i) => {
307
- e.pattern.lastIndex = 0, !e.pattern.test(i.value) && i.issues.push({
308
- origin: "string",
309
- code: "invalid_format",
310
- format: e.format,
311
- input: i.value,
312
- ...e.pattern ? { pattern: e.pattern.toString() } : {},
313
- inst: t,
314
- continue: !e.abort
315
- });
316
- }) : (s = t._zod).check ?? (s.check = () => {
317
- });
318
- }), kn = {
319
- major: 4,
320
- minor: 3,
321
- patch: 6
322
- }, I = /* @__PURE__ */ y("$ZodType", (t, e) => {
323
- var n;
324
- t ?? (t = {}), t._zod.def = e, t._zod.bag = t._zod.bag || {}, t._zod.version = kn;
325
- const s = [...t._zod.def.checks ?? []];
326
- t._zod.traits.has("$ZodCheck") && s.unshift(t);
327
- for (const i of s)
328
- for (const r of i._zod.onattach)
329
- r(t);
330
- if (s.length === 0)
331
- (n = t._zod).deferred ?? (n.deferred = []), t._zod.deferred?.push(() => {
332
- t._zod.run = t._zod.parse;
333
- });
334
- else {
335
- const i = (o, c, a) => {
336
- let u = le(o), l;
337
- for (const d of c) {
338
- if (d._zod.def.when) {
339
- if (!d._zod.def.when(o))
340
- continue;
341
- } else if (u)
342
- continue;
343
- const f = o.issues.length, p = d._zod.check(o);
344
- if (p instanceof Promise && a?.async === !1)
345
- throw new ee();
346
- if (l || p instanceof Promise)
347
- l = (l ?? Promise.resolve()).then(async () => {
348
- await p, o.issues.length !== f && (u || (u = le(o, f)));
349
- });
350
- else {
351
- if (o.issues.length === f)
352
- continue;
353
- u || (u = le(o, f));
354
- }
355
- }
356
- return l ? l.then(() => o) : o;
357
- }, r = (o, c, a) => {
358
- if (le(o))
359
- return o.aborted = !0, o;
360
- const u = i(c, s, a);
361
- if (u instanceof Promise) {
362
- if (a.async === !1)
363
- throw new ee();
364
- return u.then((l) => t._zod.parse(l, a));
365
- }
366
- return t._zod.parse(u, a);
367
- };
368
- t._zod.run = (o, c) => {
369
- if (c.skipChecks)
370
- return t._zod.parse(o, c);
371
- if (c.direction === "backward") {
372
- const u = t._zod.parse({ value: o.value, issues: [] }, { ...c, skipChecks: !0 });
373
- return u instanceof Promise ? u.then((l) => r(l, o, c)) : r(u, o, c);
374
- }
375
- const a = t._zod.parse(o, c);
376
- if (a instanceof Promise) {
377
- if (c.async === !1)
378
- throw new ee();
379
- return a.then((u) => i(u, s, c));
380
- }
381
- return i(a, s, c);
382
- };
383
- }
384
- B(t, "~standard", () => ({
385
- validate: (i) => {
386
- try {
387
- const r = pt(t, i);
388
- return r.success ? { value: r.data } : { issues: r.error?.issues };
389
- } catch {
390
- return gt(t, i).then((o) => o.success ? { value: o.data } : { issues: o.error?.issues });
391
- }
392
- },
393
- vendor: "zod",
394
- version: 1
395
- }));
396
- }), bt = /* @__PURE__ */ y("$ZodString", (t, e) => {
397
- I.init(t, e), t._zod.pattern = [...t?._zod.bag?.patterns ?? []].pop() ?? bn(t._zod.bag), t._zod.parse = (n, s) => {
398
- if (e.coerce)
399
- try {
400
- n.value = String(n.value);
401
- } catch {
402
- }
403
- return typeof n.value == "string" || n.issues.push({
404
- expected: "string",
405
- code: "invalid_type",
406
- input: n.value,
407
- inst: t
408
- }), n;
409
- };
410
- }), vt = /* @__PURE__ */ y("$ZodStringFormat", (t, e) => {
411
- Mn.init(t, e), bt.init(t, e);
412
- });
413
- function Tn(t) {
414
- if (t === "")
415
- return !0;
416
- if (t.length % 4 !== 0)
417
- return !1;
418
- try {
419
- return atob(t), !0;
420
- } catch {
421
- return !1;
422
- }
423
- }
424
- const Un = /* @__PURE__ */ y("$ZodBase64", (t, e) => {
425
- e.pattern ?? (e.pattern = yn), vt.init(t, e), t._zod.bag.contentEncoding = "base64", t._zod.check = (n) => {
426
- Tn(n.value) || n.issues.push({
427
- code: "invalid_format",
428
- format: "base64",
429
- input: n.value,
430
- inst: t,
431
- continue: !e.abort
432
- });
433
- };
434
- }), St = /* @__PURE__ */ y("$ZodNumber", (t, e) => {
435
- I.init(t, e), t._zod.pattern = t._zod.bag.pattern ?? wt, t._zod.parse = (n, s) => {
436
- if (e.coerce)
437
- try {
438
- n.value = Number(n.value);
439
- } catch {
440
- }
441
- const i = n.value;
442
- if (typeof i == "number" && !Number.isNaN(i) && Number.isFinite(i))
443
- return n;
444
- const r = typeof i == "number" ? Number.isNaN(i) ? "NaN" : Number.isFinite(i) ? void 0 : "Infinity" : void 0;
445
- return n.issues.push({
446
- expected: "number",
447
- code: "invalid_type",
448
- input: i,
449
- inst: t,
450
- ...r ? { received: r } : {}
451
- }), n;
452
- };
453
- }), En = /* @__PURE__ */ y("$ZodNumberFormat", (t, e) => {
454
- zn.init(t, e), St.init(t, e);
455
- }), xn = /* @__PURE__ */ y("$ZodBoolean", (t, e) => {
456
- I.init(t, e), t._zod.pattern = Sn, t._zod.parse = (n, s) => {
457
- if (e.coerce)
458
- try {
459
- n.value = !!n.value;
460
- } catch {
461
- }
462
- const i = n.value;
463
- return typeof i == "boolean" || n.issues.push({
464
- expected: "boolean",
465
- code: "invalid_type",
466
- input: i,
467
- inst: t
468
- }), n;
469
- };
470
- });
471
- function Ve(t, e, n) {
472
- t.issues.length && e.issues.push(...Q(n, t.issues)), e.value[n] = t.value;
473
- }
474
- const Bn = /* @__PURE__ */ y("$ZodArray", (t, e) => {
475
- I.init(t, e), t._zod.parse = (n, s) => {
476
- const i = n.value;
477
- if (!Array.isArray(i))
478
- return n.issues.push({
479
- expected: "array",
480
- code: "invalid_type",
481
- input: i,
482
- inst: t
483
- }), n;
484
- n.value = Array(i.length);
485
- const r = [];
486
- for (let o = 0; o < i.length; o++) {
487
- const c = i[o], a = e.element._zod.run({
488
- value: c,
489
- issues: []
490
- }, s);
491
- a instanceof Promise ? r.push(a.then((u) => Ve(u, n, o))) : Ve(a, n, o);
492
- }
493
- return r.length ? Promise.all(r).then(() => n) : n;
494
- };
495
- });
496
- function ve(t, e, n, s, i) {
497
- if (t.issues.length) {
498
- if (i && !(n in s))
499
- return;
500
- e.issues.push(...Q(n, t.issues));
501
- }
502
- t.value === void 0 ? n in s && (e.value[n] = void 0) : e.value[n] = t.value;
503
- }
504
- function Rn(t) {
505
- const e = Object.keys(t.shape);
506
- for (const s of e)
507
- if (!t.shape?.[s]?._zod?.traits?.has("$ZodType"))
508
- throw new Error(`Invalid element at key "${s}": expected a Zod schema`);
509
- const n = un(t.shape);
510
- return {
511
- ...t,
512
- keys: e,
513
- keySet: new Set(e),
514
- numKeys: e.length,
515
- optionalKeys: new Set(n)
516
- };
517
- }
518
- function Cn(t, e, n, s, i, r) {
519
- const o = [], c = i.keySet, a = i.catchall._zod, u = a.def.type, l = a.optout === "optional";
520
- for (const d in e) {
521
- if (c.has(d))
522
- continue;
523
- if (u === "never") {
524
- o.push(d);
525
- continue;
526
- }
527
- const f = a.run({ value: e[d], issues: [] }, s);
528
- f instanceof Promise ? t.push(f.then((p) => ve(p, n, d, e, l))) : ve(f, n, d, e, l);
529
- }
530
- return o.length && n.issues.push({
531
- code: "unrecognized_keys",
532
- keys: o,
533
- input: e,
534
- inst: r
535
- }), t.length ? Promise.all(t).then(() => n) : n;
536
- }
537
- const In = /* @__PURE__ */ y("$ZodObject", (t, e) => {
538
- if (I.init(t, e), !Object.getOwnPropertyDescriptor(e, "shape")?.get) {
539
- const c = e.shape;
540
- Object.defineProperty(e, "shape", {
541
- get: () => {
542
- const a = { ...c };
543
- return Object.defineProperty(e, "shape", {
544
- value: a
545
- }), a;
546
- }
547
- });
548
- }
549
- const s = lt(() => Rn(e));
550
- B(t._zod, "propValues", () => {
551
- const c = e.shape, a = {};
552
- for (const u in c) {
553
- const l = c[u]._zod;
554
- if (l.values) {
555
- a[u] ?? (a[u] = /* @__PURE__ */ new Set());
556
- for (const d of l.values)
557
- a[u].add(d);
558
- }
559
- }
560
- return a;
561
- });
562
- const i = be, r = e.catchall;
563
- let o;
564
- t._zod.parse = (c, a) => {
565
- o ?? (o = s.value);
566
- const u = c.value;
567
- if (!i(u))
568
- return c.issues.push({
569
- expected: "object",
570
- code: "invalid_type",
571
- input: u,
572
- inst: t
573
- }), c;
574
- c.value = {};
575
- const l = [], d = o.shape;
576
- for (const f of o.keys) {
577
- const p = d[f], b = p._zod.optout === "optional", w = p._zod.run({ value: u[f], issues: [] }, a);
578
- w instanceof Promise ? l.push(w.then((v) => ve(v, c, f, u, b))) : ve(w, c, f, u, b);
579
- }
580
- return r ? Cn(l, u, c, a, s.value, t) : l.length ? Promise.all(l).then(() => c) : c;
581
- };
582
- });
583
- function We(t, e, n, s) {
584
- for (const r of t)
585
- if (r.issues.length === 0)
586
- return e.value = r.value, e;
587
- const i = t.filter((r) => !le(r));
588
- return i.length === 1 ? (e.value = i[0].value, i[0]) : (e.issues.push({
589
- code: "invalid_union",
590
- input: e.value,
591
- inst: n,
592
- errors: t.map((r) => r.issues.map((o) => re(o, s, ie())))
593
- }), e);
594
- }
595
- const At = /* @__PURE__ */ y("$ZodUnion", (t, e) => {
596
- I.init(t, e), B(t._zod, "optin", () => e.options.some((i) => i._zod.optin === "optional") ? "optional" : void 0), B(t._zod, "optout", () => e.options.some((i) => i._zod.optout === "optional") ? "optional" : void 0), B(t._zod, "values", () => {
597
- if (e.options.every((i) => i._zod.values))
598
- return new Set(e.options.flatMap((i) => Array.from(i._zod.values)));
599
- }), B(t._zod, "pattern", () => {
600
- if (e.options.every((i) => i._zod.pattern)) {
601
- const i = e.options.map((r) => r._zod.pattern);
602
- return new RegExp(`^(${i.map((r) => dt(r.source)).join("|")})$`);
603
- }
604
- });
605
- const n = e.options.length === 1, s = e.options[0]._zod.run;
606
- t._zod.parse = (i, r) => {
607
- if (n)
608
- return s(i, r);
609
- let o = !1;
610
- const c = [];
611
- for (const a of e.options) {
612
- const u = a._zod.run({
613
- value: i.value,
614
- issues: []
615
- }, r);
616
- if (u instanceof Promise)
617
- c.push(u), o = !0;
618
- else {
619
- if (u.issues.length === 0)
620
- return u;
621
- c.push(u);
622
- }
623
- }
624
- return o ? Promise.all(c).then((a) => We(a, i, t, r)) : We(c, i, t, r);
625
- };
626
- }), Dn = /* @__PURE__ */ y("$ZodDiscriminatedUnion", (t, e) => {
627
- e.inclusive = !1, At.init(t, e);
628
- const n = t._zod.parse;
629
- B(t._zod, "propValues", () => {
630
- const i = {};
631
- for (const r of e.options) {
632
- const o = r._zod.propValues;
633
- if (!o || Object.keys(o).length === 0)
634
- throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);
635
- for (const [c, a] of Object.entries(o)) {
636
- i[c] || (i[c] = /* @__PURE__ */ new Set());
637
- for (const u of a)
638
- i[c].add(u);
639
- }
640
- }
641
- return i;
642
- });
643
- const s = lt(() => {
644
- const i = e.options, r = /* @__PURE__ */ new Map();
645
- for (const o of i) {
646
- const c = o._zod.propValues?.[e.discriminator];
647
- if (!c || c.size === 0)
648
- throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(o)}"`);
649
- for (const a of c) {
650
- if (r.has(a))
651
- throw new Error(`Duplicate discriminator value "${String(a)}"`);
652
- r.set(a, o);
653
- }
654
- }
655
- return r;
656
- });
657
- t._zod.parse = (i, r) => {
658
- const o = i.value;
659
- if (!be(o))
660
- return i.issues.push({
661
- code: "invalid_type",
662
- expected: "object",
663
- input: o,
664
- inst: t
665
- }), i;
666
- const c = s.value.get(o?.[e.discriminator]);
667
- return c ? c._zod.run(i, r) : e.unionFallback ? n(i, r) : (i.issues.push({
668
- code: "invalid_union",
669
- errors: [],
670
- note: "No matching discriminator",
671
- discriminator: e.discriminator,
672
- input: o,
673
- path: [e.discriminator],
674
- inst: t
675
- }), i);
676
- };
677
- }), On = /* @__PURE__ */ y("$ZodRecord", (t, e) => {
678
- I.init(t, e), t._zod.parse = (n, s) => {
679
- const i = n.value;
680
- if (!ft(i))
681
- return n.issues.push({
682
- expected: "record",
683
- code: "invalid_type",
684
- input: i,
685
- inst: t
686
- }), n;
687
- const r = [], o = e.keyType._zod.values;
688
- if (o) {
689
- n.value = {};
690
- const c = /* @__PURE__ */ new Set();
691
- for (const u of o)
692
- if (typeof u == "string" || typeof u == "number" || typeof u == "symbol") {
693
- c.add(typeof u == "number" ? u.toString() : u);
694
- const l = e.valueType._zod.run({ value: i[u], issues: [] }, s);
695
- l instanceof Promise ? r.push(l.then((d) => {
696
- d.issues.length && n.issues.push(...Q(u, d.issues)), n.value[u] = d.value;
697
- })) : (l.issues.length && n.issues.push(...Q(u, l.issues)), n.value[u] = l.value);
698
- }
699
- let a;
700
- for (const u in i)
701
- c.has(u) || (a = a ?? [], a.push(u));
702
- a && a.length > 0 && n.issues.push({
703
- code: "unrecognized_keys",
704
- input: i,
705
- inst: t,
706
- keys: a
707
- });
708
- } else {
709
- n.value = {};
710
- for (const c of Reflect.ownKeys(i)) {
711
- if (c === "__proto__")
712
- continue;
713
- let a = e.keyType._zod.run({ value: c, issues: [] }, s);
714
- if (a instanceof Promise)
715
- throw new Error("Async schemas not supported in object keys currently");
716
- if (typeof c == "string" && wt.test(c) && a.issues.length) {
717
- const d = e.keyType._zod.run({ value: Number(c), issues: [] }, s);
718
- if (d instanceof Promise)
719
- throw new Error("Async schemas not supported in object keys currently");
720
- d.issues.length === 0 && (a = d);
721
- }
722
- if (a.issues.length) {
723
- e.mode === "loose" ? n.value[c] = i[c] : n.issues.push({
724
- code: "invalid_key",
725
- origin: "record",
726
- issues: a.issues.map((d) => re(d, s, ie())),
727
- input: c,
728
- path: [c],
729
- inst: t
730
- });
731
- continue;
732
- }
733
- const l = e.valueType._zod.run({ value: i[c], issues: [] }, s);
734
- l instanceof Promise ? r.push(l.then((d) => {
735
- d.issues.length && n.issues.push(...Q(c, d.issues)), n.value[a.value] = d.value;
736
- })) : (l.issues.length && n.issues.push(...Q(c, l.issues)), n.value[a.value] = l.value);
737
- }
738
- }
739
- return r.length ? Promise.all(r).then(() => n) : n;
740
- };
741
- }), Ln = /* @__PURE__ */ y("$ZodEnum", (t, e) => {
742
- I.init(t, e);
743
- const n = sn(e.entries), s = new Set(n);
744
- t._zod.values = s, t._zod.pattern = new RegExp(`^(${n.filter((i) => an.has(typeof i)).map((i) => typeof i == "string" ? Ce(i) : i.toString()).join("|")})$`), t._zod.parse = (i, r) => {
745
- const o = i.value;
746
- return s.has(o) || i.issues.push({
747
- code: "invalid_value",
748
- values: n,
749
- input: o,
750
- inst: t
751
- }), i;
752
- };
753
- }), Fn = /* @__PURE__ */ y("$ZodLiteral", (t, e) => {
754
- if (I.init(t, e), e.values.length === 0)
755
- throw new Error("Cannot create literal schema with no valid values");
756
- const n = new Set(e.values);
757
- t._zod.values = n, t._zod.pattern = new RegExp(`^(${e.values.map((s) => typeof s == "string" ? Ce(s) : s ? Ce(s.toString()) : String(s)).join("|")})$`), t._zod.parse = (s, i) => {
758
- const r = s.value;
759
- return n.has(r) || s.issues.push({
760
- code: "invalid_value",
761
- values: e.values,
762
- input: r,
763
- inst: t
764
- }), s;
765
- };
766
- }), $n = /* @__PURE__ */ y("$ZodTransform", (t, e) => {
767
- I.init(t, e), t._zod.parse = (n, s) => {
768
- if (s.direction === "backward")
769
- throw new tn(t.constructor.name);
770
- const i = e.transform(n.value, n);
771
- if (s.async)
772
- return (i instanceof Promise ? i : Promise.resolve(i)).then((o) => (n.value = o, n));
773
- if (i instanceof Promise)
774
- throw new ee();
775
- return n.value = i, n;
776
- };
777
- });
778
- function qe(t, e) {
779
- return t.issues.length && e === void 0 ? { issues: [], value: void 0 } : t;
780
- }
781
- const Pn = /* @__PURE__ */ y("$ZodOptional", (t, e) => {
782
- I.init(t, e), t._zod.optin = "optional", t._zod.optout = "optional", B(t._zod, "values", () => e.innerType._zod.values ? /* @__PURE__ */ new Set([...e.innerType._zod.values, void 0]) : void 0), B(t._zod, "pattern", () => {
783
- const n = e.innerType._zod.pattern;
784
- return n ? new RegExp(`^(${dt(n.source)})?$`) : void 0;
785
- }), t._zod.parse = (n, s) => {
786
- if (e.innerType._zod.optin === "optional") {
787
- const i = e.innerType._zod.run(n, s);
788
- return i instanceof Promise ? i.then((r) => qe(r, n.value)) : qe(i, n.value);
789
- }
790
- return n.value === void 0 ? n : e.innerType._zod.run(n, s);
791
- };
792
- }), Nn = /* @__PURE__ */ y("$ZodDefault", (t, e) => {
793
- I.init(t, e), t._zod.optin = "optional", B(t._zod, "values", () => e.innerType._zod.values), t._zod.parse = (n, s) => {
794
- if (s.direction === "backward")
795
- return e.innerType._zod.run(n, s);
796
- if (n.value === void 0)
797
- return n.value = e.defaultValue, n;
798
- const i = e.innerType._zod.run(n, s);
799
- return i instanceof Promise ? i.then((r) => He(r, e)) : He(i, e);
800
- };
801
- });
802
- function He(t, e) {
803
- return t.value === void 0 && (t.value = e.defaultValue), t;
804
- }
805
- const jn = /* @__PURE__ */ y("$ZodPipe", (t, e) => {
806
- I.init(t, e), B(t._zod, "values", () => e.in._zod.values), B(t._zod, "optin", () => e.in._zod.optin), B(t._zod, "optout", () => e.out._zod.optout), B(t._zod, "propValues", () => e.in._zod.propValues), t._zod.parse = (n, s) => {
807
- if (s.direction === "backward") {
808
- const r = e.out._zod.run(n, s);
809
- return r instanceof Promise ? r.then((o) => we(o, e.in, s)) : we(r, e.in, s);
810
- }
811
- const i = e.in._zod.run(n, s);
812
- return i instanceof Promise ? i.then((r) => we(r, e.out, s)) : we(i, e.out, s);
813
- };
814
- });
815
- function we(t, e, n) {
816
- return t.issues.length ? (t.aborted = !0, t) : e._zod.run({ value: t.value, issues: t.issues }, n);
817
- }
818
- var Ge;
819
- class Zn {
820
- constructor() {
821
- this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map();
822
- }
823
- add(e, ...n) {
824
- const s = n[0];
825
- return this._map.set(e, s), s && typeof s == "object" && "id" in s && this._idmap.set(s.id, e), this;
826
- }
827
- clear() {
828
- return this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map(), this;
829
- }
830
- remove(e) {
831
- const n = this._map.get(e);
832
- return n && typeof n == "object" && "id" in n && this._idmap.delete(n.id), this._map.delete(e), this;
833
- }
834
- get(e) {
835
- const n = e._zod.parent;
836
- if (n) {
837
- const s = { ...this.get(n) ?? {} };
838
- delete s.id;
839
- const i = { ...s, ...this._map.get(e) };
840
- return Object.keys(i).length ? i : void 0;
841
- }
842
- return this._map.get(e);
843
- }
844
- has(e) {
845
- return this._map.has(e);
846
- }
847
- }
848
- function Vn() {
849
- return new Zn();
850
- }
851
- (Ge = globalThis).__zod_globalRegistry ?? (Ge.__zod_globalRegistry = Vn());
852
- // @__NO_SIDE_EFFECTS__
853
- function Wn(t, e) {
854
- return new t({
855
- type: "string",
856
- ...C()
857
- });
858
- }
859
- // @__NO_SIDE_EFFECTS__
860
- function qn(t, e) {
861
- return new t({
862
- type: "string",
863
- format: "base64",
864
- check: "string_format",
865
- abort: !1,
866
- ...C()
867
- });
868
- }
869
- // @__NO_SIDE_EFFECTS__
870
- function Hn(t, e) {
871
- return new t({
872
- type: "number",
873
- checks: [],
874
- ...C()
875
- });
876
- }
877
- // @__NO_SIDE_EFFECTS__
878
- function Gn(t, e) {
879
- return new t({
880
- type: "number",
881
- check: "number_format",
882
- abort: !1,
883
- format: "safeint",
884
- ...C()
885
- });
886
- }
887
- // @__NO_SIDE_EFFECTS__
888
- function Xn(t, e) {
889
- return new t({
890
- type: "boolean",
891
- ...C()
892
- });
893
- }
894
- // @__NO_SIDE_EFFECTS__
895
- function _t(t, e) {
896
- return new An({
897
- check: "less_than",
898
- ...C(),
899
- value: t,
900
- inclusive: !0
901
- });
902
- }
903
- // @__NO_SIDE_EFFECTS__
904
- function Yn(t, e) {
905
- return new _n({
906
- check: "greater_than",
907
- ...C(),
908
- value: t,
909
- inclusive: !0
910
- });
911
- }
912
- // @__NO_SIDE_EFFECTS__
913
- function zt(t) {
914
- return /* @__PURE__ */ Yn(0);
915
- }
916
- const D = /* @__PURE__ */ y("ZodMiniType", (t, e) => {
917
- if (!t._zod)
918
- throw new Error("Uninitialized schema in ZodMiniType.");
919
- I.init(t, e), t.def = e, t.type = e.type, t.parse = (n, s) => fn(t, n, s, { callee: t.parse }), t.safeParse = (n, s) => pt(t, n, s), t.parseAsync = async (n, s) => pn(t, n, s, { callee: t.parseAsync }), t.safeParseAsync = async (n, s) => gt(t, n, s), t.check = (...n) => t.clone({
920
- ...e,
921
- checks: [
922
- ...e.checks ?? [],
923
- ...n.map((s) => typeof s == "function" ? { _zod: { check: s, def: { check: "custom" }, onattach: [] } } : s)
924
- ]
925
- }, { parent: !0 }), t.with = t.check, t.clone = (n, s) => cn(t, n, s), t.brand = () => t, t.register = ((n, s) => (n.add(t, s), t)), t.apply = (n) => n(t);
926
- }), Mt = /* @__PURE__ */ y("ZodMiniString", (t, e) => {
927
- bt.init(t, e), D.init(t, e);
928
- });
929
- // @__NO_SIDE_EFFECTS__
930
- function S(t) {
931
- return /* @__PURE__ */ Wn(Mt);
932
- }
933
- const Kn = /* @__PURE__ */ y("ZodMiniStringFormat", (t, e) => {
934
- vt.init(t, e), Mt.init(t, e);
935
- }), Jn = /* @__PURE__ */ y("ZodMiniBase64", (t, e) => {
936
- Un.init(t, e), Kn.init(t, e);
937
- });
938
- // @__NO_SIDE_EFFECTS__
939
- function Qn(t) {
940
- return /* @__PURE__ */ qn(Jn);
941
- }
942
- const kt = /* @__PURE__ */ y("ZodMiniNumber", (t, e) => {
943
- St.init(t, e), D.init(t, e);
944
- });
945
- // @__NO_SIDE_EFFECTS__
946
- function U(t) {
947
- return /* @__PURE__ */ Hn(kt);
948
- }
949
- const es = /* @__PURE__ */ y("ZodMiniNumberFormat", (t, e) => {
950
- En.init(t, e), kt.init(t, e);
951
- });
952
- // @__NO_SIDE_EFFECTS__
953
- function Tt(t) {
954
- return /* @__PURE__ */ Gn(es);
955
- }
956
- const ts = /* @__PURE__ */ y("ZodMiniBoolean", (t, e) => {
957
- xn.init(t, e), D.init(t, e);
958
- });
959
- // @__NO_SIDE_EFFECTS__
960
- function Ie(t) {
961
- return /* @__PURE__ */ Xn(ts);
962
- }
963
- const ns = /* @__PURE__ */ y("ZodMiniArray", (t, e) => {
964
- Bn.init(t, e), D.init(t, e);
965
- });
966
- // @__NO_SIDE_EFFECTS__
967
- function q(t, e) {
968
- return new ns({
969
- type: "array",
970
- element: t,
971
- ...C()
972
- });
973
- }
974
- const ss = /* @__PURE__ */ y("ZodMiniObject", (t, e) => {
975
- In.init(t, e), D.init(t, e), B(t, "shape", () => e.shape);
976
- });
977
- // @__NO_SIDE_EFFECTS__
978
- function z(t, e) {
979
- const n = {
980
- type: "object",
981
- shape: t ?? {},
982
- ...C()
983
- };
984
- return new ss(n);
985
- }
986
- const is = /* @__PURE__ */ y("ZodMiniUnion", (t, e) => {
987
- At.init(t, e), D.init(t, e);
988
- });
989
- // @__NO_SIDE_EFFECTS__
990
- function Me(t, e) {
991
- return new is({
992
- type: "union",
993
- options: t,
994
- ...C()
995
- });
996
- }
997
- const rs = /* @__PURE__ */ y("ZodMiniDiscriminatedUnion", (t, e) => {
998
- Dn.init(t, e), D.init(t, e);
999
- });
1000
- // @__NO_SIDE_EFFECTS__
1001
- function os(t, e, n) {
1002
- return new rs({
1003
- type: "union",
1004
- options: e,
1005
- discriminator: t,
1006
- ...C()
1007
- });
1008
- }
1009
- const as = /* @__PURE__ */ y("ZodMiniRecord", (t, e) => {
1010
- On.init(t, e), D.init(t, e);
1011
- });
1012
- // @__NO_SIDE_EFFECTS__
1013
- function De(t, e, n) {
1014
- return new as({
1015
- type: "record",
1016
- keyType: t,
1017
- valueType: e,
1018
- ...C()
1019
- });
1020
- }
1021
- const cs = /* @__PURE__ */ y("ZodMiniEnum", (t, e) => {
1022
- Ln.init(t, e), D.init(t, e), t.options = Object.values(e.entries);
1023
- });
1024
- // @__NO_SIDE_EFFECTS__
1025
- function Ut(t, e) {
1026
- const n = Array.isArray(t) ? Object.fromEntries(t.map((s) => [s, s])) : t;
1027
- return new cs({
1028
- type: "enum",
1029
- entries: n,
1030
- ...C()
1031
- });
1032
- }
1033
- const us = /* @__PURE__ */ y("ZodMiniLiteral", (t, e) => {
1034
- Fn.init(t, e), D.init(t, e);
1035
- });
1036
- // @__NO_SIDE_EFFECTS__
1037
- function ye(t, e) {
1038
- return new us({
1039
- type: "literal",
1040
- values: Array.isArray(t) ? t : [t],
1041
- ...C()
1042
- });
1043
- }
1044
- const ls = /* @__PURE__ */ y("ZodMiniTransform", (t, e) => {
1045
- $n.init(t, e), D.init(t, e);
1046
- });
1047
- // @__NO_SIDE_EFFECTS__
1048
- function Et(t) {
1049
- return new ls({
1050
- type: "transform",
1051
- transform: t
1052
- });
1053
- }
1054
- const ds = /* @__PURE__ */ y("ZodMiniOptional", (t, e) => {
1055
- Pn.init(t, e), D.init(t, e);
1056
- });
1057
- // @__NO_SIDE_EFFECTS__
1058
- function m(t) {
1059
- return new ds({
1060
- type: "optional",
1061
- innerType: t
1062
- });
1063
- }
1064
- const hs = /* @__PURE__ */ y("ZodMiniDefault", (t, e) => {
1065
- Nn.init(t, e), D.init(t, e);
1066
- });
1067
- // @__NO_SIDE_EFFECTS__
1068
- function fs(t, e) {
1069
- return new hs({
1070
- type: "default",
1071
- innerType: t,
1072
- get defaultValue() {
1073
- return typeof e == "function" ? e() : on(e);
1074
- }
1075
- });
1076
- }
1077
- const ms = /* @__PURE__ */ y("ZodMiniPipe", (t, e) => {
1078
- jn.init(t, e), D.init(t, e);
1079
- });
1080
- // @__NO_SIDE_EFFECTS__
1081
- function xt(t, e) {
1082
- return new ms({
1083
- type: "pipe",
1084
- in: t,
1085
- out: e
1086
- });
1087
- }
1088
- (/* @__PURE__ */ U()).check(/* @__PURE__ */ Tt(), /* @__PURE__ */ zt(), /* @__PURE__ */ _t(255)).brand("u8");
1089
- const x = (/* @__PURE__ */ U()).check(/* @__PURE__ */ Tt(), /* @__PURE__ */ zt(), /* @__PURE__ */ _t(Number.MAX_SAFE_INTEGER)).brand("u53");
1090
- function V(t) {
1091
- return x.parse(t);
1092
- }
1093
- const Bt = /* @__PURE__ */ fs(
1094
- /* @__PURE__ */ os("kind", [
1095
- // The default hang container
1096
- /* @__PURE__ */ z({ kind: /* @__PURE__ */ ye("legacy") }),
1097
- // CMAF container with base64-encoded init segment (ftyp+moov).
1098
- // `timescale` and `trackId` are deprecated: they duplicate info in `init`
1099
- // and are accepted only so catalogs from newer publishers (which still
1100
- // emit them for older players) round-trip cleanly.
1101
- /* @__PURE__ */ z({
1102
- kind: /* @__PURE__ */ ye("cmaf"),
1103
- init: /* @__PURE__ */ Qn(),
1104
- timescale: /* @__PURE__ */ m(x),
1105
- trackId: /* @__PURE__ */ m(x)
1106
- }),
1107
- // Low Overhead Container.
1108
- /* @__PURE__ */ z({ kind: /* @__PURE__ */ ye("loc") })
1109
- ]),
1110
- { kind: "legacy" }
1111
- ), ps = /* @__PURE__ */ z({
1112
- name: /* @__PURE__ */ S()
1113
- }), Xe = /* @__PURE__ */ z({
1114
- // See: https://w3c.github.io/webcodecs/codec_registry.html
1115
- codec: /* @__PURE__ */ S(),
1116
- // The container format, used to decode the timestamp and more.
1117
- container: Bt,
1118
- // The description is used for some codecs.
1119
- // If provided, we can initialize the decoder based on the catalog alone.
1120
- // Otherwise, the initialization information is in-band.
1121
- description: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1122
- // hex encoded TODO use base64
1123
- // The sample rate of the audio in Hz
1124
- sampleRate: x,
1125
- // The number of channels in the audio
1126
- numberOfChannels: x,
1127
- // The bitrate of the audio in bits per second
1128
- // TODO: Support up to Number.MAX_SAFE_INTEGER
1129
- bitrate: /* @__PURE__ */ m(x),
1130
- // The maximum jitter before the next frame is emitted in milliseconds.
1131
- // The player's jitter buffer should be larger than this value.
1132
- // If not provided, the player should assume each frame is flushed immediately.
1133
- //
1134
- // NOTE: The audio "frame" duration depends on the codec, sample rate, etc.
1135
- // ex: AAC often uses 1024 samples per frame, so at 44100Hz, this would be 1024/44100 = 23ms
1136
- jitter: /* @__PURE__ */ m(x)
1137
- }), gs = /* @__PURE__ */ Me([
1138
- /* @__PURE__ */ z({
1139
- // A map of track name to rendition configuration.
1140
- // This is not an array so it will work with JSON Merge Patch.
1141
- renditions: /* @__PURE__ */ De(/* @__PURE__ */ S(), Xe)
1142
- }),
1143
- // Backwards compatibility: transform old {track, config} format to new object format
1144
- /* @__PURE__ */ xt(
1145
- /* @__PURE__ */ z({
1146
- track: ps,
1147
- config: Xe
1148
- }),
1149
- /* @__PURE__ */ Et((t) => ({
1150
- renditions: { [t.track.name]: t.config }
1151
- }))
1152
- )
1153
- ]), ws = /* @__PURE__ */ z({
1154
- hardware: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S())),
1155
- software: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S())),
1156
- unsupported: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S()))
1157
- }), ys = /* @__PURE__ */ z({
1158
- hardware: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S())),
1159
- software: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S())),
1160
- unsupported: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ S()))
1161
- }), bs = /* @__PURE__ */ z({
1162
- video: /* @__PURE__ */ m(ws),
1163
- audio: /* @__PURE__ */ m(ys)
1164
- }), fe = /* @__PURE__ */ z({
1165
- name: /* @__PURE__ */ S()
1166
- }), vs = /* @__PURE__ */ z({
1167
- message: /* @__PURE__ */ m(fe),
1168
- typing: /* @__PURE__ */ m(fe)
1169
- }), Rt = ["hang", "msf"], Ss = "hang";
1170
- function As(t) {
1171
- for (const e of Rt)
1172
- if (t.endsWith(`.${e}`)) return e;
1173
- }
1174
- const Ct = /* @__PURE__ */ z({
1175
- // The relative X position of the broadcast, from -1 to +1.
1176
- // This should be used for audio panning but can also be used for video positioning.
1177
- x: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1178
- // The relative Y position of the broadcast, from -1 to +1.
1179
- // This can be used for video positioning, and maybe audio panning.
1180
- y: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1181
- // The relative Z index of the broadcast, where larger values are closer to the viewer.
1182
- // This is used to break ties when there are multiple broadcasts at the same position.
1183
- z: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1184
- // The scale of the broadcast, where 1 is 100%
1185
- s: /* @__PURE__ */ m(/* @__PURE__ */ U())
1186
- }), _s = /* @__PURE__ */ z({
1187
- // The initial position of the broadcaster, from -1 to +1 in both dimensions.
1188
- // If not provided, then the broadcaster is assumed to be at (0,0)
1189
- // This should be used for audio panning but can also be used for video positioning.
1190
- initial: /* @__PURE__ */ m(Ct),
1191
- // If provided, then updates to the position are done via a separate Moq track.
1192
- // This is used to avoid a full catalog update every time we want to update a few bytes.
1193
- // TODO: These updates currently use JSON for simplicity, but we should use a binary format.
1194
- track: /* @__PURE__ */ m(fe),
1195
- // If set, then this broadcaster allows other peers to request position updates via this handle.
1196
- // We will have to discover and subscribe to their position updates.
1197
- handle: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1198
- // If provided, this broadcaster is signaling the location of other peers.
1199
- // The payload is a JSON blob keyed by handle for each peer.
1200
- peers: /* @__PURE__ */ m(fe)
1201
- }), Ur = /* @__PURE__ */ De(/* @__PURE__ */ S(), Ct), te = {
1202
- catalog: 100,
1203
- chat: 90,
1204
- audio: 80,
1205
- video: 60,
1206
- typing: 40,
1207
- location: 20,
1208
- preview: 10
1209
- }, zs = /* @__PURE__ */ z({
1210
- id: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1211
- name: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1212
- avatar: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1213
- // TODO allow using a track instead of a URL?
1214
- color: /* @__PURE__ */ m(/* @__PURE__ */ S())
1215
- }), Ms = /* @__PURE__ */ z({
1216
- name: /* @__PURE__ */ S()
1217
- }), Ye = /* @__PURE__ */ z({
1218
- // See: https://w3c.github.io/webcodecs/codec_registry.html
1219
- codec: /* @__PURE__ */ S(),
1220
- // The container format, used to decode the timestamp and more.
1221
- container: Bt,
1222
- // The description is used for some codecs.
1223
- // If provided, we can initialize the decoder based on the catalog alone.
1224
- // Otherwise, the initialization information is (repeated) before each key-frame.
1225
- description: /* @__PURE__ */ m(/* @__PURE__ */ S()),
1226
- // hex encoded TODO use base64
1227
- // The width and height of the video in pixels.
1228
- // NOTE: formats that don't use a description can adjust these values in-band.
1229
- codedWidth: /* @__PURE__ */ m(x),
1230
- codedHeight: /* @__PURE__ */ m(x),
1231
- // Ratio of display width/height to coded width/height
1232
- // Allows stretching/squishing individual "pixels" of the video
1233
- // If not provided, the display ratio is 1:1
1234
- displayAspectWidth: /* @__PURE__ */ m(x),
1235
- displayAspectHeight: /* @__PURE__ */ m(x),
1236
- // The frame rate of the video in frames per second
1237
- framerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1238
- // The bitrate of the video in bits per second
1239
- // TODO: Support up to Number.MAX_SAFE_INTEGER
1240
- bitrate: /* @__PURE__ */ m(x),
1241
- // If true, the decoder will optimize for latency.
1242
- // Default: true
1243
- optimizeForLatency: /* @__PURE__ */ m(/* @__PURE__ */ Ie()),
1244
- // The maximum jitter before the next frame is emitted in milliseconds.
1245
- // The player's jitter buffer should be larger than this value.
1246
- // If not provided, the player should assume each frame is flushed immediately.
1247
- //
1248
- // ex:
1249
- // - If each frame is flushed immediately, this would be 1000/fps.
1250
- // - If there can be up to 3 b-frames in a row, this would be 3 * 1000/fps.
1251
- // - If frames are buffered into 2s segments, this would be 2s.
1252
- jitter: /* @__PURE__ */ m(x)
1253
- }), ks = /* @__PURE__ */ Me([
1254
- /* @__PURE__ */ z({
1255
- // A map of track name to rendition configuration.
1256
- // This is not an array in order for it to work with JSON Merge Patch.
1257
- renditions: /* @__PURE__ */ De(/* @__PURE__ */ S(), Ye),
1258
- // Render the video at this size in pixels.
1259
- // This is separate from the display aspect ratio because it does not require reinitialization.
1260
- display: /* @__PURE__ */ m(
1261
- /* @__PURE__ */ z({
1262
- width: x,
1263
- height: x
1264
- })
1265
- ),
1266
- // The rotation of the video in degrees.
1267
- // Default: 0
1268
- rotation: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1269
- // If true, the decoder will flip the video horizontally
1270
- // Default: false
1271
- flip: /* @__PURE__ */ m(/* @__PURE__ */ Ie())
1272
- }),
1273
- // Backwards compatibility: transform old array of {track, config} to new object format
1274
- /* @__PURE__ */ xt(
1275
- /* @__PURE__ */ q(
1276
- /* @__PURE__ */ z({
1277
- track: Ms,
1278
- config: Ye
1279
- })
1280
- ),
1281
- /* @__PURE__ */ Et((t) => {
1282
- const e = t[0]?.config;
1283
- return {
1284
- renditions: Object.fromEntries(t.map((n) => [n.track.name, n.config])),
1285
- display: e?.displayAspectWidth !== void 0 && e?.displayAspectHeight !== void 0 ? { width: e.displayAspectWidth, height: e.displayAspectHeight } : void 0,
1286
- rotation: void 0,
1287
- flip: void 0
1288
- };
1289
- })
1290
- )
1291
- ]), Ts = /* @__PURE__ */ z({
1292
- video: /* @__PURE__ */ m(ks),
1293
- audio: /* @__PURE__ */ m(gs),
1294
- location: /* @__PURE__ */ m(_s),
1295
- user: /* @__PURE__ */ m(zs),
1296
- chat: /* @__PURE__ */ m(vs),
1297
- capabilities: /* @__PURE__ */ m(bs),
1298
- preview: /* @__PURE__ */ m(fe)
1299
- });
1300
- function Us(t) {
1301
- const n = new TextDecoder().decode(t);
1302
- try {
1303
- const s = JSON.parse(n);
1304
- return Ts.parse(s);
1305
- } catch (s) {
1306
- throw console.warn("invalid catalog", n), s;
1307
- }
1308
- }
1309
- async function Es(t) {
1310
- const e = await t.readFrame();
1311
- if (e)
1312
- return Us(e);
1313
- }
1314
- const xs = 6, Bs = 8, Ke = 1e6;
1315
- let ke = class {
1316
- decode(e) {
1317
- const [n, s] = A.Varint.decode(e);
1318
- if (s.byteLength < n)
1319
- throw new Error("loc: properties_length exceeds frame size");
1320
- const i = s.subarray(0, n), r = s.subarray(n);
1321
- let o, c, a = 0, u = !0, l = i;
1322
- for (; l.byteLength > 0; ) {
1323
- const [p, b] = A.Varint.decode(l), w = u ? p : a + p;
1324
- if (u = !1, a = w, l = b, w % 2 === 0) {
1325
- const [v, _] = A.Varint.decode(l);
1326
- if (l = _, w === xs)
1327
- o = v;
1328
- else if (w === Bs) {
1329
- if (v === 0)
1330
- throw new Error("loc: timescale property must be non-zero");
1331
- c = v;
1332
- }
1333
- } else {
1334
- const [v, _] = A.Varint.decode(l);
1335
- if (_.byteLength < v)
1336
- throw new Error("loc: property length exceeds remaining bytes");
1337
- l = _.subarray(v);
1338
- }
1339
- }
1340
- if (o === void 0)
1341
- throw new Error("loc: frame missing required timestamp property");
1342
- const d = c ?? Ke, f = Math.round(o * Ke / d);
1343
- return [{ data: r, timestamp: f, keyframe: !1 }];
1344
- }
1345
- };
1346
- function It(t) {
1347
- return t instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && t instanceof SharedArrayBuffer;
1348
- }
1349
- const Rs = "utf-16", Ee = "utf-16be", Je = "utf-16le", de = "utf-8";
1350
- function Dt(t, e = {}) {
1351
- let n;
1352
- It(t) ? n = new DataView(t) : n = new DataView(t.buffer, t.byteOffset, t.byteLength);
1353
- let s = 0, { encoding: i } = e;
1354
- if (!i) {
1355
- const u = n.getUint8(0), l = n.getUint8(1);
1356
- u == 239 && l == 187 && n.getUint8(2) == 191 ? (i = de, s = 3) : u == 254 && l == 255 ? (i = Ee, s = 2) : u == 255 && l == 254 ? (i = Je, s = 2) : i = de;
1357
- }
1358
- if (typeof TextDecoder < "u") return new TextDecoder(i).decode(n);
1359
- const { byteLength: r } = n, o = i !== Ee;
1360
- let c = "", a;
1361
- for (; s < r; ) {
1362
- switch (i) {
1363
- case de:
1364
- if (a = n.getUint8(s), a < 128) s++;
1365
- else if (a >= 194 && a <= 223) if (s + 1 < r) {
1366
- const u = n.getUint8(s + 1);
1367
- u >= 128 && u <= 191 ? (a = (a & 31) << 6 | u & 63, s += 2) : s++;
1368
- } else s++;
1369
- else if (a >= 224 && a <= 239) if (s + 2 <= r - 1) {
1370
- const u = n.getUint8(s + 1), l = n.getUint8(s + 2);
1371
- u >= 128 && u <= 191 && l >= 128 && l <= 191 ? (a = (a & 15) << 12 | (u & 63) << 6 | l & 63, s += 3) : s++;
1372
- } else s++;
1373
- else if (a >= 240 && a <= 244) if (s + 3 <= r - 1) {
1374
- const u = n.getUint8(s + 1), l = n.getUint8(s + 2), d = n.getUint8(s + 3);
1375
- u >= 128 && u <= 191 && l >= 128 && l <= 191 && d >= 128 && d <= 191 ? (a = (a & 7) << 18 | (u & 63) << 12 | (l & 63) << 6 | d & 63, s += 4) : s++;
1376
- } else s++;
1377
- else s++;
1378
- break;
1379
- case Ee:
1380
- case Rs:
1381
- case Je:
1382
- a = n.getUint16(s, o), s += 2;
1383
- break;
1384
- }
1385
- c += String.fromCodePoint(a);
1386
- }
1387
- return c;
1388
- }
1389
- function Cs(t) {
1390
- return new TextEncoder().encode(t);
1391
- }
1392
- function Is(t) {
1393
- return { writers: t?.writers ?? {} };
1394
- }
1395
- const Ds = [
1396
- "dinf",
1397
- "edts",
1398
- "grpl",
1399
- "mdia",
1400
- "meco",
1401
- "mfra",
1402
- "minf",
1403
- "moof",
1404
- "moov",
1405
- "mvex",
1406
- "schi",
1407
- "sinf",
1408
- "stbl",
1409
- "strk",
1410
- "traf",
1411
- "trak",
1412
- "tref",
1413
- "udta",
1414
- "vttc"
1415
- ];
1416
- function Ot(t) {
1417
- return "boxes" in t || Ds.includes(t.type);
1418
- }
1419
- const Qe = "utf8", R = "uint", ne = "template", et = "string", tt = "int", nt = "data";
1420
- var T = class {
1421
- /**
1422
- * Constructs a new IsoBoxWriteView.
1423
- *
1424
- * @param size - The size of the data view.
1425
- */
1426
- constructor(t, e) {
1427
- this.writeUint = (n, s) => {
1428
- const { dataView: i, cursor: r } = this;
1429
- switch (s) {
1430
- case 1:
1431
- i.setUint8(r, n);
1432
- break;
1433
- case 2:
1434
- i.setUint16(r, n);
1435
- break;
1436
- case 3: {
1437
- const o = (n & 16776960) >> 8, c = n & 255;
1438
- i.setUint16(r, o), i.setUint8(r + 2, c);
1439
- break;
1440
- }
1441
- case 4:
1442
- i.setUint32(r, n);
1443
- break;
1444
- case 8: {
1445
- const o = Math.floor(n / Math.pow(2, 32)), c = n - o * Math.pow(2, 32);
1446
- i.setUint32(r, o), i.setUint32(r + 4, c);
1447
- break;
1448
- }
1449
- }
1450
- this.cursor += s;
1451
- }, this.writeInt = (n, s) => {
1452
- const { dataView: i, cursor: r } = this;
1453
- switch (s) {
1454
- case 1:
1455
- i.setInt8(r, n);
1456
- break;
1457
- case 2:
1458
- i.setInt16(r, n);
1459
- break;
1460
- case 4:
1461
- i.setInt32(r, n);
1462
- break;
1463
- case 8:
1464
- const o = Math.floor(n / Math.pow(2, 32)), c = n - o * Math.pow(2, 32);
1465
- i.setUint32(r, o), i.setUint32(r + 4, c);
1466
- break;
1467
- }
1468
- this.cursor += s;
1469
- }, this.writeString = (n) => {
1470
- for (let s = 0, i = n.length; s < i; s++) this.writeUint(n.charCodeAt(s), 1);
1471
- }, this.writeTerminatedString = (n) => {
1472
- if (n.length !== 0) {
1473
- for (let s = 0, i = n.length; s < i; s++) this.writeUint(n.charCodeAt(s), 1);
1474
- this.writeUint(0, 1);
1475
- }
1476
- }, this.writeUtf8TerminatedString = (n) => {
1477
- const s = Cs(n);
1478
- new Uint8Array(this.dataView.buffer).set(s, this.cursor), this.cursor += s.length, this.writeUint(0, 1);
1479
- }, this.writeBytes = (n) => {
1480
- Array.isArray(n) || (n = [n]);
1481
- for (const s of n)
1482
- new Uint8Array(this.dataView.buffer).set(s, this.cursor), this.cursor += s.length;
1483
- }, this.writeArray = (n, s, i, r) => {
1484
- const o = s === R ? this.writeUint : s === ne ? this.writeTemplate : this.writeInt;
1485
- for (let c = 0; c < r; c++) o(n[c] ?? 0, i);
1486
- }, this.writeTemplate = (n, s) => {
1487
- const r = Math.round(n * Math.pow(2, s === 4 ? 16 : 8));
1488
- this.writeUint(r, s);
1489
- }, this.writeBoxHeader = (n, s) => {
1490
- s > 4294967295 ? (this.writeUint(1, 4), this.writeString(n), this.writeUint(s, 8)) : (this.writeUint(s, 4), this.writeString(n));
1491
- }, this.dataView = new DataView(new ArrayBuffer(e)), this.cursor = 0, this.writeBoxHeader(t, e);
1492
- }
1493
- /**
1494
- * The buffer of the data view.
1495
- *
1496
- * @returns The buffer of the data view.
1497
- */
1498
- get buffer() {
1499
- return this.dataView.buffer;
1500
- }
1501
- /**
1502
- * The length of the data view.
1503
- *
1504
- * @returns The length of the data view.
1505
- */
1506
- get byteLength() {
1507
- return this.dataView.byteLength;
1508
- }
1509
- /**
1510
- * The offset of the data view.
1511
- *
1512
- * @returns The offset of the data view.
1513
- */
1514
- get byteOffset() {
1515
- return this.dataView.byteOffset;
1516
- }
1517
- /**
1518
- * Writes a full box header to the data view.
1519
- *
1520
- * @param version - The version of the full box.
1521
- * @param flags - The flags of the full box.
1522
- */
1523
- writeFullBox(t, e) {
1524
- this.writeUint(t, 1), this.writeUint(e, 3);
1525
- }
1526
- };
1527
- function Lt(t, e) {
1528
- return Array.from(t, (n) => Ls(n, e));
1529
- }
1530
- function Oe(t, e) {
1531
- const n = Lt(t, e);
1532
- return {
1533
- bytes: n,
1534
- size: n.reduce((s, i) => s + i.byteLength, 0)
1535
- };
1536
- }
1537
- function Os(t, e) {
1538
- const { bytes: s, size: i } = Oe(t.boxes, e), r = 8 + i, o = new T(t.type, r);
1539
- return o.writeBytes(s), o;
1540
- }
1541
- function Ls(t, e) {
1542
- let n = null;
1543
- if ("type" in t) {
1544
- const { type: s } = t, i = e.writers?.[s];
1545
- if (i ? n = i(t, e) : Ot(t) ? n = Os(t, e) : "view" in t && (n = t.view), !n) throw new Error(`No writer found for box type: ${s}`);
1546
- }
1547
- if ("buffer" in t && (n = t), !n) throw new Error("Invalid box");
1548
- return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
1549
- }
1550
- function Fs(t, e, n) {
1551
- const s = n > 0 ? n : t.byteLength - (e - t.byteOffset);
1552
- return new Uint8Array(t.buffer, e, Math.max(s, 0));
1553
- }
1554
- function $s(t, e, n) {
1555
- let s = NaN;
1556
- const i = e - t.byteOffset;
1557
- switch (n) {
1558
- case 1:
1559
- s = t.getInt8(i);
1560
- break;
1561
- case 2:
1562
- s = t.getInt16(i);
1563
- break;
1564
- case 4:
1565
- s = t.getInt32(i);
1566
- break;
1567
- case 8:
1568
- const r = t.getInt32(i), o = t.getInt32(i + 4);
1569
- s = r * Math.pow(2, 32) + o;
1570
- break;
1571
- }
1572
- return s;
1573
- }
1574
- function Y(t, e, n) {
1575
- const s = e - t.byteOffset;
1576
- let i = NaN, r, o;
1577
- switch (n) {
1578
- case 1:
1579
- i = t.getUint8(s);
1580
- break;
1581
- case 2:
1582
- i = t.getUint16(s);
1583
- break;
1584
- case 3:
1585
- r = t.getUint16(s), o = t.getUint8(s + 2), i = (r << 8) + o;
1586
- break;
1587
- case 4:
1588
- i = t.getUint32(s);
1589
- break;
1590
- case 8:
1591
- r = t.getUint32(s), o = t.getUint32(s + 4), i = r * Math.pow(2, 32) + o;
1592
- break;
1593
- }
1594
- return i;
1595
- }
1596
- function st(t, e, n) {
1597
- let s = "";
1598
- for (let i = 0; i < n; i++) {
1599
- const r = Y(t, e + i, 1);
1600
- s += String.fromCharCode(r);
1601
- }
1602
- return s;
1603
- }
1604
- function Ps(t, e, n) {
1605
- const s = n / 2;
1606
- return Y(t, e, s) + Y(t, e + s, s) / Math.pow(2, s);
1607
- }
1608
- function Ns(t, e) {
1609
- let n = "", s = e;
1610
- for (; s - t.byteOffset < t.byteLength; ) {
1611
- const i = Y(t, s, 1);
1612
- if (i === 0) break;
1613
- n += String.fromCharCode(i), s++;
1614
- }
1615
- return n;
1616
- }
1617
- function js(t, e) {
1618
- const n = t.byteLength - (e - t.byteOffset);
1619
- return n > 0 ? Dt(new DataView(t.buffer, e, n), { encoding: de }) : "";
1620
- }
1621
- function Zs(t, e) {
1622
- const n = t.byteLength - (e - t.byteOffset);
1623
- let s = "";
1624
- if (n > 0) {
1625
- const i = new DataView(t.buffer, e, n);
1626
- let r = 0;
1627
- for (; r < n && i.getUint8(r) !== 0; r++) ;
1628
- s = Dt(new DataView(t.buffer, e, r), { encoding: de });
1629
- }
1630
- return s;
1631
- }
1632
- var Vs = class Ft {
1633
- /**
1634
- * Creates a new IsoView instance. Similar to DataView, but with additional
1635
- * methods for reading ISO BMFF data. It implements the iterator protocol,
1636
- * so it can be used in a for...of loop.
1637
- *
1638
- * @param raw - The raw data to view.
1639
- * @param config - The configuration for the IsoView.
1640
- */
1641
- constructor(e, n) {
1642
- this.truncated = !1, this.slice = (s, i) => {
1643
- const r = new Ft(new DataView(this.dataView.buffer, s, i), this.config), o = this.offset - s, c = i - o;
1644
- return this.offset += c, r.jump(o), r;
1645
- }, this.read = (s, i = 0) => {
1646
- const { dataView: r, offset: o } = this;
1647
- let c, a = i;
1648
- switch (s) {
1649
- case R:
1650
- c = Y(r, o, i);
1651
- break;
1652
- case tt:
1653
- c = $s(r, o, i);
1654
- break;
1655
- case ne:
1656
- c = Ps(r, o, i);
1657
- break;
1658
- case et:
1659
- i === -1 ? (c = Ns(r, o), a = c.length + 1) : c = st(r, o, i);
1660
- break;
1661
- case nt:
1662
- c = Fs(r, o, i), a = c.length;
1663
- break;
1664
- case Qe:
1665
- i === -1 ? (c = Zs(r, o), a = c.length + 1) : c = js(r, o);
1666
- break;
1667
- default:
1668
- c = -1;
1669
- }
1670
- return this.offset += a, c;
1671
- }, this.readUint = (s) => this.read(R, s), this.readInt = (s) => this.read(tt, s), this.readString = (s) => this.read(et, s), this.readTemplate = (s) => this.read(ne, s), this.readData = (s) => this.read(nt, s), this.readUtf8 = (s) => this.read(Qe, s), this.readFullBox = () => ({
1672
- version: this.readUint(1),
1673
- flags: this.readUint(3)
1674
- }), this.readArray = (s, i, r) => {
1675
- const o = [];
1676
- for (let c = 0; c < r; c++) o.push(this.read(s, i));
1677
- return o;
1678
- }, this.jump = (s) => {
1679
- this.offset += s;
1680
- }, this.readBox = () => {
1681
- const { dataView: s, offset: i } = this;
1682
- let r = 0;
1683
- const o = Y(s, i, 4), c = st(s, i + 4, 4), a = {
1684
- size: o,
1685
- type: c
1686
- };
1687
- r += 8, a.size === 1 && (a.largesize = Y(s, i + r, 8), r += 8);
1688
- const u = a.size === 0 ? this.bytesRemaining : a.largesize ?? a.size;
1689
- if (this.cursor + u > s.byteLength)
1690
- throw this.truncated = !0, new Error("Truncated box");
1691
- return this.jump(r), c === "uuid" && (a.usertype = this.readArray("uint", 1, 16)), a.view = this.slice(i, u), a;
1692
- }, this.readBoxes = (s = -1) => {
1693
- const i = [];
1694
- for (const r of this)
1695
- if (i.push(r), s > 0 && i.length >= s) break;
1696
- return i;
1697
- }, this.readEntries = (s, i) => {
1698
- const r = [];
1699
- for (let o = 0; o < s; o++) r.push(i());
1700
- return r;
1701
- }, this.dataView = It(e) ? new DataView(e) : e instanceof DataView ? e : new DataView(e.buffer, e.byteOffset, e.byteLength), this.offset = this.dataView.byteOffset, this.config = n || {};
1702
- }
1703
- /**
1704
- * The buffer of the data view.
1705
- */
1706
- get buffer() {
1707
- return this.dataView.buffer;
1708
- }
1709
- /**
1710
- * The byte offset of the data view.
1711
- */
1712
- get byteOffset() {
1713
- return this.dataView.byteOffset;
1714
- }
1715
- /**
1716
- * The byte length of the data view.
1717
- */
1718
- get byteLength() {
1719
- return this.dataView.byteLength;
1720
- }
1721
- /**
1722
- * The current byteoffset in the data view.
1723
- */
1724
- get cursor() {
1725
- return this.offset - this.dataView.byteOffset;
1726
- }
1727
- /**
1728
- * Whether the end of the data view has been reached.
1729
- */
1730
- get done() {
1731
- return this.cursor >= this.dataView.byteLength || this.truncated;
1732
- }
1733
- /**
1734
- * The number of bytes remaining in the data view.
1735
- */
1736
- get bytesRemaining() {
1737
- return this.dataView.byteLength - this.cursor;
1738
- }
1739
- /**
1740
- * Iterates over the boxes in the data view.
1741
- *
1742
- * @returns A generator of boxes.
1743
- */
1744
- *[Symbol.iterator]() {
1745
- const { readers: e = {} } = this.config;
1746
- for (; !this.done; ) try {
1747
- const n = this.readBox(), { type: s, view: i } = n, r = e[s] || e[s.trim()];
1748
- if (r && Object.assign(n, r(i, s)), Ot(n) && !n.boxes) {
1749
- const o = [];
1750
- for (const c of i) o.push(c);
1751
- n.boxes = o;
1752
- }
1753
- yield n;
1754
- } catch (n) {
1755
- if (n instanceof Error && n.message === "Truncated box") break;
1756
- throw n;
1757
- }
1758
- }
1759
- };
1760
- function Le(t, e) {
1761
- const n = [];
1762
- for (const s of new Vs(t, e)) n.push(s);
1763
- return n;
1764
- }
1765
- function Ws(t, e) {
1766
- return Lt(t, Is(e));
1767
- }
1768
- function qs(t, e) {
1769
- const { readArray: n, readUint: s, readTemplate: i, readBoxes: r } = e;
1770
- return {
1771
- type: t,
1772
- reserved1: n(R, 1, 6),
1773
- dataReferenceIndex: s(2),
1774
- reserved2: n(R, 4, 2),
1775
- channelcount: s(2),
1776
- samplesize: s(2),
1777
- preDefined: s(2),
1778
- reserved3: s(2),
1779
- samplerate: i(4),
1780
- boxes: r()
1781
- };
1782
- }
1783
- function Fe(t, e) {
1784
- const { readArray: n, readUint: s, readInt: i, readTemplate: r, readBoxes: o } = e;
1785
- return {
1786
- type: t,
1787
- reserved1: n(R, 1, 6),
1788
- dataReferenceIndex: s(2),
1789
- preDefined1: s(2),
1790
- reserved2: s(2),
1791
- preDefined2: n(R, 4, 3),
1792
- width: s(2),
1793
- height: s(2),
1794
- horizresolution: r(4),
1795
- vertresolution: r(4),
1796
- reserved3: s(4),
1797
- frameCount: s(2),
1798
- compressorName: n(R, 1, 32),
1799
- depth: s(2),
1800
- preDefined3: i(2),
1801
- boxes: o()
1802
- };
1803
- }
1804
- function it(t) {
1805
- return Fe("avc1", t);
1806
- }
1807
- function Hs(t) {
1808
- return Fe("hev1", t);
1809
- }
1810
- function Gs(t) {
1811
- return Fe("hvc1", t);
1812
- }
1813
- function Xs(t) {
1814
- return {
1815
- type: "mdat",
1816
- data: t.readData(-1)
1817
- };
1818
- }
1819
- function Ys(t) {
1820
- const { version: e, flags: n } = t.readFullBox(), s = t.readUint(e == 1 ? 8 : 4), i = t.readUint(e == 1 ? 8 : 4), r = t.readUint(4), o = t.readUint(e == 1 ? 8 : 4), c = t.readUint(2);
1821
- return {
1822
- type: "mdhd",
1823
- version: e,
1824
- flags: n,
1825
- creationTime: s,
1826
- modificationTime: i,
1827
- timescale: r,
1828
- duration: o,
1829
- language: String.fromCharCode((c >> 10 & 31) + 96, (c >> 5 & 31) + 96, (c & 31) + 96),
1830
- preDefined: t.readUint(2)
1831
- };
1832
- }
1833
- function Ks(t) {
1834
- return {
1835
- type: "mfhd",
1836
- ...t.readFullBox(),
1837
- sequenceNumber: t.readUint(4)
1838
- };
1839
- }
1840
- function Js(t) {
1841
- return qs("mp4a", t);
1842
- }
1843
- function Qs(t) {
1844
- const { version: e, flags: n } = t.readFullBox(), s = t.readUint(4);
1845
- return {
1846
- type: "stsd",
1847
- version: e,
1848
- flags: n,
1849
- entryCount: s,
1850
- entries: t.readBoxes(s)
1851
- };
1852
- }
1853
- function ei(t) {
1854
- const { version: e, flags: n } = t.readFullBox();
1855
- return {
1856
- type: "tfdt",
1857
- version: e,
1858
- flags: n,
1859
- baseMediaDecodeTime: t.readUint(e == 1 ? 8 : 4)
1860
- };
1861
- }
1862
- function ti(t) {
1863
- const { version: e, flags: n } = t.readFullBox();
1864
- return {
1865
- type: "tfhd",
1866
- version: e,
1867
- flags: n,
1868
- trackId: t.readUint(4),
1869
- baseDataOffset: n & 1 ? t.readUint(8) : void 0,
1870
- sampleDescriptionIndex: n & 2 ? t.readUint(4) : void 0,
1871
- defaultSampleDuration: n & 8 ? t.readUint(4) : void 0,
1872
- defaultSampleSize: n & 16 ? t.readUint(4) : void 0,
1873
- defaultSampleFlags: n & 32 ? t.readUint(4) : void 0
1874
- };
1875
- }
1876
- function ni(t) {
1877
- const { version: e, flags: n } = t.readFullBox(), s = e === 1 ? 8 : 4;
1878
- return {
1879
- type: "tkhd",
1880
- version: e,
1881
- flags: n,
1882
- creationTime: t.readUint(s),
1883
- modificationTime: t.readUint(s),
1884
- trackId: t.readUint(4),
1885
- reserved1: t.readUint(4),
1886
- duration: t.readUint(s),
1887
- reserved2: t.readArray(R, 4, 2),
1888
- layer: t.readUint(2),
1889
- alternateGroup: t.readUint(2),
1890
- volume: t.readTemplate(2),
1891
- reserved3: t.readUint(2),
1892
- matrix: t.readArray(ne, 4, 9),
1893
- width: t.readTemplate(4),
1894
- height: t.readTemplate(4)
1895
- };
1896
- }
1897
- function si(t) {
1898
- return {
1899
- type: "trex",
1900
- ...t.readFullBox(),
1901
- trackId: t.readUint(4),
1902
- defaultSampleDescriptionIndex: t.readUint(4),
1903
- defaultSampleDuration: t.readUint(4),
1904
- defaultSampleSize: t.readUint(4),
1905
- defaultSampleFlags: t.readUint(4)
1906
- };
1907
- }
1908
- function ii(t) {
1909
- const { version: e, flags: n } = t.readFullBox(), s = t.readUint(4);
1910
- let i, r;
1911
- n & 1 && (i = t.readInt(4)), n & 4 && (r = t.readUint(4));
1912
- const o = t.readEntries(s, () => {
1913
- const c = {};
1914
- return n & 256 && (c.sampleDuration = t.readUint(4)), n & 512 && (c.sampleSize = t.readUint(4)), n & 1024 && (c.sampleFlags = t.readUint(4)), n & 2048 && (c.sampleCompositionTimeOffset = e === 1 ? t.readInt(4) : t.readUint(4)), c;
1915
- });
1916
- return {
1917
- type: "trun",
1918
- version: e,
1919
- flags: n,
1920
- sampleCount: s,
1921
- dataOffset: i,
1922
- firstSampleFlags: r,
1923
- samples: o
1924
- };
1925
- }
1926
- function ri(t, e) {
1927
- const r = t.entries.length, { bytes: o, size: c } = Oe(t.entries, e), a = new T("dref", 16 + c);
1928
- return a.writeFullBox(t.version, t.flags), a.writeUint(r, 4), a.writeBytes(o), a;
1929
- }
1930
- function oi(t) {
1931
- const i = t.compatibleBrands.length * 4, r = new T("ftyp", 16 + i);
1932
- r.writeString(t.majorBrand), r.writeUint(t.minorVersion, 4);
1933
- for (const o of t.compatibleBrands) r.writeString(o);
1934
- return r;
1935
- }
1936
- function ai(t) {
1937
- const o = t.name.length + 1, c = new T("hdlr", 32 + o);
1938
- return c.writeFullBox(t.version, t.flags), c.writeUint(t.preDefined, 4), c.writeString(t.handlerType), c.writeArray(t.reserved, R, 4, 3), c.writeTerminatedString(t.name), c;
1939
- }
1940
- function ci(t) {
1941
- const e = new T("mdat", 8 + t.data.length);
1942
- return e.writeBytes(t.data), e;
1943
- }
1944
- function ui(t) {
1945
- const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new T("mdhd", n + s + i + 4 + 2 + 2);
1946
- r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.timescale, 4), r.writeUint(t.duration, e);
1947
- const o = t.language.length >= 3 ? (t.language.charCodeAt(0) - 96 & 31) << 10 | (t.language.charCodeAt(1) - 96 & 31) << 5 | t.language.charCodeAt(2) - 96 & 31 : 0;
1948
- return r.writeUint(o, 2), r.writeUint(t.preDefined, 2), r;
1949
- }
1950
- function li(t) {
1951
- const e = new T("mfhd", 16);
1952
- return e.writeFullBox(t.version, t.flags), e.writeUint(t.sequenceNumber, 4), e;
1953
- }
1954
- function di(t) {
1955
- const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new T("mvhd", n + s + i + 4 + 4 + 2 + 2 + 8 + 36 + 24 + 4);
1956
- return r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.timescale, 4), r.writeUint(t.duration, e), r.writeTemplate(t.rate, 4), r.writeTemplate(t.volume, 2), r.writeUint(t.reserved1, 2), r.writeArray(t.reserved2, R, 4, 2), r.writeArray(t.matrix, ne, 4, 9), r.writeArray(t.preDefined, R, 4, 6), r.writeUint(t.nextTrackId, 4), r;
1957
- }
1958
- function hi(t) {
1959
- const e = new T("smhd", 16);
1960
- return e.writeFullBox(t.version, t.flags), e.writeUint(t.balance, 2), e.writeUint(t.reserved, 2), e;
1961
- }
1962
- function fi(t, e) {
1963
- const r = t.entries.length, { bytes: o, size: c } = Oe(t.entries, e), a = new T("stsd", 16 + c);
1964
- return a.writeFullBox(t.version, t.flags), a.writeUint(r, 4), a.writeBytes(o), a;
1965
- }
1966
- function mi(t) {
1967
- const i = t.entryCount * 8, r = new T("stts", 16 + i);
1968
- r.writeFullBox(t.version, t.flags), r.writeUint(t.entryCount, 4);
1969
- for (const o of t.entries)
1970
- r.writeUint(o.sampleCount, 4), r.writeUint(o.sampleDelta, 4);
1971
- return r;
1972
- }
1973
- function pi(t) {
1974
- const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e, r = new T("tfdt", n + s + i);
1975
- return r.writeFullBox(t.version, t.flags), r.writeUint(t.baseMediaDecodeTime, e), r;
1976
- }
1977
- function gi(t) {
1978
- const i = t.flags & 1 ? 8 : 0, r = t.flags & 2 ? 4 : 0, o = t.flags & 8 ? 4 : 0, c = t.flags & 16 ? 4 : 0, a = t.flags & 32 ? 4 : 0, u = new T("tfhd", 16 + i + r + o + c + a);
1979
- return u.writeFullBox(t.version, t.flags), u.writeUint(t.trackId, 4), t.flags & 1 && u.writeUint(t.baseDataOffset ?? 0, 8), t.flags & 2 && u.writeUint(t.sampleDescriptionIndex ?? 0, 4), t.flags & 8 && u.writeUint(t.defaultSampleDuration ?? 0, 4), t.flags & 16 && u.writeUint(t.defaultSampleSize ?? 0, 4), t.flags & 32 && u.writeUint(t.defaultSampleFlags ?? 0, 4), u;
1980
- }
1981
- function wi(t) {
1982
- const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new T("tkhd", n + s + i + 4 + 4 + 8 + 2 + 2 + 2 + 2 + 36 + 4 + 4);
1983
- return r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.trackId, 4), r.writeUint(t.reserved1, 4), r.writeUint(t.duration, e), r.writeArray(t.reserved2, R, 4, 2), r.writeUint(t.layer, 2), r.writeUint(t.alternateGroup, 2), r.writeTemplate(t.volume, 2), r.writeUint(t.reserved3, 2), r.writeArray(t.matrix, ne, 4, 9), r.writeTemplate(t.width, 4), r.writeTemplate(t.height, 4), r;
1984
- }
1985
- function yi(t) {
1986
- const e = new T("trex", 32);
1987
- return e.writeFullBox(t.version, t.flags), e.writeUint(t.trackId, 4), e.writeUint(t.defaultSampleDescriptionIndex, 4), e.writeUint(t.defaultSampleDuration, 4), e.writeUint(t.defaultSampleSize, 4), e.writeUint(t.defaultSampleFlags, 4), e;
1988
- }
1989
- function bi(t) {
1990
- const i = t.flags & 1 ? 4 : 0, r = t.flags & 4 ? 4 : 0;
1991
- let o = 0;
1992
- t.flags & 256 && (o += 4), t.flags & 512 && (o += 4), t.flags & 1024 && (o += 4), t.flags & 2048 && (o += 4);
1993
- const c = o * t.sampleCount, a = new T("trun", 16 + i + r + c);
1994
- a.writeFullBox(t.version, t.flags), a.writeUint(t.sampleCount, 4), t.flags & 1 && a.writeUint(t.dataOffset ?? 0, 4), t.flags & 4 && a.writeUint(t.firstSampleFlags ?? 0, 4);
1995
- for (const u of t.samples)
1996
- t.flags & 256 && a.writeUint(u.sampleDuration ?? 0, 4), t.flags & 512 && a.writeUint(u.sampleSize ?? 0, 4), t.flags & 1024 && a.writeUint(u.sampleFlags ?? 0, 4), t.flags & 2048 && a.writeUint(u.sampleCompositionTimeOffset ?? 0, 4);
1997
- return a;
1998
- }
1999
- function vi(t) {
2000
- const s = t.location.length + 1, i = new T("url ", 12 + s);
2001
- return i.writeFullBox(t.version, t.flags), i.writeTerminatedString(t.location), i;
2002
- }
2003
- function Si(t) {
2004
- const e = new T("vmhd", 20);
2005
- return e.writeFullBox(t.version, t.flags), e.writeUint(t.graphicsmode, 2), e.writeArray(t.opcolor, R, 2, 3), e;
2006
- }
2007
- const Ai = {
2008
- avc1: it,
2009
- avc3: it,
2010
- // avc3 has same structure
2011
- hvc1: Gs,
2012
- hev1: Hs,
2013
- mp4a: Js,
2014
- stsd: Qs,
2015
- mdhd: Ys,
2016
- tkhd: ni,
2017
- trex: si
2018
- }, $t = {
2019
- mfhd: Ks,
2020
- tfhd: ti,
2021
- tfdt: ei,
2022
- trun: ii,
2023
- mdat: Xs
2024
- };
2025
- function L(t, e) {
2026
- for (const n of t) {
2027
- if (e(n))
2028
- return n;
2029
- const s = n.boxes;
2030
- if (s && Array.isArray(s)) {
2031
- const i = L(s, e);
2032
- if (i) return i;
2033
- }
2034
- }
2035
- }
2036
- function $e(t) {
2037
- const e = new ArrayBuffer(t.byteLength);
2038
- return new Uint8Array(e).set(t), e;
2039
- }
2040
- function W(t) {
2041
- return (e) => e.type === t;
2042
- }
2043
- function oe(t) {
2044
- const e = Le($e(t), { readers: Ai }), n = L(e, W("mdhd"));
2045
- if (!n)
2046
- throw new Error("No mdhd box found in init segment");
2047
- const i = L(e, W("tkhd"))?.trackId ?? 1, r = L(e, W("stsd"));
2048
- if (!r?.entries || r.entries.length === 0)
2049
- throw new Error("No stsd box found in init segment");
2050
- const o = r.entries[0], c = _i(o), a = L(
2051
- e,
2052
- (u) => u.type === "trex" && u.trackId === i
2053
- );
2054
- return {
2055
- description: c,
2056
- timescale: n.timescale,
2057
- trackId: i,
2058
- defaultSampleDuration: a?.defaultSampleDuration ?? 0,
2059
- defaultSampleSize: a?.defaultSampleSize ?? 0,
2060
- defaultSampleFlags: a?.defaultSampleFlags ?? 0
2061
- };
2062
- }
2063
- function _i(t) {
2064
- if (!(!t.boxes || !Array.isArray(t.boxes)))
2065
- for (const e of t.boxes) {
2066
- if (e instanceof Uint8Array) {
2067
- if (e.length > 8) {
2068
- const s = String.fromCharCode(e[4], e[5], e[6], e[7]);
2069
- if (s === "avcC" || s === "hvcC" || s === "dOps")
2070
- return new Uint8Array(e.slice(8));
2071
- if (s === "esds")
2072
- return rt(new Uint8Array(e.slice(8)));
2073
- }
2074
- continue;
2075
- }
2076
- const n = e.type;
2077
- if (n === "avcC" || n === "hvcC" || n === "dOps") {
2078
- if (e.view) {
2079
- const s = e.view, i = 8, r = s.byteOffset + i, o = e.size - i;
2080
- return new Uint8Array(s.buffer, r, o);
2081
- }
2082
- if (e.data instanceof Uint8Array)
2083
- return new Uint8Array(e.data);
2084
- if (e.raw instanceof Uint8Array)
2085
- return new Uint8Array(e.raw.slice(8));
2086
- }
2087
- if (n === "esds") {
2088
- let s;
2089
- if (e.view) {
2090
- const i = e.view, r = 8;
2091
- s = new Uint8Array(i.buffer, i.byteOffset + r, e.size - r);
2092
- } else e.data instanceof Uint8Array ? s = new Uint8Array(e.data) : e.raw instanceof Uint8Array && (s = new Uint8Array(e.raw.slice(8)));
2093
- if (s) return rt(s);
2094
- }
2095
- }
2096
- }
2097
- function rt(t) {
2098
- let e = 4;
2099
- for (; e < t.length; ) {
2100
- const n = t[e++];
2101
- let s = 0;
2102
- for (let i = 0; i < 4 && e < t.length; i++) {
2103
- const r = t[e++];
2104
- if (s = s << 7 | r & 127, (r & 128) === 0) break;
2105
- }
2106
- if (n === 5)
2107
- return e + s <= t.length ? new Uint8Array(t.buffer, t.byteOffset + e, s) : void 0;
2108
- n === 3 ? e += 3 : n === 4 ? e += 13 : e += s;
2109
- }
2110
- }
2111
- function Pt(t, e) {
2112
- const n = Le($e(t), { readers: $t });
2113
- return (L(n, W("tfdt"))?.baseMediaDecodeTime ?? 0) * 1e6 / e.timescale;
2114
- }
2115
- function zi(t, e) {
2116
- const n = Le($e(t), { readers: $t }), i = L(n, W("tfdt"))?.baseMediaDecodeTime ?? 0, r = L(n, W("tfhd")), o = r?.defaultSampleDuration ?? e.defaultSampleDuration, c = r?.defaultSampleSize ?? e.defaultSampleSize, a = r?.defaultSampleFlags ?? e.defaultSampleFlags, u = L(n, W("trun"));
2117
- if (!u)
2118
- throw new Error("No trun box found in data segment");
2119
- const l = L(n, W("mdat"));
2120
- if (!l)
2121
- throw new Error("No mdat box found in data segment");
2122
- const d = l.data;
2123
- if (!d)
2124
- throw new Error("No data in mdat box");
2125
- const f = [];
2126
- let p = 0, b = i;
2127
- for (let w = 0; w < u.sampleCount; w++) {
2128
- const v = u.samples[w] ?? {}, _ = v.sampleSize ?? c, M = v.sampleDuration ?? o;
2129
- if (_ <= 0)
2130
- throw new Error(`Invalid sample size ${_} for sample ${w} in trun`);
2131
- if (M < 0)
2132
- throw new Error(`Invalid sample duration ${M} for sample ${w} in trun`);
2133
- if (p + _ > d.length)
2134
- throw new Error(
2135
- `Sample ${w} would overflow mdat: offset=${p}, size=${_}, mdatLength=${d.length}`
2136
- );
2137
- const H = w === 0 && u.firstSampleFlags !== void 0 ? u.firstSampleFlags : v.sampleFlags ?? a, P = v.sampleCompositionTimeOffset ?? 0, G = new Uint8Array(d.slice(p, p + _));
2138
- p += _;
2139
- const X = b + P, N = Math.round(X * 1e6 / e.timescale), k = H === 0 || (H & 65536) === 0;
2140
- f.push({
2141
- data: G,
2142
- timestamp: N,
2143
- keyframe: k
2144
- }), b += M;
2145
- }
2146
- return f;
2147
- }
2148
- function $(t) {
2149
- if (t = t.startsWith("0x") ? t.slice(2) : t, t.length % 2)
2150
- throw new Error("invalid hex string length");
2151
- const e = t.match(/.{2}/g);
2152
- if (!e)
2153
- throw new Error("invalid hex string format");
2154
- return new Uint8Array(e.map((n) => parseInt(n, 16)));
2155
- }
2156
- const Se = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824], Mi = {
2157
- // Init segment boxes
2158
- ftyp: oi,
2159
- mvhd: di,
2160
- tkhd: wi,
2161
- mdhd: ui,
2162
- hdlr: ai,
2163
- vmhd: Si,
2164
- smhd: hi,
2165
- "url ": vi,
2166
- dref: ri,
2167
- stsd: fi,
2168
- stts: mi,
2169
- trex: yi,
2170
- // Data segment boxes
2171
- mfhd: li,
2172
- tfhd: gi,
2173
- tfdt: pi,
2174
- trun: bi,
2175
- mdat: ci
2176
- // For boxes without library writers, we create them manually as Uint8Arrays
2177
- };
2178
- function he(t) {
2179
- return Ws(t, { writers: Mi });
2180
- }
2181
- function Pe(t, e, n, s) {
2182
- const i = 12 + s.length, r = new Uint8Array(i), o = new DataView(r.buffer);
2183
- return o.setUint32(0, i, !1), r[4] = t.charCodeAt(0), r[5] = t.charCodeAt(1), r[6] = t.charCodeAt(2), r[7] = t.charCodeAt(3), o.setUint32(8, e << 24 | n, !1), r.set(s, 12), r;
2184
- }
2185
- function Nt() {
2186
- const t = new Uint8Array(4);
2187
- return Pe("stsc", 0, 0, t);
2188
- }
2189
- function jt() {
2190
- const t = new Uint8Array(8);
2191
- return Pe("stsz", 0, 0, t);
2192
- }
2193
- function Zt() {
2194
- const t = new Uint8Array(4);
2195
- return Pe("stco", 0, 0, t);
2196
- }
2197
- function ki(t, e, n) {
2198
- const s = 8 + n.length, r = 8 + (78 + s), o = new Uint8Array(r), c = new DataView(o.buffer);
2199
- let a = 0;
2200
- return c.setUint32(a, r, !1), a += 4, o[a++] = 97, o[a++] = 118, o[a++] = 99, o[a++] = 49, a += 6, c.setUint16(a, 1, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, a += 12, c.setUint16(a, t, !1), a += 2, c.setUint16(a, e, !1), a += 2, c.setUint32(a, 4718592, !1), a += 4, c.setUint32(a, 4718592, !1), a += 4, c.setUint32(a, 0, !1), a += 4, c.setUint16(a, 1, !1), a += 2, a += 32, c.setUint16(a, 24, !1), a += 2, c.setUint16(a, 65535, !1), a += 2, c.setUint32(a, s, !1), a += 4, o[a++] = 97, o[a++] = 118, o[a++] = 99, o[a++] = 67, o.set(n, a), o;
2201
- }
2202
- function Ti(t) {
2203
- const { codedWidth: e, codedHeight: n, description: s } = t;
2204
- if (!e || !n || !s)
2205
- throw new Error("Missing required fields to create video init segment");
2206
- const i = 1e6, r = 1, o = {
2207
- type: "ftyp",
2208
- majorBrand: "isom",
2209
- minorVersion: 512,
2210
- compatibleBrands: ["isom", "iso6", "mp41"]
2211
- }, c = {
2212
- type: "mvhd",
2213
- version: 0,
2214
- flags: 0,
2215
- creationTime: 0,
2216
- modificationTime: 0,
2217
- timescale: i,
2218
- duration: 0,
2219
- // Unknown/fragmented
2220
- rate: 65536,
2221
- // 1.0 in 16.16 fixed point
2222
- volume: 256,
2223
- // 1.0 in 8.8 fixed point
2224
- reserved1: 0,
2225
- reserved2: [0, 0],
2226
- matrix: Se,
2227
- preDefined: [0, 0, 0, 0, 0, 0],
2228
- nextTrackId: r + 1
2229
- }, a = {
2230
- type: "tkhd",
2231
- version: 0,
2232
- flags: 3,
2233
- // Track enabled + in movie
2234
- creationTime: 0,
2235
- modificationTime: 0,
2236
- trackId: r,
2237
- reserved1: 0,
2238
- duration: 0,
2239
- reserved2: [0, 0],
2240
- layer: 0,
2241
- alternateGroup: 0,
2242
- volume: 0,
2243
- // Video tracks have 0 volume
2244
- reserved3: 0,
2245
- matrix: Se,
2246
- width: e * 65536,
2247
- // 16.16 fixed point (avoid << which produces signed int)
2248
- height: n * 65536
2249
- }, u = {
2250
- type: "mdhd",
2251
- version: 0,
2252
- flags: 0,
2253
- creationTime: 0,
2254
- modificationTime: 0,
2255
- timescale: i,
2256
- duration: 0,
2257
- language: "und",
2258
- preDefined: 0
2259
- }, l = {
2260
- type: "hdlr",
2261
- version: 0,
2262
- flags: 0,
2263
- preDefined: 0,
2264
- handlerType: "vide",
2265
- reserved: [0, 0, 0],
2266
- name: "VideoHandler"
2267
- }, d = {
2268
- type: "vmhd",
2269
- version: 0,
2270
- flags: 1,
2271
- // Required to be 1
2272
- graphicsmode: 0,
2273
- opcolor: [0, 0, 0]
2274
- }, b = {
2275
- type: "dinf",
2276
- boxes: [{
2277
- type: "dref",
2278
- version: 0,
2279
- flags: 0,
2280
- entryCount: 1,
2281
- entries: [{
2282
- type: "url ",
2283
- version: 0,
2284
- flags: 1,
2285
- // Self-contained flag
2286
- location: ""
2287
- }]
2288
- }]
2289
- }, v = {
2290
- type: "stsd",
2291
- version: 0,
2292
- flags: 0,
2293
- entryCount: 1,
2294
- // biome-ignore lint/suspicious/noExplicitAny: Raw avc1 box since library doesn't handle avcC children
2295
- entries: [ki(e, n, $(s))]
2296
- }, _ = {
2297
- type: "stts",
2298
- version: 0,
2299
- flags: 0,
2300
- entryCount: 0,
2301
- entries: []
2302
- }, M = Nt(), H = jt(), P = Zt(), Ue = he([o, {
2303
- type: "moov",
2304
- boxes: [c, {
2305
- type: "trak",
2306
- boxes: [a, {
2307
- type: "mdia",
2308
- boxes: [u, l, {
2309
- type: "minf",
2310
- boxes: [d, b, {
2311
- type: "stbl",
2312
- // biome-ignore lint/suspicious/noExplicitAny: Raw boxes for types without library writers
2313
- boxes: [v, _, M, H, P]
2314
- }]
2315
- }]
2316
- }]
2317
- }, {
2318
- type: "mvex",
2319
- boxes: [{
2320
- type: "trex",
2321
- version: 0,
2322
- flags: 0,
2323
- trackId: r,
2324
- defaultSampleDescriptionIndex: 1,
2325
- defaultSampleDuration: 0,
2326
- defaultSampleSize: 0,
2327
- defaultSampleFlags: 0
2328
- }]
2329
- }]
2330
- }]), me = Ue.reduce((F, j) => F + j.byteLength, 0), pe = new Uint8Array(me);
2331
- let ae = 0;
2332
- for (const F of Ue)
2333
- pe.set(new Uint8Array(F.buffer, F.byteOffset, F.byteLength), ae), ae += F.byteLength;
2334
- return pe;
2335
- }
2336
- function Ui(t) {
2337
- const { sampleRate: e, numberOfChannels: n, description: s, codec: i } = t, r = 1e6, o = 1, c = {
2338
- type: "ftyp",
2339
- majorBrand: "isom",
2340
- minorVersion: 512,
2341
- compatibleBrands: ["isom", "iso6", "mp41"]
2342
- }, a = {
2343
- type: "mvhd",
2344
- version: 0,
2345
- flags: 0,
2346
- creationTime: 0,
2347
- modificationTime: 0,
2348
- timescale: r,
2349
- duration: 0,
2350
- rate: 65536,
2351
- volume: 256,
2352
- reserved1: 0,
2353
- reserved2: [0, 0],
2354
- matrix: Se,
2355
- preDefined: [0, 0, 0, 0, 0, 0],
2356
- nextTrackId: o + 1
2357
- }, u = {
2358
- type: "tkhd",
2359
- version: 0,
2360
- flags: 3,
2361
- creationTime: 0,
2362
- modificationTime: 0,
2363
- trackId: o,
2364
- reserved1: 0,
2365
- duration: 0,
2366
- reserved2: [0, 0],
2367
- layer: 0,
2368
- alternateGroup: 0,
2369
- volume: 256,
2370
- // Audio tracks have volume (1.0 in 8.8 fixed point)
2371
- reserved3: 0,
2372
- matrix: Se,
2373
- width: 0,
2374
- height: 0
2375
- }, l = {
2376
- type: "mdhd",
2377
- version: 0,
2378
- flags: 0,
2379
- creationTime: 0,
2380
- modificationTime: 0,
2381
- timescale: r,
2382
- duration: 0,
2383
- language: "und",
2384
- preDefined: 0
2385
- }, d = {
2386
- type: "hdlr",
2387
- version: 0,
2388
- flags: 0,
2389
- preDefined: 0,
2390
- handlerType: "soun",
2391
- reserved: [0, 0, 0],
2392
- name: "SoundHandler"
2393
- }, f = {
2394
- type: "smhd",
2395
- version: 0,
2396
- flags: 0,
2397
- balance: 0,
2398
- reserved: 0
2399
- }, w = {
2400
- type: "dinf",
2401
- boxes: [{
2402
- type: "dref",
2403
- version: 0,
2404
- flags: 0,
2405
- entryCount: 1,
2406
- entries: [{
2407
- type: "url ",
2408
- version: 0,
2409
- flags: 1,
2410
- location: ""
2411
- }]
2412
- }]
2413
- }, _ = {
2414
- type: "stsd",
2415
- version: 0,
2416
- flags: 0,
2417
- entryCount: 1,
2418
- // biome-ignore lint/suspicious/noExplicitAny: Raw sample entry box
2419
- entries: [Ei(i, e, n, s)]
2420
- }, M = {
2421
- type: "stts",
2422
- version: 0,
2423
- flags: 0,
2424
- entryCount: 0,
2425
- entries: []
2426
- }, H = Nt(), P = jt(), G = Zt(), me = he([c, {
2427
- type: "moov",
2428
- boxes: [a, {
2429
- type: "trak",
2430
- boxes: [u, {
2431
- type: "mdia",
2432
- boxes: [l, d, {
2433
- type: "minf",
2434
- boxes: [f, w, {
2435
- type: "stbl",
2436
- // biome-ignore lint/suspicious/noExplicitAny: Raw boxes for types without library writers
2437
- boxes: [_, M, H, P, G]
2438
- }]
2439
- }]
2440
- }]
2441
- }, {
2442
- type: "mvex",
2443
- boxes: [{
2444
- type: "trex",
2445
- version: 0,
2446
- flags: 0,
2447
- trackId: o,
2448
- defaultSampleDescriptionIndex: 1,
2449
- defaultSampleDuration: 0,
2450
- defaultSampleSize: 0,
2451
- defaultSampleFlags: 0
2452
- }]
2453
- }]
2454
- }]), pe = me.reduce((j, Qt) => j + Qt.byteLength, 0), ae = new Uint8Array(pe);
2455
- let F = 0;
2456
- for (const j of me)
2457
- ae.set(new Uint8Array(j.buffer, j.byteOffset, j.byteLength), F), F += j.byteLength;
2458
- return ae;
2459
- }
2460
- function Ei(t, e, n, s) {
2461
- if (t.startsWith("mp4a"))
2462
- return xi(e, n, s);
2463
- if (t === "opus")
2464
- return Bi(e, n, s);
2465
- throw new Error(`Unsupported audio codec: ${t}`);
2466
- }
2467
- function xi(t, e, n) {
2468
- const s = Ci(t, e, n), r = 8 + (28 + s.length), o = new Uint8Array(r), c = new DataView(o.buffer);
2469
- let a = 0;
2470
- return c.setUint32(a, r, !1), a += 4, o[a++] = 109, o[a++] = 112, o[a++] = 52, o[a++] = 97, a += 6, c.setUint16(a, 1, !1), a += 2, a += 8, c.setUint16(a, e, !1), a += 2, c.setUint16(a, 16, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint32(a, t * 65536, !1), a += 4, o.set(s, a), o;
2471
- }
2472
- function Bi(t, e, n) {
2473
- const s = Ii(e, t, n), r = 8 + (28 + s.length), o = new Uint8Array(r), c = new DataView(o.buffer);
2474
- let a = 0;
2475
- return c.setUint32(a, r, !1), a += 4, o[a++] = 79, o[a++] = 112, o[a++] = 117, o[a++] = 115, a += 6, c.setUint16(a, 1, !1), a += 2, a += 8, c.setUint16(a, e, !1), a += 2, c.setUint16(a, 16, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint32(a, t * 65536, !1), a += 4, o.set(s, a), o;
2476
- }
2477
- function Ri(t, e) {
2478
- const s = {
2479
- 96e3: 0,
2480
- 88200: 1,
2481
- 64e3: 2,
2482
- 48e3: 3,
2483
- 44100: 4,
2484
- 32e3: 5,
2485
- 24e3: 6,
2486
- 22050: 7,
2487
- 16e3: 8,
2488
- 12e3: 9,
2489
- 11025: 10,
2490
- 8e3: 11,
2491
- 7350: 12
2492
- }[t] ?? 4, r = 2 << 3 | s >> 1, o = (s & 1) << 7 | e << 3;
2493
- return new Uint8Array([r, o]);
2494
- }
2495
- function Ci(t, e, n) {
2496
- const s = n ? $(n) : Ri(t, e), i = s.length, r = 15 + i, o = 5 + r + 3, c = 14 + o, a = new Uint8Array(c), u = new DataView(a.buffer);
2497
- let l = 0;
2498
- return u.setUint32(l, c, !1), l += 4, a[l++] = 101, a[l++] = 115, a[l++] = 100, a[l++] = 115, u.setUint32(l, 0, !1), l += 4, a[l++] = 3, a[l++] = o, u.setUint16(l, 0, !1), l += 2, a[l++] = 0, a[l++] = 4, a[l++] = r, a[l++] = 64, a[l++] = 21, a[l++] = 0, a[l++] = 0, a[l++] = 0, u.setUint32(l, 0, !1), l += 4, u.setUint32(l, 0, !1), l += 4, a[l++] = 5, a[l++] = i, a.set(s, l), l += i, a[l++] = 6, a[l++] = 1, a[l++] = 2, a;
2499
- }
2500
- function Ii(t, e, n) {
2501
- if (n) {
2502
- const c = $(n), a = 8 + c.length, u = new Uint8Array(a);
2503
- return new DataView(u.buffer).setUint32(0, a, !1), u[4] = 100, u[5] = 79, u[6] = 112, u[7] = 115, u.set(c, 8), u;
2504
- }
2505
- const s = 19, i = new Uint8Array(s), r = new DataView(i.buffer);
2506
- let o = 0;
2507
- return r.setUint32(o, s, !1), o += 4, i[o++] = 100, i[o++] = 79, i[o++] = 112, i[o++] = 115, i[o++] = 0, i[o++] = t, r.setUint16(o, 312, !1), o += 2, r.setUint32(o, e, !1), o += 4, r.setInt16(o, 0, !1), o += 2, i[o++] = 0, i;
2508
- }
2509
- function Vt(t) {
2510
- const { data: e, timestamp: n, duration: s, keyframe: i, sequence: r, trackId: o = 1 } = t, c = i ? 33554432 : 16842752, a = {
2511
- type: "mfhd",
2512
- version: 0,
2513
- flags: 0,
2514
- sequenceNumber: r
2515
- }, u = {
2516
- type: "tfhd",
2517
- version: 0,
2518
- flags: 131072,
2519
- trackId: o
2520
- }, l = {
2521
- type: "tfdt",
2522
- version: 1,
2523
- // version 1 for 64-bit baseMediaDecodeTime
2524
- flags: 0,
2525
- baseMediaDecodeTime: n
2526
- }, d = {
2527
- type: "trun",
2528
- version: 0,
2529
- flags: 1793,
2530
- sampleCount: 1,
2531
- dataOffset: 0,
2532
- // Will be calculated after we know moof size
2533
- samples: [
2534
- {
2535
- sampleDuration: s,
2536
- sampleSize: e.byteLength,
2537
- sampleFlags: c
2538
- }
2539
- ]
2540
- }, p = {
2541
- type: "moof",
2542
- boxes: [a, {
2543
- type: "traf",
2544
- boxes: [u, l, d]
2545
- }]
2546
- }, b = he([p]);
2547
- let w = 0;
2548
- for (const k of b)
2549
- w += k.byteLength;
2550
- d.dataOffset = w + 8;
2551
- const v = he([p]);
2552
- w = 0;
2553
- for (const k of v)
2554
- w += k.byteLength;
2555
- const _ = new ArrayBuffer(e.byteLength), M = new Uint8Array(_);
2556
- M.set(e);
2557
- const P = he([{
2558
- type: "mdat",
2559
- data: M
2560
- }]);
2561
- let G = 0;
2562
- for (const k of P)
2563
- G += k.byteLength;
2564
- const X = new Uint8Array(w + G);
2565
- let N = 0;
2566
- for (const k of v)
2567
- X.set(new Uint8Array(k.buffer, k.byteOffset, k.byteLength), N), N += k.byteLength;
2568
- for (const k of P)
2569
- X.set(new Uint8Array(k.buffer, k.byteOffset, k.byteLength), N), N += k.byteLength;
2570
- return X;
2571
- }
2572
- let Wt = class {
2573
- #e;
2574
- constructor(e) {
2575
- this.#e = e;
2576
- }
2577
- decode(e) {
2578
- return zi(e, this.#e).map((n) => ({
2579
- data: n.data,
2580
- timestamp: n.timestamp,
2581
- keyframe: n.keyframe
2582
- }));
2583
- }
2584
- };
2585
- class se {
2586
- #e;
2587
- #t;
2588
- #n;
2589
- #s = [];
2590
- #i;
2591
- // the active group sequence number
2592
- // Wake up the consumer when a new frame is available.
2593
- #r;
2594
- #a = new h([]);
2595
- buffered = this.#a;
2596
- #o = new E();
2597
- constructor(e, n) {
2598
- this.#e = e, this.#t = n.format, this.#n = h.from(n.latency ?? A.Time.Milli.zero), this.#o.spawn(this.#c.bind(this)), this.#o.cleanup(() => {
2599
- this.#e.close();
2600
- for (const s of this.#s)
2601
- s.consumer.close();
2602
- this.#s.length = 0;
2603
- });
2604
- }
2605
- async #c() {
2606
- for (; ; ) {
2607
- const e = await this.#e.recvGroup();
2608
- if (!e) break;
2609
- if (this.#i === void 0 && (this.#i = e.sequence), e.sequence < this.#i) {
2610
- console.warn(`skipping old group: ${e.sequence} < ${this.#i}`), e.close();
2611
- continue;
2612
- }
2613
- const n = {
2614
- consumer: e,
2615
- frames: []
2616
- };
2617
- this.#s.push(n), this.#s.sort((s, i) => s.consumer.sequence - i.consumer.sequence), this.#o.spawn(this.#u.bind(this, n));
2618
- }
2619
- }
2620
- async #u(e) {
2621
- try {
2622
- let n = 0;
2623
- for (; ; ) {
2624
- const s = await e.consumer.readFrame();
2625
- if (!s) break;
2626
- const i = this.#t.decode(s);
2627
- for (const r of i) {
2628
- const o = {
2629
- data: r.data,
2630
- timestamp: r.timestamp,
2631
- // Protocol invariant: groups always start at a keyframe.
2632
- // For index 0, we enforce this regardless of what the format reports.
2633
- // For index > 0, we trust the format's keyframe detection.
2634
- keyframe: n === 0 ? !0 : r.keyframe
2635
- };
2636
- n++, e.frames.push(o), (e.latest === void 0 || o.timestamp > e.latest) && (e.latest = o.timestamp), this.#l(), e.consumer.sequence === this.#i ? (this.#r?.(), this.#r = void 0) : this.#d();
2637
- }
2638
- }
2639
- } catch {
2640
- } finally {
2641
- e.done = !0, e.consumer.sequence === this.#i && (this.#i += 1), this.#l(), this.#r?.(), this.#r = void 0, e.consumer.close();
2642
- }
2643
- }
2644
- #d() {
2645
- if (this.#i === void 0) return;
2646
- let e = !1;
2647
- for (; this.#s.length >= 2; ) {
2648
- const n = A.Time.Micro.fromMilli(this.#n.peek());
2649
- let s, i;
2650
- for (const c of this.#s) {
2651
- if (c.latest === void 0) continue;
2652
- const a = c.frames.at(0)?.timestamp ?? c.latest;
2653
- (s === void 0 || a < s) && (s = a), (i === void 0 || c.latest > i) && (i = c.latest);
2654
- }
2655
- if (s === void 0 || i === void 0 || i - s <= n) break;
2656
- const o = this.#s.shift();
2657
- if (!o) break;
2658
- this.#i = this.#s[0]?.consumer.sequence, console.warn(`skipping slow group: ${o.consumer.sequence} -> ${this.#i}`), o.consumer.close(), o.frames.length = 0, e = !0;
2659
- }
2660
- e && (this.#l(), this.#r?.(), this.#r = void 0);
2661
- }
2662
- // Returns the next frame in order, along with the group number.
2663
- // If frame is undefined, the group is done.
2664
- async next() {
2665
- for (; ; ) {
2666
- if (this.#s.length > 0 && this.#i !== void 0 && this.#s[0].consumer.sequence <= this.#i) {
2667
- const s = this.#s[0].frames.shift();
2668
- if (s)
2669
- return this.#l(), { frame: s, group: this.#s[0].consumer.sequence };
2670
- if (this.#i > this.#s[0].consumer.sequence || this.#s[0].done) {
2671
- this.#s[0].consumer.sequence === this.#i && (this.#i += 1);
2672
- const i = this.#s.shift();
2673
- if (i)
2674
- return this.#l(), { frame: void 0, group: i.consumer.sequence };
2675
- }
2676
- }
2677
- if (this.#r)
2678
- throw new Error("multiple calls to next not supported");
2679
- const e = this.#o.abort;
2680
- if (e.aborted) return;
2681
- const n = await new Promise((s) => {
2682
- const i = () => s(!0);
2683
- e.addEventListener("abort", i, { once: !0 }), this.#r = () => {
2684
- e.removeEventListener("abort", i), s(!1);
2685
- };
2686
- });
2687
- if (this.#r = void 0, n) return;
2688
- }
2689
- }
2690
- #l() {
2691
- const e = [];
2692
- let n;
2693
- for (const s of this.#s) {
2694
- const i = s.frames.at(0);
2695
- if (!i || s.latest === void 0) continue;
2696
- const r = A.Time.Milli.fromMicro(i.timestamp), o = A.Time.Milli.fromMicro(s.latest), c = e.at(-1), a = n?.done && n.consumer.sequence + 1 === s.consumer.sequence;
2697
- c && (c.end >= r || a) ? c.end = A.Time.Milli.max(c.end, o) : e.push({ start: r, end: o }), n = s;
2698
- }
2699
- this.#a.set(e);
2700
- }
2701
- close() {
2702
- this.#o.close();
2703
- }
2704
- }
2705
- class Te {
2706
- decode(e) {
2707
- const [n, s] = A.Varint.decode(e);
2708
- return [{ data: s, timestamp: n, keyframe: !1 }];
2709
- }
2710
- }
2711
- function Ae(t, e) {
2712
- if (t.length === 0) return e;
2713
- if (e.length === 0) return t;
2714
- const n = [], s = [...t, ...e].sort((i, r) => i.start - r.start);
2715
- for (const i of s) {
2716
- const r = n.at(-1);
2717
- r && r.end >= i.start ? r.end = g.Milli.max(r.end, i.end) : n.push({ ...i });
2718
- }
2719
- return n;
2720
- }
2721
- let xe;
2722
- async function ot() {
2723
- return globalThis.AudioEncoder && globalThis.AudioDecoder ? !0 : (xe || (console.warn("using Opus polyfill; performance may be degraded"), xe = Promise.all([
2724
- import("./libav-opus-af-BlMWboA7.js"),
2725
- import("./main-DGBFe0O7.js")
2726
- ]).then(async ([t, e]) => (await e.load({
2727
- LibAV: t,
2728
- polyfill: !0
2729
- }), !0))), await xe);
2730
- }
2731
- function K(t) {
2732
- const e = atob(t), n = new Uint8Array(e.length);
2733
- for (let s = 0; s < e.length; s++) n[s] = e.charCodeAt(s);
2734
- return n;
2735
- }
2736
- const Z = 0, O = 1, ce = 2, J = 3, Di = 4;
2737
- function qt(t, e, n) {
2738
- if (t <= 0) throw new Error("invalid channels");
2739
- if (e <= 0) throw new Error("invalid capacity");
2740
- if (n <= 0) throw new Error("invalid sample rate");
2741
- const s = new SharedArrayBuffer(t * e * Float32Array.BYTES_PER_ELEMENT), i = new SharedArrayBuffer(Di * Int32Array.BYTES_PER_ELEMENT), r = new Int32Array(i);
2742
- return Atomics.store(r, J, 1), { channels: t, capacity: e, rate: n, samples: s, control: i };
2743
- }
2744
- function Oi(t, e) {
2745
- return (t - e | 0) > 0 ? t : e;
2746
- }
2747
- function ue(t, e) {
2748
- return (t % e + e) % e;
2749
- }
2750
- function Be(t, e, n) {
2751
- for (; ; ) {
2752
- const s = Atomics.load(t, e);
2753
- if ((n - s | 0) <= 0) return s;
2754
- if (Atomics.compareExchange(t, e, s, n) === s) return n;
2755
- }
2756
- }
2757
- class Ne {
2758
- channels;
2759
- capacity;
2760
- rate;
2761
- init;
2762
- #e;
2763
- #t;
2764
- constructor(e) {
2765
- this.channels = e.channels, this.capacity = e.capacity, this.rate = e.rate, this.init = e, this.#e = new Int32Array(e.control), this.#t = [];
2766
- for (let n = 0; n < this.channels; n++)
2767
- this.#t.push(
2768
- new Float32Array(e.samples, n * this.capacity * Float32Array.BYTES_PER_ELEMENT, this.capacity)
2769
- );
2770
- }
2771
- /**
2772
- * Insert audio samples at the given timestamp.
2773
- * Main thread only. Handles out-of-order writes, gap filling, and overflow.
2774
- */
2775
- insert(e, n) {
2776
- if (n.length !== this.channels) throw new Error("wrong number of channels");
2777
- let s = Math.round(g.Second.fromMicro(e) * this.rate);
2778
- const i = n[0].length;
2779
- let r = 0;
2780
- const o = s + i | 0, c = Atomics.load(this.#e, O), a = c - s | 0;
2781
- if (a > 0) {
2782
- if (a >= i)
2783
- return;
2784
- r = a, s = s + a | 0;
2785
- }
2786
- const u = i - r;
2787
- (o - c | 0) > this.capacity && Be(this.#e, O, o - this.capacity | 0);
2788
- const l = Atomics.load(this.#e, Z), d = s - l | 0;
2789
- if (d > 0) {
2790
- const w = Math.min(d, this.capacity);
2791
- for (let v = 0; v < this.channels; v++) {
2792
- const _ = this.#t[v];
2793
- for (let M = 0; M < w; M++)
2794
- _[ue(l + M | 0, this.capacity)] = 0;
2795
- }
2796
- }
2797
- for (let w = 0; w < this.channels; w++) {
2798
- const v = n[w], _ = this.#t[w];
2799
- for (let M = 0; M < u; M++)
2800
- _[ue(s + M | 0, this.capacity)] = v[r + M];
2801
- }
2802
- Atomics.store(this.#e, Z, Oi(Atomics.load(this.#e, Z), o));
2803
- const f = Atomics.load(this.#e, O), p = Atomics.load(this.#e, Z), b = Atomics.load(this.#e, ce);
2804
- (p - f | 0) >= b && b > 0 && Atomics.store(this.#e, J, 0);
2805
- }
2806
- /**
2807
- * Read audio samples into the output buffers.
2808
- * AudioWorklet only. Returns the number of samples read.
2809
- */
2810
- read(e) {
2811
- if (Atomics.load(this.#e, J) === 1) return 0;
2812
- let n = Atomics.load(this.#e, O);
2813
- const s = Atomics.load(this.#e, Z), i = Atomics.load(this.#e, ce), r = s - n | 0;
2814
- if (i > 0 && r > i) {
2815
- const a = s - i | 0;
2816
- n = Be(this.#e, O, a);
2817
- }
2818
- const o = s - n | 0, c = Math.min(o, e[0].length);
2819
- if (c <= 0) return 0;
2820
- for (let a = 0; a < this.channels; a++) {
2821
- const u = this.#t[a], l = e[a];
2822
- for (let d = 0; d < c; d++)
2823
- l[d] = u[ue(n + d | 0, this.capacity)];
2824
- }
2825
- return Be(this.#e, O, n + c | 0), c;
2826
- }
2827
- /** Update the target latency in samples. */
2828
- setLatency(e) {
2829
- Atomics.store(this.#e, ce, e);
2830
- }
2831
- /**
2832
- * Allocate a new ring with `newCapacity` samples and copy the unread window
2833
- * [READ, WRITE) plus control state into it. Used when growing capacity so
2834
- * we don't drop buffered audio. If `newCapacity` is smaller than the unread
2835
- * span, the oldest samples are truncated.
2836
- *
2837
- * Main thread only. `resize()` reads from the source `SharedRingBuffer` and
2838
- * writes into a freshly allocated buffer from `allocSharedRingBuffer`, so it
2839
- * relies on the same invariant as `insert()`: no concurrent main-thread
2840
- * writers. The AudioWorklet reader is tolerated via the CAS discipline used
2841
- * by READ/WRITE elsewhere.
2842
- */
2843
- resize(e) {
2844
- const n = qt(this.channels, e, this.rate), s = new Ne(n), i = Atomics.load(this.#e, O), r = Atomics.load(this.#e, Z), o = Atomics.load(this.#e, ce), c = Atomics.load(this.#e, J), a = r - i | 0, u = Math.max(0, Math.min(a, s.capacity)), l = r - u | 0;
2845
- for (let d = 0; d < this.channels; d++) {
2846
- const f = this.#t[d], p = s.#t[d];
2847
- for (let b = 0; b < u; b++) {
2848
- const w = l + b | 0;
2849
- p[ue(w, s.capacity)] = f[ue(w, this.capacity)];
2850
- }
2851
- }
2852
- return Atomics.store(s.#e, O, l), Atomics.store(s.#e, Z, r), Atomics.store(s.#e, ce, o), Atomics.store(s.#e, J, c), s;
2853
- }
2854
- /** Current playback timestamp derived from READ position. */
2855
- get timestamp() {
2856
- const e = Atomics.load(this.#e, O);
2857
- return g.Micro.fromSecond(e / this.rate);
2858
- }
2859
- /** Whether the buffer is stalled (waiting to fill). */
2860
- get stalled() {
2861
- return Atomics.load(this.#e, J) === 1;
2862
- }
2863
- /**
2864
- * Number of buffered samples (WRITE - READ).
2865
- *
2866
- * Non-atomic: WRITE and READ are loaded separately, so a concurrent
2867
- * writer/reader can make the two loads inconsistent. Intended for
2868
- * tests and diagnostics, not control-flow decisions.
2869
- */
2870
- get length() {
2871
- return Atomics.load(this.#e, Z) - Atomics.load(this.#e, O) | 0;
2872
- }
2873
- }
2874
- function Li() {
2875
- return !(typeof SharedArrayBuffer > "u" || typeof crossOriginIsolated < "u" && !crossOriginIsolated);
2876
- }
2877
- function Fi(t, e, n, s) {
2878
- return Li() ? (console.log("[audio] using SharedArrayBuffer audio buffer"), new $i(t, e, n, s)) : (console.log("[audio] using postMessage audio buffer (SharedArrayBuffer unavailable)"), new Pi(t, e, n, s));
2879
- }
2880
- class $i {
2881
- rate;
2882
- channels;
2883
- #e;
2884
- #t;
2885
- #n = new h(0);
2886
- timestamp = this.#n;
2887
- #s = new h(!0);
2888
- stalled = this.#s;
2889
- #i = new E();
2890
- constructor(e, n, s, i) {
2891
- this.#e = e, this.channels = n, this.rate = s;
2892
- const r = Math.max(s, i * 2), o = qt(n, r, s);
2893
- this.#t = new Ne(o), this.#t.setLatency(i);
2894
- const c = { type: "init-shared", ...o };
2895
- e.port.postMessage(c), this.#i.interval(() => {
2896
- this.#n.set(this.#t.timestamp), this.#s.set(this.#t.stalled);
2897
- }, 50);
2898
- }
2899
- insert(e, n) {
2900
- this.#t.insert(e, n);
2901
- }
2902
- setLatency(e) {
2903
- if (this.#t.capacity < e * 1.5) {
2904
- const n = Math.max(this.rate, e * 2);
2905
- this.#t = this.#t.resize(n), this.#t.setLatency(e);
2906
- const s = { type: "init-shared", ...this.#t.init };
2907
- this.#e.port.postMessage(s);
2908
- } else
2909
- this.#t.setLatency(e);
2910
- }
2911
- close() {
2912
- this.#i.close();
2913
- }
2914
- }
2915
- class Pi {
2916
- rate;
2917
- channels;
2918
- #e;
2919
- #t = new h(0);
2920
- timestamp = this.#t;
2921
- #n = new h(!0);
2922
- stalled = this.#n;
2923
- #s = new E();
2924
- constructor(e, n, s, i) {
2925
- this.#e = e, this.channels = n, this.rate = s;
2926
- const r = g.Milli.fromSecond(i / s), o = { type: "init-post", channels: n, rate: s, latency: r };
2927
- e.port.postMessage(o), this.#s.event(e.port, "message", (c) => {
2928
- const a = c.data;
2929
- a?.type === "state" && (this.#t.set(a.timestamp), this.#n.set(a.stalled));
2930
- }), e.port.start();
2931
- }
2932
- insert(e, n) {
2933
- const s = { type: "data", data: n, timestamp: e };
2934
- this.#e.port.postMessage(
2935
- s,
2936
- n.map((i) => i.buffer)
2937
- );
2938
- }
2939
- setLatency(e) {
2940
- const s = { type: "latency", latency: g.Milli.fromSecond(e / this.rate) };
2941
- this.#e.port.postMessage(s);
2942
- }
2943
- close() {
2944
- this.#s.close();
2945
- }
2946
- }
2947
- const Ni = `var __defProp = Object.defineProperty;
2948
- var __getOwnPropNames = Object.getOwnPropertyNames;
2949
- var __esm = (fn, res) => function __init() {
2950
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
2951
- };
2952
- var __export = (target, all) => {
2953
- for (var name in all)
2954
- __defProp(target, name, { get: all[name], enumerable: true });
2955
- };
2956
-
2957
- // ../net/src/path.ts
2958
- var init_path = __esm({
2959
- "../net/src/path.ts"() {
2960
- "use strict";
2961
- }
2962
- });
2963
-
2964
- // ../net/src/varint.ts
2965
- var MAX_U6, MAX_U14, MAX_U30, MAX_U53, MAX_U64, MAX_U62;
2966
- var init_varint = __esm({
2967
- "../net/src/varint.ts"() {
2968
- "use strict";
2969
- MAX_U6 = 2 ** 6 - 1;
2970
- MAX_U14 = 2 ** 14 - 1;
2971
- MAX_U30 = 2 ** 30 - 1;
2972
- MAX_U53 = Number.MAX_SAFE_INTEGER;
2973
- MAX_U64 = (1n << 64n) - 1n;
2974
- MAX_U62 = 2n ** 62n - 1n;
2975
- }
2976
- });
2977
-
2978
- // ../net/src/index.ts
2979
- init_path();
2980
-
2981
- // ../net/src/time.ts
2982
- var time_exports = {};
2983
- __export(time_exports, {
2984
- Micro: () => Micro,
2985
- Milli: () => Milli,
2986
- Nano: () => Nano,
2987
- Second: () => Second
2988
- });
2989
- var Nano = {
2990
- zero: 0,
2991
- fromMicro: (us) => us * 1e3,
2992
- fromMilli: (ms) => ms * 1e6,
2993
- fromSecond: (s) => s * 1e9,
2994
- toMicro: (ns) => ns / 1e3,
2995
- toMilli: (ns) => ns / 1e6,
2996
- toSecond: (ns) => ns / 1e9,
2997
- now: () => performance.now() * 1e6,
2998
- add: (a, b) => a + b,
2999
- sub: (a, b) => a - b,
3000
- mul: (a, b) => a * b,
3001
- div: (a, b) => a / b,
3002
- max: (a, b) => Math.max(a, b),
3003
- min: (a, b) => Math.min(a, b)
3004
- };
3005
- var Micro = {
3006
- zero: 0,
3007
- fromNano: (ns) => ns / 1e3,
3008
- fromMilli: (ms) => ms * 1e3,
3009
- fromSecond: (s) => s * 1e6,
3010
- toNano: (us) => us * 1e3,
3011
- toMilli: (us) => us / 1e3,
3012
- toSecond: (us) => us / 1e6,
3013
- now: () => performance.now() * 1e3,
3014
- add: (a, b) => a + b,
3015
- sub: (a, b) => a - b,
3016
- mul: (a, b) => a * b,
3017
- div: (a, b) => a / b,
3018
- max: (a, b) => Math.max(a, b),
3019
- min: (a, b) => Math.min(a, b)
3020
- };
3021
- var Milli = {
3022
- zero: 0,
3023
- fromNano: (ns) => ns / 1e6,
3024
- fromMicro: (us) => us / 1e3,
3025
- fromSecond: (s) => s * 1e3,
3026
- toNano: (ms) => ms * 1e6,
3027
- toMicro: (ms) => ms * 1e3,
3028
- toSecond: (ms) => ms / 1e3,
3029
- now: () => performance.now(),
3030
- add: (a, b) => a + b,
3031
- sub: (a, b) => a - b,
3032
- mul: (a, b) => a * b,
3033
- div: (a, b) => a / b,
3034
- max: (a, b) => Math.max(a, b),
3035
- min: (a, b) => Math.min(a, b)
3036
- };
3037
- var Second = {
3038
- zero: 0,
3039
- fromNano: (ns) => ns / 1e9,
3040
- fromMicro: (us) => us / 1e6,
3041
- fromMilli: (ms) => ms / 1e3,
3042
- toNano: (s) => s * 1e9,
3043
- toMicro: (s) => s * 1e6,
3044
- toMilli: (s) => s * 1e3,
3045
- now: () => performance.now() / 1e3,
3046
- add: (a, b) => a + b,
3047
- sub: (a, b) => a - b,
3048
- mul: (a, b) => a * b,
3049
- div: (a, b) => a / b,
3050
- max: (a, b) => Math.max(a, b),
3051
- min: (a, b) => Math.min(a, b)
3052
- };
3053
-
3054
- // ../net/src/index.ts
3055
- init_varint();
3056
-
3057
- // src/audio/ring-buffer.ts
3058
- var AudioRingBuffer = class {
3059
- #buffer;
3060
- #writeIndex = 0;
3061
- #readIndex = 0;
3062
- rate;
3063
- channels;
3064
- #stalled = true;
3065
- constructor(props) {
3066
- if (props.channels <= 0) throw new Error("invalid channels");
3067
- if (props.rate <= 0) throw new Error("invalid sample rate");
3068
- if (props.latency <= 0) throw new Error("invalid latency");
3069
- const samples = Math.ceil(props.rate * time_exports.Second.fromMilli(props.latency));
3070
- if (samples === 0) throw new Error("empty buffer");
3071
- this.rate = props.rate;
3072
- this.channels = props.channels;
3073
- this.#buffer = [];
3074
- for (let i = 0; i < this.channels; i++) {
3075
- this.#buffer[i] = new Float32Array(samples);
3076
- }
3077
- }
3078
- get stalled() {
3079
- return this.#stalled;
3080
- }
3081
- get timestamp() {
3082
- return time_exports.Micro.fromSecond(this.#readIndex / this.rate);
3083
- }
3084
- get length() {
3085
- return this.#writeIndex - this.#readIndex;
3086
- }
3087
- get capacity() {
3088
- return this.#buffer[0]?.length;
3089
- }
3090
- resize(latency) {
3091
- const newCapacity = Math.ceil(this.rate * time_exports.Second.fromMilli(latency));
3092
- if (newCapacity === this.capacity) return;
3093
- if (newCapacity === 0) throw new Error("empty buffer");
3094
- const newBuffer = [];
3095
- for (let i = 0; i < this.channels; i++) {
3096
- newBuffer[i] = new Float32Array(newCapacity);
3097
- }
3098
- const samplesToKeep = Math.min(this.length, newCapacity);
3099
- if (samplesToKeep > 0) {
3100
- const copyStart = this.#writeIndex - samplesToKeep;
3101
- for (let channel = 0; channel < this.channels; channel++) {
3102
- const src = this.#buffer[channel];
3103
- const dst = newBuffer[channel];
3104
- for (let i = 0; i < samplesToKeep; i++) {
3105
- const srcPos = (copyStart + i) % src.length;
3106
- const dstPos = (copyStart + i) % dst.length;
3107
- dst[dstPos] = src[srcPos];
3108
- }
3109
- }
3110
- }
3111
- this.#buffer = newBuffer;
3112
- this.#readIndex = this.#writeIndex - samplesToKeep;
3113
- if (samplesToKeep === 0) this.#stalled = true;
3114
- }
3115
- write(timestamp, data) {
3116
- if (data.length !== this.channels) throw new Error("wrong number of channels");
3117
- let start = Math.round(time_exports.Second.fromMicro(timestamp) * this.rate);
3118
- let samples = data[0].length;
3119
- let offset = this.#readIndex - start;
3120
- if (offset > samples) {
3121
- return;
3122
- } else if (offset > 0) {
3123
- samples -= offset;
3124
- start += offset;
3125
- } else {
3126
- offset = 0;
3127
- }
3128
- const end = start + samples;
3129
- const overflow = end - this.#readIndex - this.#buffer[0].length;
3130
- if (overflow >= 0) {
3131
- this.#stalled = false;
3132
- this.#readIndex += overflow;
3133
- }
3134
- if (start > this.#writeIndex) {
3135
- const gapSize = Math.min(start - this.#writeIndex, this.#buffer[0].length);
3136
- if (gapSize === 1) {
3137
- console.warn("floating point inaccuracy detected");
3138
- }
3139
- for (let channel = 0; channel < this.channels; channel++) {
3140
- const dst = this.#buffer[channel];
3141
- for (let i = 0; i < gapSize; i++) {
3142
- const writePos = (this.#writeIndex + i) % dst.length;
3143
- dst[writePos] = 0;
3144
- }
3145
- }
3146
- }
3147
- for (let channel = 0; channel < this.channels; channel++) {
3148
- let src = data[channel];
3149
- src = src.subarray(src.length - samples);
3150
- const dst = this.#buffer[channel];
3151
- if (src.length !== samples) throw new Error("mismatching number of samples");
3152
- for (let i = 0; i < samples; i++) {
3153
- const writePos = (start + i) % dst.length;
3154
- dst[writePos] = src[i];
3155
- }
3156
- }
3157
- if (end > this.#writeIndex) {
3158
- this.#writeIndex = end;
3159
- }
3160
- }
3161
- read(output) {
3162
- if (output.length !== this.channels) throw new Error("wrong number of channels");
3163
- if (this.#stalled) return 0;
3164
- const samples = Math.min(this.#writeIndex - this.#readIndex, output[0].length);
3165
- if (samples === 0) return 0;
3166
- for (let channel = 0; channel < this.channels; channel++) {
3167
- const dst = output[channel];
3168
- const src = this.#buffer[channel];
3169
- if (dst.length !== output[0].length) throw new Error("mismatching number of samples");
3170
- for (let i = 0; i < samples; i++) {
3171
- const readPos = (this.#readIndex + i) % src.length;
3172
- dst[i] = src[readPos];
3173
- }
3174
- }
3175
- this.#readIndex += samples;
3176
- return samples;
3177
- }
3178
- };
3179
-
3180
- // src/audio/shared-ring-buffer.ts
3181
- var WRITE = 0;
3182
- var READ = 1;
3183
- var LATENCY = 2;
3184
- var STALLED = 3;
3185
- var CONTROL_SLOTS = 4;
3186
- function allocSharedRingBuffer(channels, capacity, rate) {
3187
- if (channels <= 0) throw new Error("invalid channels");
3188
- if (capacity <= 0) throw new Error("invalid capacity");
3189
- if (rate <= 0) throw new Error("invalid sample rate");
3190
- const samples = new SharedArrayBuffer(channels * capacity * Float32Array.BYTES_PER_ELEMENT);
3191
- const control = new SharedArrayBuffer(CONTROL_SLOTS * Int32Array.BYTES_PER_ELEMENT);
3192
- const ctrl = new Int32Array(control);
3193
- Atomics.store(ctrl, STALLED, 1);
3194
- return { channels, capacity, rate, samples, control };
3195
- }
3196
- function i32Max(a, b) {
3197
- return (a - b | 0) > 0 ? a : b;
3198
- }
3199
- function slot(idx, capacity) {
3200
- return (idx % capacity + capacity) % capacity;
3201
- }
3202
- function casAdvance(arr, idx, candidate) {
3203
- for (; ; ) {
3204
- const current = Atomics.load(arr, idx);
3205
- if ((candidate - current | 0) <= 0) return current;
3206
- const witnessed = Atomics.compareExchange(arr, idx, current, candidate);
3207
- if (witnessed === current) return candidate;
3208
- }
3209
- }
3210
- var SharedRingBuffer = class _SharedRingBuffer {
3211
- channels;
3212
- capacity;
3213
- rate;
3214
- init;
3215
- #control;
3216
- #samples;
3217
- constructor(init) {
3218
- this.channels = init.channels;
3219
- this.capacity = init.capacity;
3220
- this.rate = init.rate;
3221
- this.init = init;
3222
- this.#control = new Int32Array(init.control);
3223
- this.#samples = [];
3224
- for (let i = 0; i < this.channels; i++) {
3225
- this.#samples.push(
3226
- new Float32Array(init.samples, i * this.capacity * Float32Array.BYTES_PER_ELEMENT, this.capacity)
3227
- );
3228
- }
3229
- }
3230
- /**
3231
- * Insert audio samples at the given timestamp.
3232
- * Main thread only. Handles out-of-order writes, gap filling, and overflow.
3233
- */
3234
- insert(timestamp, data) {
3235
- if (data.length !== this.channels) throw new Error("wrong number of channels");
3236
- let start = Math.round(time_exports.Second.fromMicro(timestamp) * this.rate);
3237
- const originalLength = data[0].length;
3238
- let offset = 0;
3239
- const end = start + originalLength | 0;
3240
- const read = Atomics.load(this.#control, READ);
3241
- const behind = read - start | 0;
3242
- if (behind > 0) {
3243
- if (behind >= originalLength) {
3244
- return;
3245
- }
3246
- offset = behind;
3247
- start = start + behind | 0;
3248
- }
3249
- const samples = originalLength - offset;
3250
- if ((end - read | 0) > this.capacity) {
3251
- casAdvance(this.#control, READ, end - this.capacity | 0);
3252
- }
3253
- const write = Atomics.load(this.#control, WRITE);
3254
- const gap = start - write | 0;
3255
- if (gap > 0) {
3256
- const gapSize = Math.min(gap, this.capacity);
3257
- for (let channel = 0; channel < this.channels; channel++) {
3258
- const dst = this.#samples[channel];
3259
- for (let i = 0; i < gapSize; i++) {
3260
- dst[slot(write + i | 0, this.capacity)] = 0;
3261
- }
3262
- }
3263
- }
3264
- for (let channel = 0; channel < this.channels; channel++) {
3265
- const src = data[channel];
3266
- const dst = this.#samples[channel];
3267
- for (let i = 0; i < samples; i++) {
3268
- dst[slot(start + i | 0, this.capacity)] = src[offset + i];
3269
- }
3270
- }
3271
- Atomics.store(this.#control, WRITE, i32Max(Atomics.load(this.#control, WRITE), end));
3272
- const currentRead = Atomics.load(this.#control, READ);
3273
- const currentWrite = Atomics.load(this.#control, WRITE);
3274
- const latency = Atomics.load(this.#control, LATENCY);
3275
- if ((currentWrite - currentRead | 0) >= latency && latency > 0) {
3276
- Atomics.store(this.#control, STALLED, 0);
3277
- }
3278
- }
3279
- /**
3280
- * Read audio samples into the output buffers.
3281
- * AudioWorklet only. Returns the number of samples read.
3282
- */
3283
- read(output) {
3284
- if (Atomics.load(this.#control, STALLED) === 1) return 0;
3285
- let read = Atomics.load(this.#control, READ);
3286
- const write = Atomics.load(this.#control, WRITE);
3287
- const latency = Atomics.load(this.#control, LATENCY);
3288
- const buffered = write - read | 0;
3289
- if (latency > 0 && buffered > latency) {
3290
- const skipTo = write - latency | 0;
3291
- read = casAdvance(this.#control, READ, skipTo);
3292
- }
3293
- const available = write - read | 0;
3294
- const count = Math.min(available, output[0].length);
3295
- if (count <= 0) return 0;
3296
- for (let channel = 0; channel < this.channels; channel++) {
3297
- const src = this.#samples[channel];
3298
- const dst = output[channel];
3299
- for (let i = 0; i < count; i++) {
3300
- dst[i] = src[slot(read + i | 0, this.capacity)];
3301
- }
3302
- }
3303
- casAdvance(this.#control, READ, read + count | 0);
3304
- return count;
3305
- }
3306
- /** Update the target latency in samples. */
3307
- setLatency(samples) {
3308
- Atomics.store(this.#control, LATENCY, samples);
3309
- }
3310
- /**
3311
- * Allocate a new ring with \`newCapacity\` samples and copy the unread window
3312
- * [READ, WRITE) plus control state into it. Used when growing capacity so
3313
- * we don't drop buffered audio. If \`newCapacity\` is smaller than the unread
3314
- * span, the oldest samples are truncated.
3315
- *
3316
- * Main thread only. \`resize()\` reads from the source \`SharedRingBuffer\` and
3317
- * writes into a freshly allocated buffer from \`allocSharedRingBuffer\`, so it
3318
- * relies on the same invariant as \`insert()\`: no concurrent main-thread
3319
- * writers. The AudioWorklet reader is tolerated via the CAS discipline used
3320
- * by READ/WRITE elsewhere.
3321
- */
3322
- resize(newCapacity) {
3323
- const init = allocSharedRingBuffer(this.channels, newCapacity, this.rate);
3324
- const dst = new _SharedRingBuffer(init);
3325
- const read = Atomics.load(this.#control, READ);
3326
- const write = Atomics.load(this.#control, WRITE);
3327
- const latency = Atomics.load(this.#control, LATENCY);
3328
- const stalled = Atomics.load(this.#control, STALLED);
3329
- const available = write - read | 0;
3330
- const copyCount = Math.max(0, Math.min(available, dst.capacity));
3331
- const copyStart = write - copyCount | 0;
3332
- for (let channel = 0; channel < this.channels; channel++) {
3333
- const src = this.#samples[channel];
3334
- const out = dst.#samples[channel];
3335
- for (let i = 0; i < copyCount; i++) {
3336
- const idx = copyStart + i | 0;
3337
- out[slot(idx, dst.capacity)] = src[slot(idx, this.capacity)];
3338
- }
3339
- }
3340
- Atomics.store(dst.#control, READ, copyStart);
3341
- Atomics.store(dst.#control, WRITE, write);
3342
- Atomics.store(dst.#control, LATENCY, latency);
3343
- Atomics.store(dst.#control, STALLED, stalled);
3344
- return dst;
3345
- }
3346
- /** Current playback timestamp derived from READ position. */
3347
- get timestamp() {
3348
- const read = Atomics.load(this.#control, READ);
3349
- return time_exports.Micro.fromSecond(read / this.rate);
3350
- }
3351
- /** Whether the buffer is stalled (waiting to fill). */
3352
- get stalled() {
3353
- return Atomics.load(this.#control, STALLED) === 1;
3354
- }
3355
- /**
3356
- * Number of buffered samples (WRITE - READ).
3357
- *
3358
- * Non-atomic: WRITE and READ are loaded separately, so a concurrent
3359
- * writer/reader can make the two loads inconsistent. Intended for
3360
- * tests and diagnostics, not control-flow decisions.
3361
- */
3362
- get length() {
3363
- return Atomics.load(this.#control, WRITE) - Atomics.load(this.#control, READ) | 0;
3364
- }
3365
- };
3366
-
3367
- // src/audio/render-worklet.ts
3368
- var Render = class extends AudioWorkletProcessor {
3369
- // Set after init, depending on which path the main thread chose.
3370
- #backend;
3371
- #underflow = 0;
3372
- #stateCounter = 0;
3373
- constructor() {
3374
- super();
3375
- this.port.onmessage = (event) => {
3376
- const msg = event.data;
3377
- if (msg.type === "init-shared") {
3378
- console.log("[audio-worklet] init-shared: using SharedArrayBuffer path");
3379
- this.#backend = new SharedRingBuffer(msg);
3380
- this.#underflow = 0;
3381
- } else if (msg.type === "init-post") {
3382
- console.log("[audio-worklet] init-post: using postMessage path");
3383
- this.#backend = new AudioRingBuffer(msg);
3384
- this.#underflow = 0;
3385
- } else if (msg.type === "data") {
3386
- if (this.#backend instanceof AudioRingBuffer) this.#backend.write(msg.timestamp, msg.data);
3387
- } else if (msg.type === "latency") {
3388
- if (this.#backend instanceof AudioRingBuffer) this.#backend.resize(msg.latency);
3389
- }
3390
- };
3391
- }
3392
- process(_inputs, outputs, _parameters) {
3393
- const output = outputs[0];
3394
- const backend = this.#backend;
3395
- const samplesRead = backend?.read(output) ?? 0;
3396
- if (samplesRead < output[0].length) {
3397
- this.#underflow += output[0].length - samplesRead;
3398
- } else if (this.#underflow > 0 && backend) {
3399
- console.debug(\`audio underflow: \${Math.round(1e3 * this.#underflow / backend.rate)}ms\`);
3400
- this.#underflow = 0;
3401
- }
3402
- if (backend instanceof AudioRingBuffer) {
3403
- this.#stateCounter++;
3404
- if (this.#stateCounter >= 5) {
3405
- this.#stateCounter = 0;
3406
- const state = {
3407
- type: "state",
3408
- timestamp: backend.timestamp,
3409
- stalled: backend.stalled
3410
- };
3411
- this.port.postMessage(state);
3412
- }
3413
- }
3414
- return true;
3415
- }
3416
- };
3417
- registerProcessor("render", Render);
3418
- `, ji = new Blob([Ni], { type: "application/javascript" }), Zi = URL.createObjectURL(ji);
3419
- let Vi = class {
3420
- source;
3421
- enabled;
3422
- #e = new h(void 0);
3423
- context = this.#e;
3424
- // The root of the audio graph, which can be used for custom visualizations.
3425
- #t = new h(void 0);
3426
- // Downcast to AudioNode so it matches Publish.Audio
3427
- root = this.#t;
3428
- #n = new h(void 0);
3429
- sampleRate = this.#n;
3430
- #s = new h(void 0);
3431
- stats = this.#s;
3432
- // Current playback timestamp from worklet
3433
- #i = new h(void 0);
3434
- timestamp = this.#i;
3435
- // Whether the audio buffer is stalled (waiting to fill)
3436
- #r = new h(!0);
3437
- stalled = this.#r;
3438
- // Decode buffer: audio sent to worklet but not yet played
3439
- #a = new h([]);
3440
- // Combined buffered ranges (network jitter + decode buffer)
3441
- #o = new h([]);
3442
- buffered = this.#o;
3443
- // Audio ring bridging main thread and worklet (shared memory or postMessage transport).
3444
- #c;
3445
- #u = new E();
3446
- constructor(e, n) {
3447
- this.source = e, this.source.supported.set(Wi), this.enabled = h.from(n?.enabled ?? !1), this.#u.run(this.#d.bind(this)), this.#u.run(this.#l.bind(this)), this.#u.run(this.#h.bind(this)), this.#u.run(this.#m.bind(this));
3448
- }
3449
- #d(e) {
3450
- const n = e.get(this.source.config);
3451
- if (!n) return;
3452
- const s = n.sampleRate, i = n.numberOfChannels, r = new AudioContext({
3453
- latencyHint: "interactive",
3454
- // We don't use real-time because of the buffer.
3455
- sampleRate: s
3456
- });
3457
- e.set(this.#e, r), e.cleanup(() => r.close()), e.spawn(async () => {
3458
- if (await r.audioWorklet.addModule(Zi), r.state === "closed") return;
3459
- const o = new AudioWorkletNode(r, "render", {
3460
- channelCount: i,
3461
- channelCountMode: "explicit",
3462
- outputChannelCount: [i]
3463
- });
3464
- e.cleanup(() => o.disconnect());
3465
- const c = this.source.sync.buffer.peek(), a = Math.ceil(s * g.Second.fromMilli(c)), u = Fi(o, i, s, a);
3466
- this.#c = u, e.cleanup(() => {
3467
- u.close(), this.#c = void 0;
3468
- }), e.run((l) => {
3469
- const d = g.Milli.fromMicro(l.get(u.timestamp));
3470
- this.#i.set(d), this.#y(d);
3471
- }), e.run((l) => {
3472
- this.#r.set(l.get(u.stalled));
3473
- }), e.set(this.#t, o);
3474
- });
3475
- }
3476
- #l(e) {
3477
- const n = e.getAll([this.enabled, this.#e]);
3478
- if (!n) return;
3479
- const [s, i] = n;
3480
- i.resume();
3481
- }
3482
- #h(e) {
3483
- if (!e.get(this.#t)) return;
3484
- const s = this.#c;
3485
- if (!s) return;
3486
- const i = e.get(this.source.sync.buffer), r = Math.ceil(s.rate * g.Second.fromMilli(i));
3487
- s.setLatency(r);
3488
- }
3489
- #m(e) {
3490
- if (!e.get(this.enabled)) return;
3491
- const s = e.get(this.source.broadcast);
3492
- if (!s) return;
3493
- const i = e.get(this.source.track);
3494
- if (!i) return;
3495
- const r = e.get(this.source.config);
3496
- if (!r) return;
3497
- const o = e.get(s.active);
3498
- if (!o) return;
3499
- const c = o.subscribe(i, te.audio);
3500
- e.cleanup(() => c.close()), r.container.kind === "cmaf" ? this.#g(e, c, r) : this.#p(e, c, r);
3501
- }
3502
- #p(e, n, s) {
3503
- const i = s.container.kind === "loc" ? new ke() : new Te(), r = new se(n, {
3504
- format: i,
3505
- latency: this.source.sync.buffer
3506
- });
3507
- e.cleanup(() => r.close()), e.run((o) => {
3508
- const c = o.get(r.buffered), a = o.get(this.#a);
3509
- this.#o.update(() => Ae(c, a));
3510
- }), e.spawn(async () => {
3511
- if (!await ot()) return;
3512
- let c = 0;
3513
- const a = new AudioDecoder({
3514
- output: (l) => {
3515
- if (c++, c <= 3) {
3516
- l.close();
3517
- return;
3518
- }
3519
- this.#f(l);
3520
- },
3521
- error: (l) => console.error(l)
3522
- });
3523
- e.cleanup(() => {
3524
- a.state !== "closed" && a.close();
3525
- });
3526
- const u = s.codec === "opus" ? void 0 : s.description ? $(s.description) : void 0;
3527
- for (a.configure({
3528
- ...s,
3529
- description: u
3530
- }); ; ) {
3531
- const l = await r.next();
3532
- if (!l) break;
3533
- const { frame: d } = l;
3534
- if (!d) continue;
3535
- const f = g.Milli.fromMicro(d.timestamp);
3536
- this.source.sync.received(f, "audio"), this.#s.update((b) => ({
3537
- bytesReceived: (b?.bytesReceived ?? 0) + d.data.byteLength
3538
- }));
3539
- const p = new EncodedAudioChunk({
3540
- type: d.keyframe ? "key" : "delta",
3541
- data: d.data,
3542
- timestamp: d.timestamp
3543
- });
3544
- a.decode(p);
3545
- }
3546
- });
3547
- }
3548
- #g(e, n, s) {
3549
- if (s.container.kind !== "cmaf") return;
3550
- const i = K(s.container.init), r = oe(i), o = s.codec === "opus" ? void 0 : s.description ? $(s.description) : r.description, c = new se(n, {
3551
- format: new Wt(r),
3552
- latency: this.source.sync.buffer
3553
- });
3554
- e.cleanup(() => c.close()), e.run((a) => {
3555
- const u = a.get(c.buffered), l = a.get(this.#a);
3556
- this.#o.update(() => Ae(u, l));
3557
- }), e.spawn(async () => {
3558
- if (!await ot()) return;
3559
- const u = new AudioDecoder({
3560
- output: (l) => this.#f(l),
3561
- error: (l) => console.error(l)
3562
- });
3563
- for (e.cleanup(() => {
3564
- u.state !== "closed" && u.close();
3565
- }), u.configure({
3566
- codec: s.codec,
3567
- sampleRate: s.sampleRate,
3568
- numberOfChannels: s.numberOfChannels,
3569
- description: o
3570
- }); ; ) {
3571
- const l = await c.next();
3572
- if (!l) break;
3573
- const { frame: d } = l;
3574
- if (!d) continue;
3575
- const f = g.Milli.fromMicro(d.timestamp);
3576
- if (this.source.sync.received(f, "audio"), this.#s.update((p) => ({
3577
- bytesReceived: (p?.bytesReceived ?? 0) + d.data.byteLength
3578
- })), u.state === "closed") break;
3579
- u.decode(
3580
- new EncodedAudioChunk({
3581
- type: d.keyframe ? "key" : "delta",
3582
- data: d.data,
3583
- timestamp: d.timestamp
3584
- })
3585
- );
3586
- }
3587
- });
3588
- }
3589
- #f(e) {
3590
- const n = e.timestamp, s = g.Milli.fromMicro(n), i = this.#c;
3591
- if (!i) {
3592
- e.close();
3593
- return;
3594
- }
3595
- const r = e.numberOfFrames / e.sampleRate * 1e6, o = g.Milli.fromMicro(r), c = g.Milli.add(s, o);
3596
- this.#w(s, c);
3597
- const a = Math.min(e.numberOfChannels, i.channels), u = [];
3598
- for (let l = 0; l < a; l++) {
3599
- const d = new Float32Array(e.numberOfFrames);
3600
- e.copyTo(d, { format: "f32-planar", planeIndex: l }), u.push(d);
3601
- }
3602
- i.insert(n, u), e.close();
3603
- }
3604
- #w(e, n) {
3605
- e > n || this.#a.mutate((s) => {
3606
- for (const i of s)
3607
- if (e <= i.end + 1 && n >= i.start) {
3608
- i.start = g.Milli.min(i.start, e), i.end = g.Milli.max(i.end, n);
3609
- return;
3610
- }
3611
- s.push({ start: e, end: n }), s.sort((i, r) => i.start - r.start);
3612
- });
3613
- }
3614
- #y(e) {
3615
- this.#a.mutate((n) => {
3616
- for (; n.length > 0; ) {
3617
- if (n[0].end >= e) {
3618
- n[0].start = g.Milli.max(n[0].start, e);
3619
- break;
3620
- }
3621
- n.shift();
3622
- }
3623
- });
3624
- }
3625
- close() {
3626
- this.#u.close();
3627
- }
3628
- };
3629
- async function Wi(t) {
3630
- let e;
3631
- if (t.codec !== "opus") {
3632
- if (t.description)
3633
- e = $(t.description);
3634
- else if (t.container.kind === "cmaf")
3635
- try {
3636
- e = oe(K(t.container.init)).description;
3637
- } catch (s) {
3638
- return console.warn(`audio: malformed CMAF init segment for codec ${t.codec}`, s), !1;
3639
- }
3640
- }
3641
- return (await AudioDecoder.isConfigSupported({
3642
- ...t,
3643
- description: e
3644
- })).supported ?? !1;
3645
- }
3646
- const at = 1e-3, Re = 0.2;
3647
- class qi {
3648
- source;
3649
- volume;
3650
- muted;
3651
- // Similar to muted, but controls whether we download audio at all.
3652
- // That way we can be "muted" but also download audio for visualizations.
3653
- paused;
3654
- #e = new E();
3655
- // The volume to use when unmuted.
3656
- #t = 0.5;
3657
- // The gain node used to adjust the volume.
3658
- #n = new h(void 0);
3659
- constructor(e, n) {
3660
- this.source = e, this.volume = h.from(n?.volume ?? 0.5), this.muted = h.from(n?.muted ?? !1), this.paused = h.from(n?.paused ?? n?.muted ?? !1), this.#e.run((s) => {
3661
- s.get(this.muted) ? (this.#t = this.volume.peek() || 0.5, this.volume.set(0)) : this.volume.set(this.#t);
3662
- }), this.#e.run((s) => {
3663
- const i = !s.get(this.paused) && !s.get(this.muted);
3664
- this.source.enabled.set(i);
3665
- }), this.#e.run((s) => {
3666
- const i = s.get(this.volume);
3667
- this.muted.set(i === 0);
3668
- }), this.#e.run((s) => {
3669
- const i = s.get(this.source.root);
3670
- if (!i) return;
3671
- const r = new GainNode(i.context, { gain: s.get(this.volume) });
3672
- i.connect(r), s.set(this.#n, r), s.run((o) => {
3673
- o.get(this.source.enabled) && (r.connect(i.context.destination), o.cleanup(() => r.disconnect()));
3674
- });
3675
- }), this.#e.run((s) => {
3676
- const i = s.get(this.#n);
3677
- if (!i) return;
3678
- s.cleanup(() => i.gain.cancelScheduledValues(i.context.currentTime));
3679
- const r = s.get(this.volume);
3680
- r < at ? (i.gain.exponentialRampToValueAtTime(at, i.context.currentTime + Re), i.gain.setValueAtTime(0, i.context.currentTime + Re + 0.01)) : i.gain.exponentialRampToValueAtTime(r, i.context.currentTime + Re);
3681
- });
3682
- }
3683
- close() {
3684
- this.#e.close();
3685
- }
3686
- }
3687
- class Ht {
3688
- element;
3689
- paused;
3690
- #e;
3691
- #t = new h(void 0);
3692
- mediaSource = this.#t;
3693
- #n = new E();
3694
- constructor(e, n) {
3695
- this.element = h.from(n?.element), this.paused = h.from(n?.paused ?? !1), this.#e = e, this.#n.run(this.#s.bind(this)), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#o.bind(this));
3696
- }
3697
- #s(e) {
3698
- const n = e.get(this.element);
3699
- if (!n) return;
3700
- const s = new MediaSource();
3701
- n.src = URL.createObjectURL(s), e.cleanup(() => URL.revokeObjectURL(n.src)), e.event(
3702
- s,
3703
- "sourceopen",
3704
- () => {
3705
- e.set(this.#t, s);
3706
- },
3707
- { once: !0 }
3708
- ), e.event(s, "error", (i) => {
3709
- console.error("[MSE] MediaSource error event:", i);
3710
- });
3711
- }
3712
- #i(e) {
3713
- const n = e.get(this.element);
3714
- if (!n || e.get(this.paused)) return;
3715
- const i = g.Milli.toSecond(e.get(this.#e.buffer));
3716
- e.interval(() => {
3717
- const r = n.buffered;
3718
- if (r.length === 0) return;
3719
- const c = r.end(r.length - 1) - i, a = c - n.currentTime;
3720
- (a > 0.1 || a < -0.1) && (console.warn("seeking", a > 0 ? "forward" : "backward", Math.abs(a).toFixed(3), "seconds"), n.currentTime = c);
3721
- }, 100);
3722
- }
3723
- #r(e) {
3724
- const n = e.get(this.element);
3725
- if (!n) return;
3726
- const s = e.get(this.mediaSource);
3727
- s && e.interval(async () => {
3728
- for (const i of s.sourceBuffers) {
3729
- for (; i.updating; )
3730
- await new Promise((r) => i.addEventListener("updateend", r, { once: !0 }));
3731
- n.currentTime > 10 && i.remove(0, n.currentTime - 10);
3732
- }
3733
- }, 1e3);
3734
- }
3735
- #a(e) {
3736
- const n = e.get(this.element);
3737
- if (!n) return;
3738
- const s = e.get(this.paused);
3739
- s && !n.paused ? n.pause() : !s && n.paused && n.play().catch((i) => {
3740
- console.error("[MSE] MediaElement play error:", i);
3741
- });
3742
- }
3743
- // Seek to the target position based on the reference and latency.
3744
- #o(e) {
3745
- const n = e.get(this.element);
3746
- if (!n || e.get(this.paused)) return;
3747
- const i = e.get(this.#e.reference);
3748
- if (i === void 0) return;
3749
- const r = e.get(this.#e.buffer), o = g.Milli.sub(g.Milli.sub(g.Milli.now(), i), r);
3750
- n.currentTime = g.Milli.toSecond(o);
3751
- }
3752
- close() {
3753
- this.#n.close();
3754
- }
3755
- }
3756
- const Rr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3757
- __proto__: null,
3758
- Muxer: Ht
3759
- }, Symbol.toStringTag, { value: "Module" })), Hi = 20, ct = 100;
3760
- class je {
3761
- // The earliest time we've received a frame, relative to its timestamp.
3762
- // This will keep being updated as we catch up to the live playhead then will be relatively static.
3763
- #e = new h(void 0);
3764
- reference = this.#e;
3765
- // The latency setting: "real-time" auto-computes jitter from RTT, a number sets a fixed jitter.
3766
- latency;
3767
- // The jitter buffer in milliseconds (always numeric).
3768
- // In "real-time" mode this is updated automatically from RTT.
3769
- // When latency is a number, jitter equals that number.
3770
- jitter;
3771
- // Any additional delay required for audio or video.
3772
- audio;
3773
- video;
3774
- // The total buffer required: jitter + max(audio, video).
3775
- #t = new h(g.Milli.zero);
3776
- buffer = this.#t;
3777
- // A ghetto way to learn when the reference/buffer changes.
3778
- // There's probably a way to use Effect, but lets keep it simple for now.
3779
- #n;
3780
- // The media timestamp of the most recently received frame.
3781
- timestamp = new h(void 0);
3782
- // Per-label late-frame tracking: accumulate count and max lateness, flush on recovery.
3783
- #s = /* @__PURE__ */ new Map();
3784
- // The connection used for "real-time" jitter: PROBE supplies RTT.
3785
- #i;
3786
- // Minimum RTT seen, used as the baseline for jitter calculation.
3787
- // Avoids inflating jitter due to bufferbloat.
3788
- #r;
3789
- signals = new E();
3790
- constructor(e) {
3791
- this.latency = h.from(e?.latency ?? "real-time"), this.jitter = new h(ct), this.#i = e?.connection, this.audio = h.from(e?.audio), this.video = h.from(e?.video), this.#n = Promise.withResolvers(), this.signals.run(this.#a.bind(this)), this.signals.run(this.#o.bind(this));
3792
- }
3793
- #a(e) {
3794
- const n = e.get(this.latency);
3795
- if (typeof n == "number") {
3796
- this.#r = void 0, this.jitter.set(n);
3797
- return;
3798
- }
3799
- const i = (this.#i ? e.get(this.#i) : void 0)?.rtt, r = i ? e.get(i) : void 0;
3800
- if (r !== void 0) {
3801
- this.#r = this.#r !== void 0 ? Math.min(this.#r, r) : r;
3802
- const o = Math.max(Hi, this.#r * 1.25);
3803
- this.jitter.set(o);
3804
- return;
3805
- }
3806
- this.#r = void 0, this.jitter.set(ct);
3807
- }
3808
- #o(e) {
3809
- const n = e.get(this.jitter), s = e.get(this.video) ?? g.Milli.zero, i = e.get(this.audio) ?? g.Milli.zero, r = g.Milli.add(g.Milli.max(s, i), n);
3810
- this.#t.set(r), this.#n.resolve(), this.#n = Promise.withResolvers();
3811
- }
3812
- // Update the reference if this is the earliest frame we've seen, relative to its timestamp.
3813
- received(e, n = "") {
3814
- this.timestamp.update((o) => o === void 0 || e > o ? e : o);
3815
- const s = g.Milli.now(), i = g.Milli.sub(s, e), r = this.#e.peek();
3816
- if (r !== void 0) {
3817
- const o = g.Milli.add(g.Milli.sub(r, i), this.#t.peek());
3818
- if (o < 0) {
3819
- const c = this.#s.get(n);
3820
- c ? (c.count++, c.maxMs = Math.max(c.maxMs, -o)) : this.#s.set(n, { count: 1, maxMs: -o });
3821
- } else {
3822
- const c = this.#s.get(n);
3823
- if (c) {
3824
- const a = n ? `sync[${n}]` : "sync", u = je.#c(c.maxMs);
3825
- console.debug(`${a}: ${c.count} late frame(s), max ${u} behind`), this.#s.delete(n);
3826
- }
3827
- }
3828
- if (i >= r)
3829
- return;
3830
- }
3831
- this.#e.set(i), this.#n.resolve(), this.#n = Promise.withResolvers();
3832
- }
3833
- // The PTS that should be rendering right now, derived from the reference + buffer.
3834
- // Returns undefined if no frames have been received yet.
3835
- now() {
3836
- const e = this.#e.peek();
3837
- if (e !== void 0)
3838
- return g.Milli.sub(g.Milli.sub(g.Milli.now(), e), this.#t.peek());
3839
- }
3840
- // Sleep until it's time to render this frame.
3841
- async wait(e) {
3842
- if (this.#e.peek() === void 0)
3843
- throw new Error("reference not set; call update() first");
3844
- for (; ; ) {
3845
- const s = g.Milli.now(), i = g.Milli.sub(s, e), r = this.#e.peek();
3846
- if (r === void 0) return;
3847
- const o = g.Milli.add(g.Milli.sub(r, i), this.#t.peek());
3848
- if (o <= 0 || o < 5) return;
3849
- const c = new Promise((u) => setTimeout(u, o)).then(() => !0);
3850
- if (await Promise.race([this.#n.promise, c])) return;
3851
- }
3852
- }
3853
- static #c(e) {
3854
- if (e = Math.round(e), e < 1e3) return `${e}ms`;
3855
- const n = e / 1e3;
3856
- if (n < 60) return `${Math.round(n * 10) / 10}s`;
3857
- const s = n / 60;
3858
- return `${Math.round(s * 10) / 10}m`;
3859
- }
3860
- close() {
3861
- this.signals.close();
3862
- }
3863
- }
3864
- const Gi = 500, Xi = 100;
3865
- class Yi {
3866
- enabled;
3867
- // Don't download any longer
3868
- source;
3869
- // The current track running, held so we can cancel it when the new track is ready.
3870
- #e = new h(void 0);
3871
- // Expose the current frame to render as a signal
3872
- #t = new h(void 0);
3873
- frame = this.#t;
3874
- // The timestamp of the current frame.
3875
- #n = new h(void 0);
3876
- timestamp = this.#n;
3877
- // The display size of the video in pixels, ideally sourced from the catalog.
3878
- #s = new h(void 0);
3879
- display = this.#s;
3880
- #i = new h(!1);
3881
- stalled = this.#i;
3882
- #r = new h(void 0);
3883
- stats = this.#r;
3884
- // Combined buffered ranges (network jitter + decode buffer)
3885
- #a = new h([]);
3886
- buffered = this.#a;
3887
- #o = new E();
3888
- #c() {
3889
- this.#t.update((e) => {
3890
- e?.close();
3891
- }), this.#n.set(void 0);
3892
- }
3893
- constructor(e, n) {
3894
- this.enabled = h.from(n?.enabled ?? !1), this.source = e, this.source.supported.set(Ji), this.#o.run(this.#u.bind(this)), this.#o.run(this.#d.bind(this)), this.#o.run(this.#l.bind(this)), this.#o.run(this.#h.bind(this));
3895
- }
3896
- #u(e) {
3897
- const n = e.getAll([this.enabled, this.source.broadcast, this.source.track, this.source.config]);
3898
- if (!n) {
3899
- this.#e.set(void 0);
3900
- return;
3901
- }
3902
- const [s, i, r, o] = n, c = e.get(i.active);
3903
- if (!c) {
3904
- this.#e.set(void 0), this.#c(), this.#a.set([]);
3905
- return;
3906
- }
3907
- let a = new Ki({
3908
- source: this.source,
3909
- broadcast: c,
3910
- track: r,
3911
- config: o,
3912
- stats: this.#r
3913
- });
3914
- e.cleanup(() => a?.close()), e.run((u) => {
3915
- if (!a) return;
3916
- const l = u.get(this.#e);
3917
- if (l) {
3918
- const d = u.get(a.timestamp), f = u.get(l.timestamp);
3919
- if (!d || f && f > d + Xi) return;
3920
- }
3921
- this.#e.set(a), a = void 0, u.close();
3922
- });
3923
- }
3924
- #d(e) {
3925
- const n = e.get(this.#e);
3926
- if (!n) {
3927
- this.#a.set([]);
3928
- return;
3929
- }
3930
- e.cleanup(() => n.close()), e.run((s) => {
3931
- const i = s.get(n.frame);
3932
- this.#t.update((r) => (r?.close(), i?.clone()));
3933
- }), e.proxy(this.#n, n.timestamp), e.proxy(this.#a, n.buffered);
3934
- }
3935
- #l(e) {
3936
- const n = e.get(this.source.catalog);
3937
- if (!n) return;
3938
- const s = n.display;
3939
- if (s) {
3940
- e.set(this.#s, {
3941
- width: s.width,
3942
- height: s.height
3943
- });
3944
- return;
3945
- }
3946
- const i = e.get(this.frame);
3947
- i && e.set(this.#s, {
3948
- width: i.displayWidth,
3949
- height: i.displayHeight
3950
- });
3951
- }
3952
- #h(e) {
3953
- if (!e.get(this.enabled)) return;
3954
- if (!e.get(this.frame)) {
3955
- this.#i.set(!0);
3956
- return;
3957
- }
3958
- this.#i.set(!1), e.timer(() => {
3959
- this.#i.set(!0);
3960
- }, Gi);
3961
- }
3962
- close() {
3963
- this.#c(), this.#o.close();
3964
- }
3965
- }
3966
- class Ki {
3967
- source;
3968
- broadcast;
3969
- track;
3970
- config;
3971
- stats;
3972
- timestamp = new h(void 0);
3973
- frame = new h(void 0);
3974
- // Network jitter + decode buffer.
3975
- buffered = new h([]);
3976
- // Decoded frames waiting to be rendered.
3977
- #e = new h([]);
3978
- signals = new E();
3979
- constructor(e) {
3980
- const { codedWidth: n, codedHeight: s, ...i } = e.config;
3981
- this.source = e.source, this.broadcast = e.broadcast, this.track = e.track, this.config = i, this.stats = e.stats, this.signals.run(this.#t.bind(this));
3982
- }
3983
- #t(e) {
3984
- const n = this.broadcast.subscribe(this.track, te.video);
3985
- e.cleanup(() => n.close());
3986
- const s = new VideoDecoder({
3987
- output: async (i) => {
3988
- try {
3989
- const r = g.Milli.fromMicro(i.timestamp);
3990
- if (r < (this.timestamp.peek() ?? 0))
3991
- return;
3992
- this.frame.peek() === void 0 && this.frame.set(i.clone());
3993
- const o = this.source.sync.wait(r).then(() => !0);
3994
- if (!await Promise.race([o, e.cancel]) || r < (this.timestamp.peek() ?? 0))
3995
- return;
3996
- this.timestamp.set(r), this.#r(r), this.frame.update((a) => (a?.close(), i.clone()));
3997
- } finally {
3998
- i.close();
3999
- }
4000
- },
4001
- // TODO bubble up error
4002
- error: (i) => {
4003
- console.error(i), e.close();
4004
- }
4005
- });
4006
- e.cleanup(() => {
4007
- s.state !== "closed" && s.close();
4008
- }), this.config.container.kind === "cmaf" ? this.#s(e, n, s) : this.#n(e, n, s);
4009
- }
4010
- #n(e, n, s) {
4011
- const i = this.config.container.kind === "loc" ? new ke() : new Te(), r = new se(n, {
4012
- format: i,
4013
- latency: this.source.sync.buffer
4014
- });
4015
- e.cleanup(() => r.close()), e.run((c) => {
4016
- const a = c.get(r.buffered), u = c.get(this.#e);
4017
- this.buffered.update(() => Ae(a, u));
4018
- }), s.configure({
4019
- ...this.config,
4020
- description: this.config.description ? $(this.config.description) : void 0,
4021
- optimizeForLatency: this.config.optimizeForLatency ?? !0,
4022
- // @ts-expect-error Only supported by Chrome, so the renderer has to flip manually.
4023
- flip: !1
4024
- });
4025
- let o;
4026
- e.spawn(async () => {
4027
- for (; ; ) {
4028
- const c = await r.next();
4029
- if (!c) break;
4030
- const { frame: a, group: u } = c;
4031
- if (!a) {
4032
- o && (o.final = !0);
4033
- continue;
4034
- }
4035
- const l = g.Milli.fromMicro(a.timestamp);
4036
- this.source.sync.received(l, "video");
4037
- const d = new EncodedVideoChunk({
4038
- type: a.keyframe ? "key" : "delta",
4039
- data: a.data,
4040
- timestamp: a.timestamp
4041
- });
4042
- this.stats.update((p) => ({
4043
- frameCount: (p?.frameCount ?? 0) + 1,
4044
- bytesReceived: (p?.bytesReceived ?? 0) + a.data.byteLength
4045
- }));
4046
- const f = o;
4047
- if (f && (f.group === u || f.final && f.group + 1 === u)) {
4048
- const p = g.Milli.fromMicro(f.timestamp), b = g.Milli.fromMicro(a.timestamp);
4049
- this.#i(p, b);
4050
- }
4051
- o = {
4052
- timestamp: a.timestamp,
4053
- group: u,
4054
- final: !1
4055
- }, s.decode(d);
4056
- }
4057
- });
4058
- }
4059
- #s(e, n, s) {
4060
- if (this.config.container.kind !== "cmaf") return;
4061
- const i = K(this.config.container.init), r = oe(i), o = this.config.description ? $(this.config.description) : r.description, c = new se(n, {
4062
- format: new Wt(r),
4063
- latency: this.source.sync.buffer
4064
- });
4065
- e.cleanup(() => c.close()), e.run((u) => {
4066
- const l = u.get(c.buffered), d = u.get(this.#e);
4067
- this.buffered.update(() => Ae(l, d));
4068
- }), s.configure({
4069
- codec: this.config.codec,
4070
- description: o,
4071
- optimizeForLatency: this.config.optimizeForLatency ?? !0,
4072
- // @ts-expect-error Only supported by Chrome, so the renderer has to flip manually.
4073
- flip: !1
4074
- });
4075
- let a;
4076
- e.spawn(async () => {
4077
- for (; ; ) {
4078
- const u = await c.next();
4079
- if (!u) break;
4080
- const { frame: l, group: d } = u;
4081
- if (!l) {
4082
- a && (a.final = !0);
4083
- continue;
4084
- }
4085
- const f = g.Milli.fromMicro(l.timestamp);
4086
- this.source.sync.received(f, "video"), this.stats.update((b) => ({
4087
- frameCount: (b?.frameCount ?? 0) + 1,
4088
- bytesReceived: (b?.bytesReceived ?? 0) + l.data.byteLength
4089
- }));
4090
- const p = a;
4091
- if (p && (p.group === d || p.final && p.group + 1 === d)) {
4092
- const b = g.Milli.fromMicro(p.timestamp), w = g.Milli.fromMicro(l.timestamp);
4093
- this.#i(b, w);
4094
- }
4095
- if (a = {
4096
- timestamp: l.timestamp,
4097
- group: d,
4098
- final: !1
4099
- }, s.state === "closed") break;
4100
- s.decode(
4101
- new EncodedVideoChunk({
4102
- type: l.keyframe ? "key" : "delta",
4103
- data: l.data,
4104
- timestamp: l.timestamp
4105
- })
4106
- );
4107
- }
4108
- });
4109
- }
4110
- // Add a range to the decode buffer (decoded, waiting to render)
4111
- #i(e, n) {
4112
- e > n || this.#e.mutate((s) => {
4113
- for (const i of s)
4114
- if (i.start <= n && i.end >= e) {
4115
- i.start = g.Milli.min(i.start, e), i.end = g.Milli.max(i.end, n);
4116
- return;
4117
- }
4118
- s.push({ start: e, end: n }), s.sort((i, r) => i.start - r.start);
4119
- });
4120
- }
4121
- // Trim the decode buffer up to the rendered timestamp
4122
- #r(e) {
4123
- this.#e.mutate((n) => {
4124
- for (; n.length > 0; ) {
4125
- if (n[0].end >= e) {
4126
- n[0].start = g.Milli.max(n[0].start, e);
4127
- break;
4128
- }
4129
- n.shift();
4130
- }
4131
- });
4132
- }
4133
- close() {
4134
- this.signals.close(), this.frame.update((e) => {
4135
- e?.close();
4136
- });
4137
- }
4138
- }
4139
- async function Ji(t) {
4140
- let e;
4141
- if (t.description)
4142
- e = $(t.description);
4143
- else if (t.container.kind === "cmaf")
4144
- try {
4145
- e = oe(K(t.container.init)).description;
4146
- } catch (s) {
4147
- return console.warn(`video: malformed CMAF init segment for codec ${t.codec}`, s), !1;
4148
- }
4149
- const { supported: n } = await VideoDecoder.isConfigSupported({
4150
- codec: t.codec,
4151
- description: e,
4152
- optimizeForLatency: t.optimizeForLatency ?? !0
4153
- });
4154
- if (n) return !0;
4155
- if (t.codec.startsWith("avc3.")) {
4156
- const s = `avc1.${t.codec.slice(5)}`;
4157
- if ((await VideoDecoder.isConfigSupported({
4158
- codec: s,
4159
- description: e,
4160
- optimizeForLatency: t.optimizeForLatency ?? !0
4161
- })).supported)
4162
- return t.codec = s, !0;
4163
- }
4164
- return !1;
4165
- }
4166
- let Qi = class {
4167
- muxer;
4168
- source;
4169
- // TODO implement stats
4170
- #e = new h(void 0);
4171
- stats = this.#e;
4172
- #t = new h([]);
4173
- buffered = this.#t;
4174
- #n = new h(!1);
4175
- stalled = this.#n;
4176
- #s = new h(A.Time.Milli.zero);
4177
- timestamp = this.#s;
4178
- signals = new E();
4179
- constructor(e, n) {
4180
- this.muxer = e, this.source = n, this.source.supported.set(er), this.signals.run(this.#i.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#u.bind(this));
4181
- }
4182
- #i(e) {
4183
- const n = e.get(this.muxer.element);
4184
- if (!n) return;
4185
- const s = e.get(this.muxer.mediaSource);
4186
- if (!s) return;
4187
- const i = e.get(this.source.broadcast);
4188
- if (!i) return;
4189
- const r = e.get(i.active);
4190
- if (!r) return;
4191
- const o = e.get(this.source.track);
4192
- if (!o) return;
4193
- const c = e.get(this.source.config);
4194
- if (!c) return;
4195
- const a = `video/mp4; codecs="${c.codec}"`, u = s.addSourceBuffer(a);
4196
- e.cleanup(() => {
4197
- s.removeSourceBuffer(u), u.abort();
4198
- }), e.event(u, "error", (l) => {
4199
- console.error("[MSE] SourceBuffer error:", l);
4200
- }), e.event(u, "updateend", () => {
4201
- this.#t.set(Gt(u.buffered));
4202
- }), c.container.kind === "cmaf" ? this.#a(e, r, o, c, u, n) : this.#o(e, r, o, c, u, n);
4203
- }
4204
- async #r(e, n) {
4205
- for (; e.updating; )
4206
- await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
4207
- for (e.appendBuffer(n); e.updating; )
4208
- await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
4209
- }
4210
- #a(e, n, s, i, r, o) {
4211
- if (i.container.kind !== "cmaf") throw new Error("unreachable");
4212
- const c = n.subscribe(s, te.video);
4213
- e.cleanup(() => c.close());
4214
- const a = K(i.container.init), u = oe(a);
4215
- e.spawn(async () => {
4216
- for (await this.#r(r, a); ; ) {
4217
- const l = await c.readFrame();
4218
- if (!l) return;
4219
- const d = Pt(l, u);
4220
- this.source.sync.received(A.Time.Milli.fromMicro(d), "video"), await this.#r(r, l), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0));
4221
- }
4222
- });
4223
- }
4224
- #o(e, n, s, i, r, o) {
4225
- const c = n.subscribe(s, te.video);
4226
- e.cleanup(() => c.close());
4227
- const a = i.container.kind === "loc" ? new ke() : new Te(), u = new se(c, {
4228
- format: a,
4229
- latency: this.source.sync.buffer
4230
- });
4231
- e.cleanup(() => u.close()), e.spawn(async () => {
4232
- const l = Ti(i);
4233
- await this.#r(r, l);
4234
- let d = 1, f, p;
4235
- for (; ; ) {
4236
- const b = await u.next();
4237
- if (!b) return;
4238
- if (!b.frame) continue;
4239
- p = b.frame;
4240
- const w = A.Time.Milli.fromMicro(p.timestamp);
4241
- this.source.sync.received(w, "video");
4242
- break;
4243
- }
4244
- for (; ; ) {
4245
- const b = await u.next();
4246
- if (b && !b.frame) continue;
4247
- const w = b?.frame;
4248
- if (w) {
4249
- f = A.Time.Micro.sub(w.timestamp, p.timestamp);
4250
- const _ = A.Time.Milli.fromMicro(w.timestamp);
4251
- this.source.sync.received(_, "video");
4252
- }
4253
- const v = Vt({
4254
- data: p.data,
4255
- timestamp: p.timestamp,
4256
- duration: f ?? 0,
4257
- // Default to 0 duration if there's literally one frame then stream FIN.
4258
- keyframe: p.keyframe,
4259
- sequence: d++
4260
- });
4261
- if (await this.#r(r, v), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0)), !w) return;
4262
- p = w;
4263
- }
4264
- });
4265
- }
4266
- #c(e) {
4267
- const n = e.get(this.muxer.element);
4268
- if (!n) return;
4269
- const s = () => {
4270
- this.#n.set(n.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA);
4271
- };
4272
- s(), e.event(n, "waiting", s), e.event(n, "playing", s), e.event(n, "seeking", s);
4273
- }
4274
- #u(e) {
4275
- const n = e.get(this.muxer.element);
4276
- if (n)
4277
- if ("requestVideoFrameCallback" in n) {
4278
- const s = n;
4279
- let i;
4280
- const r = () => {
4281
- const o = A.Time.Milli.fromSecond(s.currentTime);
4282
- this.#s.set(o), i = s.requestVideoFrameCallback(r);
4283
- };
4284
- i = s.requestVideoFrameCallback(r), e.cleanup(() => s.cancelVideoFrameCallback(i));
4285
- } else
4286
- e.event(n, "timeupdate", () => {
4287
- const s = A.Time.Milli.fromSecond(n.currentTime);
4288
- this.#s.set(s);
4289
- });
4290
- }
4291
- close() {
4292
- this.source.close(), this.signals.close();
4293
- }
4294
- };
4295
- async function er(t) {
4296
- return MediaSource.isTypeSupported(`video/mp4; codecs="${t.codec}"`);
4297
- }
4298
- class tr {
4299
- decoder;
4300
- // The canvas to render the video to.
4301
- canvas;
4302
- // Whether the video is paused.
4303
- paused;
4304
- // The most recently rendered frame, updated after each rAF paint.
4305
- frame = new h(void 0);
4306
- // The media timestamp of the most recently rendered frame.
4307
- timestamp = new h(void 0);
4308
- #e = new h(void 0);
4309
- #t = new h(!1);
4310
- #n = new E();
4311
- constructor(e, n) {
4312
- this.decoder = e, this.canvas = h.from(n?.canvas), this.paused = h.from(n?.paused ?? !1), this.#n.run((s) => {
4313
- const i = s.get(this.canvas);
4314
- this.#e.set(i?.getContext("2d") ?? void 0);
4315
- }), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#s.bind(this));
4316
- }
4317
- #s(e) {
4318
- const n = e.getAll([this.canvas, this.decoder.display]);
4319
- if (!n) return;
4320
- const [s, i] = n;
4321
- (s.width !== i.width || s.height !== i.height) && (s.width = i.width, s.height = i.height);
4322
- }
4323
- // Track whether the canvas is visible in the viewport and the tab is focused.
4324
- #i(e) {
4325
- const n = e.get(this.canvas);
4326
- if (!n) {
4327
- this.#t.set(!1);
4328
- return;
4329
- }
4330
- let s = !1;
4331
- const i = () => {
4332
- this.#t.set(s && !document.hidden);
4333
- }, r = new IntersectionObserver(
4334
- (o) => {
4335
- for (const c of o)
4336
- s = c.isIntersecting, i();
4337
- },
4338
- { threshold: 0.01 }
4339
- );
4340
- e.event(document, "visibilitychange", i), r.observe(n), e.cleanup(() => r.disconnect()), e.cleanup(() => this.#t.set(!1));
4341
- }
4342
- // Detect when video should be downloaded.
4343
- #r(e) {
4344
- const n = e.get(this.paused), s = e.get(this.#t);
4345
- if (e.cleanup(() => this.decoder.enabled.set(!1)), !n) {
4346
- this.decoder.enabled.set(s);
4347
- return;
4348
- }
4349
- const i = e.get(this.decoder.frame);
4350
- this.decoder.enabled.set(!i);
4351
- }
4352
- #a(e) {
4353
- const n = e.get(this.#e);
4354
- if (!n) return;
4355
- const s = e.get(this.decoder.frame);
4356
- let i = requestAnimationFrame(() => {
4357
- this.#o(n, s), s ? (this.frame.update((r) => (r?.close(), s.clone())), this.timestamp.set(g.Milli.fromMicro(s.timestamp))) : (this.frame.update((r) => {
4358
- r?.close();
4359
- }), this.timestamp.set(void 0)), i = void 0;
4360
- });
4361
- e.cleanup(() => {
4362
- i && cancelAnimationFrame(i);
4363
- });
4364
- }
4365
- #o(e, n) {
4366
- if (!n) {
4367
- e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height);
4368
- return;
4369
- }
4370
- e.save(), e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height), this.decoder.source.catalog.peek()?.flip && (e.scale(-1, 1), e.translate(-e.canvas.width, 0)), e.drawImage(n, 0, 0, e.canvas.width, e.canvas.height), e.restore();
4371
- }
4372
- // Close the track and all associated resources.
4373
- close() {
4374
- this.frame.update((e) => {
4375
- e?.close();
4376
- }), this.timestamp.set(void 0), this.#n.close();
4377
- }
4378
- }
4379
- function nr(t) {
4380
- return (e) => {
4381
- const n = [], s = [];
4382
- for (const [i, r] of e)
4383
- if (r.codedWidth && r.codedHeight) {
4384
- const o = r.codedWidth * r.codedHeight;
4385
- o <= t ? n.push({ name: i, size: o }) : s.push({ name: i, size: o });
4386
- }
4387
- return n.sort((i, r) => r.size - i.size), n.length > 0 ? n.map((i) => i.name) : s.length > 0 ? (s.sort((i, r) => i.size - r.size), [s[0].name]) : e.map(([i]) => i);
4388
- };
4389
- }
4390
- function sr(t, e) {
4391
- return (n) => {
4392
- const s = [], i = [];
4393
- for (const [r, o] of n) {
4394
- if (!o.codedWidth || !o.codedHeight) continue;
4395
- const c = o.codedWidth * o.codedHeight, a = t == null || o.codedWidth <= t, u = e == null || o.codedHeight <= e;
4396
- a && u ? s.push({ name: r, size: c }) : i.push({ name: r, size: c });
4397
- }
4398
- return s.sort((r, o) => o.size - r.size), s.length > 0 ? s.map((r) => r.name) : i.length > 0 ? (i.sort((r, o) => r.size - o.size), [i[0].name]) : n.map(([r]) => r);
4399
- };
4400
- }
4401
- function ir(t) {
4402
- return (e) => {
4403
- const n = [], s = [];
4404
- for (const [i, r] of e)
4405
- r.bitrate != null && r.bitrate <= t ? n.push({ name: i, bitrate: r.bitrate }) : r.bitrate != null && s.push({ name: i, bitrate: r.bitrate });
4406
- return n.sort((i, r) => r.bitrate - i.bitrate), n.length > 0 ? n.map((i) => i.name) : s.length > 0 ? (s.sort((i, r) => i.bitrate - r.bitrate), [s[0].name]) : e.map(([i]) => i);
4407
- };
4408
- }
4409
- function rr(t) {
4410
- let e = t[0];
4411
- for (const n of t) {
4412
- const [, s] = n, [, i] = e, r = (s.codedWidth ?? 0) * (s.codedHeight ?? 0), o = (i.codedWidth ?? 0) * (i.codedHeight ?? 0);
4413
- if (r !== o) {
4414
- r > o && (e = n);
4415
- continue;
4416
- }
4417
- (s.bitrate ?? 0) > (i.bitrate ?? 0) && (e = n);
4418
- }
4419
- return e[0];
4420
- }
4421
- let or = class {
4422
- broadcast;
4423
- target;
4424
- #e = new h(void 0);
4425
- catalog = this.#e;
4426
- #t = new h({});
4427
- available = this.#t;
4428
- // The name of the active rendition.
4429
- #n = new h(void 0);
4430
- track = this.#n;
4431
- #s = new h(void 0);
4432
- config = this.#s;
4433
- sync;
4434
- supported;
4435
- #i = new E();
4436
- constructor(e, n) {
4437
- this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.sync = e, this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#a.bind(this)), this.#i.run(this.#o.bind(this));
4438
- }
4439
- #r(e) {
4440
- const n = e.get(this.broadcast);
4441
- if (!n) return;
4442
- const s = e.get(n.catalog)?.video;
4443
- s && e.set(this.#e, s);
4444
- }
4445
- #a(e) {
4446
- const n = e.get(this.supported);
4447
- if (!n) return;
4448
- const s = e.get(this.#e)?.renditions ?? {};
4449
- e.spawn(async () => {
4450
- const i = {};
4451
- for (const [r, o] of Object.entries(s))
4452
- await n(o) && (i[r] = o);
4453
- Object.keys(i).length === 0 && Object.keys(s).length > 0 && console.warn("[Source] No supported video renditions found:", s), this.#t.set(i);
4454
- });
4455
- }
4456
- #o(e) {
4457
- const n = e.get(this.#t);
4458
- if (Object.keys(n).length === 0) return;
4459
- const s = e.get(this.target);
4460
- if (s?.name && s.name in n) {
4461
- const a = n[s.name];
4462
- e.set(this.#n, s.name), e.set(this.#s, a), e.set(this.sync.video, a.jitter);
4463
- return;
4464
- }
4465
- let i = s;
4466
- if (!s?.bitrate) {
4467
- const a = e.get(this.broadcast), l = (a ? e.get(a.connection) : void 0)?.recvBandwidth;
4468
- if (l) {
4469
- const d = e.get(l);
4470
- if (d != null) {
4471
- const f = Math.round(d * 0.8);
4472
- i = { ...s, bitrate: f };
4473
- }
4474
- }
4475
- }
4476
- const r = this.#c(n, i);
4477
- if (!r) return;
4478
- const o = n[r];
4479
- e.set(this.#n, r), e.set(this.#s, o);
4480
- const c = o.jitter ?? (o.framerate ? Math.ceil(1e3 / o.framerate) : void 0);
4481
- e.set(this.sync.video, c);
4482
- }
4483
- /**
4484
- * Select the best rendition using a generic filter system.
4485
- *
4486
- * Each enabled filter returns matching renditions sorted by preference.
4487
- * The first rendition present in every filter's output is selected.
4488
- * If no rendition satisfies all filters, a warning is logged.
4489
- */
4490
- #c(e, n) {
4491
- const s = Object.entries(e);
4492
- if (s.length === 0) return;
4493
- if (s.length === 1) return s[0][0];
4494
- const i = [];
4495
- if (n?.pixels != null && i.push(nr(n.pixels)), (n?.width != null || n?.height != null) && i.push(sr(n.width, n.height)), n?.bitrate != null && i.push(ir(n.bitrate)), i.length === 0)
4496
- return rr(s);
4497
- const r = i.map((c) => c(s)), o = r.map((c) => new Set(c));
4498
- for (const c of r[0])
4499
- if (o.every((a) => a.has(c)))
4500
- return c;
4501
- console.warn("conflicting rendition filters, no rendition satisfies all criteria");
4502
- }
4503
- close() {
4504
- this.#i.close();
4505
- }
4506
- };
4507
- function Gt(t) {
4508
- const e = [];
4509
- for (let n = 0; n < t.length; n++) {
4510
- const s = A.Time.Milli.fromSecond(t.start(n)), i = A.Time.Milli.fromSecond(t.end(n));
4511
- e.push({ start: s, end: i });
4512
- }
4513
- return e;
4514
- }
4515
- class ar {
4516
- // The source of the video.
4517
- source;
4518
- // The stats of the video.
4519
- stats = new h(void 0);
4520
- // We're currently stalled waiting for the next frame
4521
- stalled = new h(!1);
4522
- // Buffered time ranges
4523
- buffered = new h([]);
4524
- // The timestamp of the current frame
4525
- timestamp = new h(A.Time.Milli.zero);
4526
- constructor(e) {
4527
- this.source = e;
4528
- }
4529
- }
4530
- class cr {
4531
- source;
4532
- // The volume of the audio, between 0 and 1.
4533
- volume = new h(0.5);
4534
- // Whether the audio is muted.
4535
- muted = new h(!1);
4536
- // The stats of the audio.
4537
- stats = new h(void 0);
4538
- // Buffered time ranges
4539
- buffered = new h([]);
4540
- // The AudioContext used for playback (set by the WebCodecs backend; undefined under MSE).
4541
- context = new h(void 0);
4542
- constructor(e) {
4543
- this.source = e;
4544
- }
4545
- }
4546
- class Dr {
4547
- element = new h(void 0);
4548
- broadcast;
4549
- latency;
4550
- jitter;
4551
- paused;
4552
- video;
4553
- #e;
4554
- audio;
4555
- #t;
4556
- // Used to sync audio and video playback at a target delay.
4557
- sync;
4558
- signals = new E();
4559
- constructor(e) {
4560
- this.element = h.from(e?.element), this.broadcast = h.from(e?.broadcast), this.sync = new je({ latency: e?.latency, connection: e?.connection }), this.latency = this.sync.latency, this.jitter = this.sync.jitter, this.#e = new or(this.sync, {
4561
- broadcast: this.broadcast
4562
- }), this.#t = new hr(this.sync, {
4563
- broadcast: this.broadcast
4564
- }), this.video = new ar(this.#e), this.audio = new cr(this.#t), this.paused = h.from(e?.paused ?? !1), this.signals.run(this.#n.bind(this));
4565
- }
4566
- #n(e) {
4567
- const n = e.get(this.element);
4568
- n && (n instanceof HTMLCanvasElement ? this.#s(e, n) : n instanceof HTMLVideoElement && this.#i(e, n));
4569
- }
4570
- #s(e, n) {
4571
- const s = new Yi(this.#e), i = new Vi(this.#t), r = new qi(i, {
4572
- volume: this.audio.volume,
4573
- muted: this.audio.muted,
4574
- paused: this.paused
4575
- }), o = new tr(s, {
4576
- canvas: n,
4577
- paused: this.paused
4578
- });
4579
- e.cleanup(() => {
4580
- s.close(), i.close(), r.close(), o.close();
4581
- }), e.proxy(this.video.stats, s.stats), e.proxy(this.video.buffered, s.buffered), e.proxy(this.video.stalled, s.stalled), e.proxy(this.video.timestamp, s.timestamp), e.proxy(this.audio.stats, i.stats), e.proxy(this.audio.buffered, i.buffered), e.proxy(this.audio.context, i.context);
4582
- }
4583
- #i(e, n) {
4584
- const s = new Ht(this.sync, {
4585
- paused: this.paused,
4586
- element: n
4587
- }), i = new Qi(s, this.#e), r = new ur(s, this.#t, {
4588
- volume: this.audio.volume,
4589
- muted: this.audio.muted
4590
- });
4591
- e.cleanup(() => {
4592
- i.close(), r.close(), s.close();
4593
- }), e.proxy(this.video.stats, i.stats), e.proxy(this.video.buffered, i.buffered), e.proxy(this.video.stalled, i.stalled), e.proxy(this.video.timestamp, i.timestamp), e.proxy(this.audio.stats, r.stats), e.proxy(this.audio.buffered, r.buffered), e.proxy(this.audio.context, r.context);
4594
- }
4595
- close() {
4596
- this.signals.close(), this.#e.close(), this.#t.close(), this.sync.close();
4597
- }
4598
- }
4599
- class ur {
4600
- muxer;
4601
- source;
4602
- volume;
4603
- muted;
4604
- #e = new h(void 0);
4605
- stats = this.#e;
4606
- #t = new h([]);
4607
- buffered = this.#t;
4608
- // MSE plays through the <video> element, not WebAudio.
4609
- context = new h(void 0);
4610
- #n = new E();
4611
- constructor(e, n, s) {
4612
- this.muxer = e, this.source = n, this.source.supported.set(lr), this.volume = h.from(s?.volume ?? 0.5), this.muted = h.from(s?.muted ?? !1), this.#n.run(this.#s.bind(this)), this.#n.run(this.#o.bind(this));
4613
- }
4614
- #s(e) {
4615
- const n = e.get(this.muxer.element);
4616
- if (!n) return;
4617
- const s = e.get(this.muxer.mediaSource);
4618
- if (!s) return;
4619
- const i = e.get(this.source.broadcast);
4620
- if (!i) return;
4621
- const r = e.get(i.active);
4622
- if (!r) return;
4623
- const o = e.get(this.source.track);
4624
- if (!o) return;
4625
- const c = e.get(this.source.config);
4626
- if (!c) return;
4627
- const a = `audio/mp4; codecs="${c.codec}"`, u = s.addSourceBuffer(a);
4628
- e.cleanup(() => {
4629
- s.removeSourceBuffer(u), u.abort();
4630
- }), e.event(u, "error", (d) => {
4631
- console.error("[MSE] SourceBuffer error:", d);
4632
- }), e.event(u, "updateend", () => {
4633
- this.#t.set(Gt(u.buffered));
4634
- });
4635
- const l = r.subscribe(o, te.audio);
4636
- e.cleanup(() => l.close()), c.container.kind === "cmaf" ? this.#r(e, l, c, u, n) : this.#a(e, l, c, u, n);
4637
- }
4638
- async #i(e, n) {
4639
- for (; e.updating; )
4640
- await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
4641
- for (e.appendBuffer(n); e.updating; )
4642
- await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
4643
- }
4644
- #r(e, n, s, i, r) {
4645
- if (s.container.kind !== "cmaf") throw new Error("unreachable");
4646
- const o = K(s.container.init), c = oe(o);
4647
- e.spawn(async () => {
4648
- for (await this.#i(i, o); ; ) {
4649
- const a = await n.readFrame();
4650
- if (!a) return;
4651
- const u = Pt(a, c);
4652
- this.source.sync.received(A.Time.Milli.fromMicro(u), "audio"), await this.#i(i, a), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0));
4653
- }
4654
- });
4655
- }
4656
- #a(e, n, s, i, r) {
4657
- const o = s.container.kind === "loc" ? new ke() : new Te(), c = new se(n, {
4658
- format: o,
4659
- latency: this.source.sync.buffer
4660
- });
4661
- e.cleanup(() => c.close()), e.spawn(async () => {
4662
- const a = Ui(s);
4663
- await this.#i(i, a);
4664
- let u = 1, l, d;
4665
- for (; ; ) {
4666
- const f = await c.next();
4667
- if (!f) return;
4668
- if (!f.frame) continue;
4669
- d = f.frame;
4670
- const p = A.Time.Milli.fromMicro(d.timestamp);
4671
- this.source.sync.received(p, "audio");
4672
- break;
4673
- }
4674
- for (; ; ) {
4675
- const f = await c.next();
4676
- if (f && !f.frame) continue;
4677
- const p = f?.frame;
4678
- if (p) {
4679
- l = A.Time.Micro.sub(p.timestamp, d.timestamp);
4680
- const w = A.Time.Milli.fromMicro(p.timestamp);
4681
- this.source.sync.received(w, "audio");
4682
- }
4683
- const b = Vt({
4684
- data: d.data,
4685
- timestamp: d.timestamp,
4686
- duration: l ?? 0,
4687
- // Default to 0 duration if there's literally one frame then stream FIN.
4688
- keyframe: d.keyframe,
4689
- sequence: u++
4690
- });
4691
- if (await this.#i(i, b), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0)), !p) return;
4692
- d = p;
4693
- }
4694
- });
4695
- }
4696
- #o(e) {
4697
- const n = e.get(this.muxer.element);
4698
- if (!n) return;
4699
- const s = e.get(this.volume), i = e.get(this.muted);
4700
- i && !n.muted ? n.muted = !0 : !i && n.muted && (n.muted = !1), s !== n.volume && (n.volume = s), e.event(n, "volumechange", () => {
4701
- this.volume.set(n.volume);
4702
- });
4703
- }
4704
- close() {
4705
- this.#n.close();
4706
- }
4707
- }
4708
- async function lr(t) {
4709
- return MediaSource.isTypeSupported(`audio/mp4; codecs="${t.codec}"`);
4710
- }
4711
- const dr = 128;
4712
- class hr {
4713
- broadcast;
4714
- target;
4715
- #e = new h(void 0);
4716
- catalog = this.#e;
4717
- #t = new h({});
4718
- available = this.#t;
4719
- #n = new h(void 0);
4720
- track = this.#n;
4721
- #s = new h(void 0);
4722
- config = this.#s;
4723
- supported;
4724
- // Used to target a latency and synchronize playback of video with audio.
4725
- sync;
4726
- #i = new E();
4727
- constructor(e, n) {
4728
- this.sync = e, this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#a.bind(this)), this.#i.run(this.#o.bind(this));
4729
- }
4730
- #r(e) {
4731
- const n = e.get(this.broadcast);
4732
- if (!n) return;
4733
- const s = e.get(n.catalog)?.audio;
4734
- s && e.set(this.#e, s);
4735
- }
4736
- #a(e) {
4737
- const n = e.get(this.#e)?.renditions ?? {}, s = e.get(this.supported);
4738
- s && e.spawn(async () => {
4739
- const i = {};
4740
- for (const [r, o] of Object.entries(n))
4741
- await s(o) && (i[r] = o);
4742
- Object.keys(i).length === 0 && Object.keys(n).length > 0 && console.warn("no supported audio renditions found:", n), this.#t.set(i);
4743
- });
4744
- }
4745
- #o(e) {
4746
- const n = e.get(this.#t);
4747
- if (Object.keys(n).length === 0) return;
4748
- const s = e.get(this.target);
4749
- let i;
4750
- if (s?.name && s.name in n)
4751
- i = { track: s.name, config: n[s.name] };
4752
- else if (i = this.#c(n), !i) return;
4753
- e.set(this.#n, i.track), e.set(this.#s, i.config);
4754
- const r = i.config.jitter ?? fr(i.config) ?? 0, o = Math.ceil(dr / i.config.sampleRate * 1e3), c = r + o;
4755
- e.set(this.sync.audio, c);
4756
- }
4757
- /**
4758
- * Select rendition based on the configured strategy.
4759
- */
4760
- #c(e) {
4761
- const n = Object.entries(e);
4762
- if (n.length !== 0) {
4763
- for (const [s, i] of n)
4764
- if (i.container.kind === "legacy")
4765
- return { track: s, config: i };
4766
- for (const [s, i] of n)
4767
- if (i.container.kind === "loc")
4768
- return { track: s, config: i };
4769
- for (const [s, i] of n)
4770
- if (i.container.kind === "cmaf")
4771
- return { track: s, config: i };
4772
- }
4773
- }
4774
- close() {
4775
- this.#i.close();
4776
- }
4777
- }
4778
- function fr(t) {
4779
- if (t.codec.startsWith("opus"))
4780
- return 20;
4781
- if (t.codec.startsWith("mp4a"))
4782
- return Math.ceil(1024 / t.sampleRate * 1e3);
4783
- }
4784
- const mr = /* @__PURE__ */ Me([
4785
- /* @__PURE__ */ Ut(["loc", "cmaf", "legacy", "mediatimeline", "eventtimeline"]),
4786
- /* @__PURE__ */ S()
4787
- ]), pr = /* @__PURE__ */ Me([
4788
- /* @__PURE__ */ Ut(["video", "audio", "audiodescription", "caption", "subtitle", "signlanguage"]),
4789
- /* @__PURE__ */ S()
4790
- ]), gr = /* @__PURE__ */ z({
4791
- name: /* @__PURE__ */ S(),
4792
- packaging: mr,
4793
- isLive: /* @__PURE__ */ Ie(),
4794
- role: /* @__PURE__ */ m(pr),
4795
- codec: /* @__PURE__ */ m(/* @__PURE__ */ S()),
4796
- width: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4797
- height: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4798
- framerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4799
- samplerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4800
- channelConfig: /* @__PURE__ */ m(/* @__PURE__ */ S()),
4801
- bitrate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4802
- initData: /* @__PURE__ */ m(/* @__PURE__ */ S()),
4803
- renderGroup: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4804
- altGroup: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4805
- // Non-standard: maximum delay (ms) between consecutive frames on this track.
4806
- // The player's buffer must be at least this large to avoid underruns.
4807
- // Mirrors the `jitter` field in the hang catalog.
4808
- jitter: /* @__PURE__ */ m(/* @__PURE__ */ U())
4809
- }), wr = /* @__PURE__ */ z({
4810
- version: /* @__PURE__ */ ye(1),
4811
- tracks: /* @__PURE__ */ q(gr)
4812
- });
4813
- function yr(t) {
4814
- const n = new TextDecoder().decode(t);
4815
- try {
4816
- const s = JSON.parse(n);
4817
- return wr.parse(s);
4818
- } catch (s) {
4819
- throw console.warn("invalid MSF catalog", n), s;
4820
- }
4821
- }
4822
- async function br(t) {
4823
- const e = await t.readFrame();
4824
- if (e)
4825
- return yr(e);
4826
- }
4827
- const vr = 48e3, ut = 2;
4828
- function Sr(t) {
4829
- let e = "";
4830
- for (let n = 0; n < t.length; n++) e += t[n].toString(16).padStart(2, "0");
4831
- return e;
4832
- }
4833
- function Xt(t) {
4834
- let e;
4835
- try {
4836
- e = t.initData ? K(t.initData) : void 0;
4837
- } catch {
4838
- e = void 0;
4839
- }
4840
- return t.packaging === "cmaf" && t.initData && e ? {
4841
- container: { kind: "cmaf", init: t.initData },
4842
- // hang's CMAF path reads codec metadata from the init segment, so we
4843
- // don't need to surface a separate description here.
4844
- description: void 0
4845
- } : {
4846
- container: { kind: "legacy" },
4847
- description: e ? Sr(e) : void 0
4848
- };
4849
- }
4850
- function Ar(t) {
4851
- if (!t.codec) return;
4852
- const { container: e, description: n } = Xt(t);
4853
- return {
4854
- codec: t.codec,
4855
- container: e,
4856
- description: n,
4857
- codedWidth: t.width != null ? V(t.width) : void 0,
4858
- codedHeight: t.height != null ? V(t.height) : void 0,
4859
- framerate: t.framerate,
4860
- bitrate: t.bitrate != null ? V(t.bitrate) : void 0,
4861
- jitter: t.jitter != null ? V(t.jitter) : void 0
4862
- };
4863
- }
4864
- function _r(t) {
4865
- if (!t.codec) return;
4866
- const e = (() => {
4867
- if (!t.channelConfig) return ut;
4868
- const i = Number.parseInt(t.channelConfig, 10);
4869
- return Number.isFinite(i) ? i : ut;
4870
- })(), { container: n, description: s } = Xt(t);
4871
- return {
4872
- codec: t.codec,
4873
- container: n,
4874
- description: s,
4875
- sampleRate: V(t.samplerate ?? vr),
4876
- numberOfChannels: V(e),
4877
- bitrate: t.bitrate != null ? V(t.bitrate) : void 0,
4878
- jitter: t.jitter != null ? V(t.jitter) : void 0
4879
- };
4880
- }
4881
- function zr(t) {
4882
- const e = {}, n = {};
4883
- for (const i of t.tracks)
4884
- if (i.role === "video") {
4885
- const r = Ar(i);
4886
- r && (e[i.name] = r);
4887
- } else if (i.role === "audio") {
4888
- const r = _r(i);
4889
- r && (n[i.name] = r);
4890
- }
4891
- const s = {};
4892
- return Object.keys(e).length > 0 && (s.video = { renditions: e }), Object.keys(n).length > 0 && (s.audio = { renditions: n }), s;
4893
- }
4894
- const Mr = [...Rt, "manual"];
4895
- function Or(t) {
4896
- if (t !== null)
4897
- return Mr.find((e) => e === t);
4898
- }
4899
- class Lr {
4900
- connection;
4901
- enabled;
4902
- name;
4903
- status = new h("offline");
4904
- reload;
4905
- // `undefined` means auto-detect from the broadcast name extension.
4906
- catalogFormat;
4907
- #e = new h(void 0);
4908
- active = this.#e;
4909
- // The active catalog. Writable so users can supply it directly when
4910
- // catalogFormat is "manual"; otherwise the fetch loop owns writes.
4911
- catalog;
4912
- // All actively announced broadcast paths from the connection.
4913
- #t;
4914
- // Whether `name` is currently in the announced set (or skipping the check).
4915
- // Derived in its own effect so that flaps for unrelated broadcasts don't
4916
- // retrigger the broadcast/catalog subscriptions.
4917
- #n = new h(!1);
4918
- signals = new E();
4919
- constructor(e) {
4920
- this.connection = h.from(e?.connection), this.name = h.from(e?.name ?? en.empty()), this.enabled = h.from(e?.enabled ?? !1), this.reload = h.from(e?.reload ?? !1), this.catalogFormat = h.from(e?.catalogFormat), this.catalog = h.from(e?.catalog), this.#t = e?.announced ?? new h(/* @__PURE__ */ new Set()), this.signals.run(this.#s.bind(this)), this.signals.run(this.#i.bind(this)), this.signals.run(this.#r.bind(this));
4921
- }
4922
- #s(e) {
4923
- if (!e.get(this.reload)) {
4924
- this.#n.set(!0);
4925
- return;
4926
- }
4927
- if (e.get(this.connection)?.url.hostname.endsWith("mediaoverquic.com")) {
4928
- console.warn("Cloudflare relay does not support broadcast discovery yet; ignoring reload signal."), this.#n.set(!0);
4929
- return;
4930
- }
4931
- const i = e.get(this.name), r = e.get(this.#t);
4932
- this.#n.set(r.has(i));
4933
- }
4934
- #i(e) {
4935
- if (!e.get(this.enabled) || !e.get(this.#n)) return;
4936
- const s = e.get(this.connection);
4937
- if (!s) return;
4938
- const i = e.get(this.name), r = s.consume(i);
4939
- e.cleanup(() => r.close()), e.set(this.#e, r, void 0);
4940
- }
4941
- #r(e) {
4942
- if (!e.get(this.enabled)) return;
4943
- const s = e.get(this.catalogFormat), i = e.get(this.name), r = s ?? As(i) ?? Ss;
4944
- if (r === "manual") {
4945
- const l = e.get(this.catalog);
4946
- this.status.set(l ? "live" : "loading");
4947
- return;
4948
- }
4949
- const o = e.get(this.active);
4950
- if (!o) return;
4951
- this.status.set("loading");
4952
- const c = r === "hang" ? "catalog.json" : "catalog", a = o.subscribe(c, te.catalog);
4953
- e.cleanup(() => a.close());
4954
- const u = r === "hang" ? async () => Es(a) : async () => {
4955
- const l = await br(a);
4956
- return l ? zr(l) : void 0;
4957
- };
4958
- e.spawn(async () => {
4959
- try {
4960
- for (; ; ) {
4961
- const l = await Promise.race([e.cancel, u()]);
4962
- if (!l) break;
4963
- console.debug("received catalog", r, this.name.peek(), l), this.catalog.set(l), this.status.set("live");
4964
- }
4965
- } catch (l) {
4966
- console.warn("error fetching catalog", this.name.peek(), l);
4967
- } finally {
4968
- this.catalog.set(void 0), this.status.set("offline");
4969
- }
4970
- });
4971
- }
4972
- close() {
4973
- this.signals.close();
4974
- }
4975
- }
4976
- export {
4977
- Lr as B,
4978
- Mr as C,
4979
- Yi as D,
4980
- qi as E,
4981
- Qi as M,
4982
- te as P,
4983
- tr as R,
4984
- or as S,
4985
- m as a,
4986
- Ie as b,
4987
- Vi as c,
4988
- ur as d,
4989
- hr as e,
4990
- Ur as f,
4991
- Ct as g,
4992
- Dr as h,
4993
- je as i,
4994
- Rr as m,
4995
- z as o,
4996
- Or as p,
4997
- S as s,
4998
- Gt as t
4999
- };
5000
- //# sourceMappingURL=broadcast-CLjMphZS.js.map