@vindral/web-sdk 3.4.3 → 4.0.0-190-g016e452d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CyQYN-2T.js ADDED
@@ -0,0 +1,4310 @@
1
+ var Io = Object.create;
2
+ var ir = Object.defineProperty, So = Object.defineProperties, Uo = Object.getOwnPropertyDescriptor, To = Object.getOwnPropertyDescriptors;
3
+ var qi = Object.getOwnPropertySymbols;
4
+ var Jr = Object.prototype.hasOwnProperty, Kr = Object.prototype.propertyIsEnumerable;
5
+ var pt = (i, t) => (t = Symbol[i]) ? t : Symbol.for("Symbol." + i), Et = (i) => {
6
+ throw TypeError(i);
7
+ }, nr = Math.pow, _i = (i, t, e) => t in i ? ir(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, Yt = (i, t) => {
8
+ for (var e in t || (t = {}))
9
+ Jr.call(t, e) && _i(i, e, t[e]);
10
+ if (qi)
11
+ for (var e of qi(t))
12
+ Kr.call(t, e) && _i(i, e, t[e]);
13
+ return i;
14
+ }, rr = (i, t) => So(i, To(t)), Yr = (i, t) => ir(i, "name", { value: t, configurable: !0 });
15
+ var Qr = (i, t) => {
16
+ var e = {};
17
+ for (var n in i)
18
+ Jr.call(i, n) && t.indexOf(n) < 0 && (e[n] = i[n]);
19
+ if (i != null && qi)
20
+ for (var n of qi(i))
21
+ t.indexOf(n) < 0 && Kr.call(i, n) && (e[n] = i[n]);
22
+ return e;
23
+ };
24
+ var Ve = (i) => {
25
+ var t;
26
+ return [, , , Io((t = i == null ? void 0 : i[pt("metadata")]) != null ? t : null)];
27
+ }, qr = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Ds = (i) => i !== void 0 && typeof i != "function" ? Et("Function expected") : i, Eo = (i, t, e, n, r) => ({ kind: qr[i], name: t, metadata: n, addInitializer: (a) => e._ ? Et("Already initialized") : r.push(Ds(a || null)) }), Jt = (i, t) => _i(t, pt("metadata"), i[3]), Ce = (i, t, e, n) => {
28
+ for (var r = 0, a = i[t >> 1], c = a && a.length; r < c; r++) t & 1 ? a[r].call(e) : n = a[r].call(e, n);
29
+ return n;
30
+ }, X = (i, t, e, n, r, a) => {
31
+ var c, d, f, p, b, m = t & 7, I = !!(t & 8), y = !!(t & 16), E = m > 3 ? i.length + 1 : m ? I ? 1 : 2 : 0, P = qr[m + 5], H = m > 3 && (i[E - 1] = []), T = i[E] || (i[E] = []), g = m && (!y && !I && (r = r.prototype), m < 5 && (m > 3 || !y) && Uo(m < 4 ? r : { get [e]() {
32
+ return s(this, a);
33
+ }, set [e](S) {
34
+ return u(this, a, S);
35
+ } }, e));
36
+ m ? y && m < 4 && Yr(a, (m > 2 ? "set " : m > 1 ? "get " : "") + e) : Yr(r, e);
37
+ for (var Y = n.length - 1; Y >= 0; Y--)
38
+ p = Eo(m, e, f = {}, i[3], T), m && (p.static = I, p.private = y, b = p.access = { has: y ? (S) => Do(r, S) : (S) => e in S }, m ^ 3 && (b.get = y ? (S) => (m ^ 1 ? s : w)(S, r, m ^ 4 ? a : g.get) : (S) => S[e]), m > 2 && (b.set = y ? (S, Tt) => u(S, r, Tt, m ^ 4 ? a : g.set) : (S, Tt) => S[e] = Tt)), d = (0, n[Y])(m ? m < 4 ? y ? a : g[P] : m > 4 ? void 0 : { get: g.get, set: g.set } : r, p), f._ = 1, m ^ 4 || d === void 0 ? Ds(d) && (m > 4 ? H.unshift(d) : m ? y ? a = d : g[P] = d : r = d) : typeof d != "object" || d === null ? Et("Object expected") : (Ds(c = d.get) && (g.get = c), Ds(c = d.set) && (g.set = c), Ds(c = d.init) && H.unshift(c));
39
+ return m || Jt(i, r), g && ir(r, e, g), y ? m ^ 4 ? a : g : r;
40
+ }, l = (i, t, e) => _i(i, typeof t != "symbol" ? t + "" : t, e), ar = (i, t, e) => t.has(i) || Et("Cannot " + e), Do = (i, t) => Object(t) !== t ? Et('Cannot use the "in" operator on this value') : i.has(t), s = (i, t, e) => (ar(i, t, "read from private field"), e ? e.call(i) : t.get(i)), o = (i, t, e) => t.has(i) ? Et("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, e), u = (i, t, e, n) => (ar(i, t, "write to private field"), n ? n.call(i, e) : t.set(i, e), e), w = (i, t, e) => (ar(i, t, "access private method"), e);
41
+ var _r = (i, t, e, n) => ({
42
+ set _(r) {
43
+ u(i, t, r, e);
44
+ },
45
+ get _() {
46
+ return s(i, t, n);
47
+ }
48
+ });
49
+ var h = (i, t, e) => new Promise((n, r) => {
50
+ var a = (f) => {
51
+ try {
52
+ d(e.next(f));
53
+ } catch (p) {
54
+ r(p);
55
+ }
56
+ }, c = (f) => {
57
+ try {
58
+ d(e.throw(f));
59
+ } catch (p) {
60
+ r(p);
61
+ }
62
+ }, d = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(a, c);
63
+ d((e = e.apply(i, t)).next());
64
+ }), A = function(i, t) {
65
+ this[0] = i, this[1] = t;
66
+ }, Dt = (i, t, e) => {
67
+ var n = (c, d, f, p) => {
68
+ try {
69
+ var b = e[c](d), m = (d = b.value) instanceof A, I = b.done;
70
+ Promise.resolve(m ? d[0] : d).then((y) => m ? n(c === "return" ? c : "next", d[1] ? { done: y.done, value: y.value } : y, f, p) : f({ value: y, done: I })).catch((y) => n("throw", y, f, p));
71
+ } catch (y) {
72
+ p(y);
73
+ }
74
+ }, r = (c) => a[c] = (d) => new Promise((f, p) => n(c, d, f, p)), a = {};
75
+ return e = e.apply(i, t), a[pt("asyncIterator")] = () => a, r("next"), r("throw"), r("return"), a;
76
+ }, or = (i) => {
77
+ var t = i[pt("asyncIterator")], e = !1, n, r = {};
78
+ return t == null ? (t = i[pt("iterator")](), n = (a) => r[a] = (c) => t[a](c)) : (t = t.call(i), n = (a) => r[a] = (c) => {
79
+ if (e) {
80
+ if (e = !1, a === "throw") throw c;
81
+ return c;
82
+ }
83
+ return e = !0, {
84
+ done: !1,
85
+ value: new A(new Promise((d) => {
86
+ var f = t[a](c);
87
+ f instanceof Object || Et("Object expected"), d(f);
88
+ }), 1)
89
+ };
90
+ }), r[pt("iterator")] = () => r, n("next"), "throw" in t ? n("throw") : r.throw = (a) => {
91
+ throw a;
92
+ }, "return" in t && n("return"), r;
93
+ }, C = (i, t, e) => (t = i[pt("asyncIterator")]) ? t.call(i) : (i = i[pt("iterator")](), t = {}, e = (n, r) => (r = i[n]) && (t[n] = (a) => new Promise((c, d, f) => (a = r.call(i, a), f = a.done, Promise.resolve(a.value).then((p) => c({ value: p, done: f }), d)))), e("next"), e("return"), t);
94
+ var mt = (i, t, e) => {
95
+ if (t != null) {
96
+ typeof t != "object" && typeof t != "function" && Et("Object expected");
97
+ var n;
98
+ e && (n = t[pt("asyncDispose")]), n === void 0 && (n = t[pt("dispose")]), typeof n != "function" && Et("Object not disposable"), i.push([e, n, t]);
99
+ } else e && i.push([e]);
100
+ return t;
101
+ }, bt = (i, t, e) => {
102
+ var n = typeof SuppressedError == "function" ? SuppressedError : function(c, d, f, p) {
103
+ return p = Error(f), p.name = "SuppressedError", p.error = c, p.suppressed = d, p;
104
+ }, r = (c) => t = e ? new n(c, t, "An error was suppressed during disposal") : (e = !0, c), a = (c) => {
105
+ for (; c = i.pop(); )
106
+ try {
107
+ var d = c[1] && c[1].call(c[2]);
108
+ if (c[0]) return Promise.resolve(d).then(a, (f) => (r(f), a()));
109
+ } catch (f) {
110
+ r(f);
111
+ }
112
+ if (e) throw t;
113
+ };
114
+ return a();
115
+ };
116
+ import { D as x, F as Pr, n as B, B as tr, b as Ao, w as er, i as _, L as Xt, a as Oo, W as Vo, t as Co, m as Bo, c as xo, e as Po } from "./fJLVXBMw.js";
117
+ import { a as Sa, p as Ro, c as Lo } from "./F-U5JXpv.js";
118
+ function Rr(i) {
119
+ const t = new Lr(i);
120
+ return [t, t];
121
+ }
122
+ var jt, Fe, rt, ti;
123
+ class Lr {
124
+ constructor(t) {
125
+ /// The internal queue
126
+ o(this, jt);
127
+ /// Slows down push when the queue is full
128
+ o(this, Fe, new x());
129
+ /// Slows down pop when the queue is empty
130
+ o(this, rt);
131
+ /// The channel is closed
132
+ o(this, ti, !1);
133
+ u(this, jt, new Pr(t));
134
+ }
135
+ close() {
136
+ var t;
137
+ (t = s(this, rt)) == null || t.resolve(), u(this, ti, !0);
138
+ }
139
+ abort(t) {
140
+ var e, n;
141
+ (e = s(this, rt)) == null || e.promise.catch(B), (n = s(this, rt)) == null || n.reject(t);
142
+ }
143
+ push(t) {
144
+ return h(this, null, function* () {
145
+ var e;
146
+ s(this, jt).isFull() && (yield s(this, Fe).promise), s(this, jt).push(t), (e = s(this, rt)) == null || e.resolve(), u(this, rt, new x());
147
+ });
148
+ }
149
+ pop() {
150
+ return h(this, null, function* () {
151
+ var t;
152
+ for (; !(s(this, ti) && s(this, jt).isEmpty()); ) {
153
+ const e = s(this, jt).pop();
154
+ if (e)
155
+ return s(this, Fe).resolve(), u(this, Fe, new x()), e;
156
+ s(this, rt) || u(this, rt, new x()), yield (t = s(this, rt)) == null ? void 0 : t.promise;
157
+ }
158
+ });
159
+ }
160
+ start(t) {
161
+ }
162
+ pull(t) {
163
+ return h(this, null, function* () {
164
+ const e = yield this.pop();
165
+ e ? t.enqueue(e) : t.close();
166
+ });
167
+ }
168
+ cancel(t) {
169
+ this.abort(new Error(t));
170
+ }
171
+ next() {
172
+ return h(this, null, function* () {
173
+ const t = yield this.pop().catch(() => {
174
+ });
175
+ return t ? { done: !1, value: t } : { done: !0, value: void 0 };
176
+ });
177
+ }
178
+ return() {
179
+ return this.close(), Promise.resolve({ done: !0, value: void 0 });
180
+ }
181
+ [Symbol.asyncIterator]() {
182
+ return this;
183
+ }
184
+ }
185
+ jt = new WeakMap(), Fe = new WeakMap(), rt = new WeakMap(), ti = new WeakMap();
186
+ function k(i) {
187
+ return typeof BigInt == "function" ? BigInt(i) : i;
188
+ }
189
+ function Oe() {
190
+ return typeof Symbol.asyncDispose != "symbol" && Object.defineProperty(Symbol, "asyncDispose", { value: Symbol.for("asyncDispose") }), Symbol.asyncDispose;
191
+ }
192
+ function Ua() {
193
+ return typeof Symbol.dispose != "symbol" && Object.defineProperty(Symbol, "dispose", { value: Symbol.for("dispose") }), Symbol.dispose;
194
+ }
195
+ var ei, dr;
196
+ class jo {
197
+ constructor(t, e) {
198
+ o(this, ei);
199
+ l(this, "value");
200
+ l(this, "unlocker");
201
+ this.value = t, this.unlocker = e;
202
+ }
203
+ unlocked() {
204
+ var t;
205
+ return (t = this.unlocker) == null ? void 0 : t.promise;
206
+ }
207
+ [Ua()]() {
208
+ w(this, ei, dr).call(this);
209
+ }
210
+ [Symbol.dispose]() {
211
+ w(this, ei, dr).call(this);
212
+ }
213
+ }
214
+ ei = new WeakSet(), dr = function() {
215
+ this.unlocker.resolve(this.value);
216
+ };
217
+ var _t, te;
218
+ class Go {
219
+ constructor(t) {
220
+ o(this, _t);
221
+ o(this, te, new x());
222
+ u(this, _t, t), s(this, te).resolve(t);
223
+ }
224
+ unsafeValue() {
225
+ return s(this, _t);
226
+ }
227
+ isLocked() {
228
+ return s(this, te).pending;
229
+ }
230
+ lock() {
231
+ return h(this, null, function* () {
232
+ const t = new x();
233
+ t.promise.then((n) => {
234
+ u(this, _t, n);
235
+ }).catch(B);
236
+ const e = s(this, te).promise.then(() => t);
237
+ return u(this, te, t), yield e, new jo(s(this, _t), t);
238
+ });
239
+ }
240
+ }
241
+ _t = new WeakMap(), te = new WeakMap();
242
+ var et, at;
243
+ class ft {
244
+ constructor(t) {
245
+ o(this, et);
246
+ o(this, at);
247
+ u(this, et, t), u(this, at, new x());
248
+ }
249
+ isClosed() {
250
+ var t;
251
+ return !((t = s(this, at)) != null && t.pending);
252
+ }
253
+ /**
254
+ * Return only the current value
255
+ */
256
+ current() {
257
+ return s(this, et);
258
+ }
259
+ /**
260
+ * Return the current value and a promise for the next value
261
+ */
262
+ value() {
263
+ var t;
264
+ return [s(this, et), (t = s(this, at)) == null ? void 0 : t.promise];
265
+ }
266
+ update(t) {
267
+ var e;
268
+ if (!((e = s(this, at)) != null && e.pending))
269
+ throw new Error("ObservableValue is closed");
270
+ u(this, et, t instanceof Function ? t(s(this, et)) : t), s(this, at).resolve(s(this, et)), u(this, at, new x());
271
+ }
272
+ close() {
273
+ var t;
274
+ (t = s(this, at)) == null || t.resolve(s(this, et)), u(this, at, void 0);
275
+ }
276
+ waitFor(t) {
277
+ return h(this, null, function* () {
278
+ if (t(s(this, et)))
279
+ return s(this, et);
280
+ for (; ; ) {
281
+ const [e, n] = this.value();
282
+ if (!n)
283
+ return;
284
+ const r = yield n;
285
+ if (t(r))
286
+ return r;
287
+ }
288
+ });
289
+ }
290
+ [Symbol.asyncIterator]() {
291
+ return Dt(this, null, function* () {
292
+ for (; ; ) {
293
+ const [t, e] = this.value();
294
+ if (yield t, !e)
295
+ return;
296
+ yield new A(e);
297
+ }
298
+ });
299
+ }
300
+ }
301
+ et = new WeakMap(), at = new WeakMap();
302
+ function Ta(i) {
303
+ try {
304
+ return i();
305
+ } catch (t) {
306
+ return t;
307
+ }
308
+ }
309
+ function Ea(i) {
310
+ let t = i.readUint32();
311
+ const e = [i.readUint8(), i.readUint8(), i.readUint8(), i.readUint8()], n = String.fromCharCode.apply(null, e);
312
+ return t === 1 && (t = i.readUint64() - 8), {
313
+ size: t - 8,
314
+ // Subtract header size
315
+ type: n
316
+ };
317
+ }
318
+ function No(i, t) {
319
+ const e = Ea(t), n = new tr(t.readBytes(e.size));
320
+ if (e.type !== i.type)
321
+ throw new Error(`invalid error type: ${e.type}, expected ${i.type}`);
322
+ const r = i.decodeData(n);
323
+ return n.readRemaining(), r;
324
+ }
325
+ function Zt(i) {
326
+ const t = i.readUint8(), e = i.readUint24();
327
+ return {
328
+ version: t,
329
+ flags: e
330
+ };
331
+ }
332
+ const xe = class xe {
333
+ constructor({
334
+ timescale: t,
335
+ presentationTime: e,
336
+ presentationTimeDelta: n,
337
+ schemeIdUri: r,
338
+ value: a,
339
+ eventDuration: c,
340
+ id: d,
341
+ data: f
342
+ }) {
343
+ l(this, "type", xe.type);
344
+ l(this, "timescale");
345
+ l(this, "presentationTime");
346
+ l(this, "presentationTimeDelta");
347
+ l(this, "schemeIdUri");
348
+ l(this, "value");
349
+ l(this, "eventDuration");
350
+ l(this, "id");
351
+ l(this, "data");
352
+ this.timescale = t, this.presentationTime = e, this.presentationTimeDelta = n, this.schemeIdUri = r, this.value = a, this.eventDuration = c, this.id = d, this.data = f;
353
+ }
354
+ static decodeData(t) {
355
+ const { version: e } = Zt(t);
356
+ switch (e) {
357
+ case 1: {
358
+ const n = t.readUint32(), r = t.readUint64(), a = t.readUint32(), c = t.readUint32(), d = t.readUtf8String(), f = t.readUtf8String(), p = t.remaining(), b = t.readBytes(p);
359
+ return new xe({
360
+ timescale: n,
361
+ presentationTime: r,
362
+ eventDuration: a,
363
+ id: c,
364
+ schemeIdUri: d,
365
+ value: f,
366
+ data: b
367
+ });
368
+ }
369
+ case 0: {
370
+ const n = t.readUtf8String(), r = t.readUtf8String(), a = t.readUint32(), c = t.readUint32(), d = t.readUint32(), f = t.readUint32(), p = t.remaining(), b = t.readBytes(p);
371
+ return new xe({ timescale: a, presentationTimeDelta: c, schemeIdUri: n, value: r, eventDuration: d, id: f, data: b });
372
+ }
373
+ default:
374
+ throw new Error(`unsupported version ${e}`);
375
+ }
376
+ }
377
+ };
378
+ l(xe, "type", "emsg");
379
+ let hn = xe;
380
+ const Rs = class Rs {
381
+ constructor(t) {
382
+ l(this, "type", Rs.type);
383
+ l(this, "data");
384
+ this.data = t;
385
+ }
386
+ static decodeData(t) {
387
+ const e = t.readRemaining();
388
+ return new Rs(e);
389
+ }
390
+ };
391
+ l(Rs, "type", "mdat");
392
+ let ln = Rs;
393
+ const Ls = class Ls {
394
+ constructor(t, e, n) {
395
+ l(this, "type", Ls.type);
396
+ l(this, "extra");
397
+ /**
398
+ * The byte offset of the baseMediaDecodeTime field
399
+ */
400
+ l(this, "byteOffset");
401
+ l(this, "baseMediaDecodeTime");
402
+ this.extra = t, this.byteOffset = e, this.baseMediaDecodeTime = n;
403
+ }
404
+ static decodeData(t) {
405
+ const e = Zt(t), n = t.byteOffset();
406
+ let r = 0;
407
+ return e.version === 1 ? r = t.readUint64() : r = t.readUint32(), new Ls(e, n, r);
408
+ }
409
+ };
410
+ l(Ls, "type", "tfdt");
411
+ let dn = Ls;
412
+ const O = class O {
413
+ constructor(t, e, n) {
414
+ l(this, "type", O.type);
415
+ l(this, "dataOffset");
416
+ l(this, "firstSampleFlags");
417
+ l(this, "samplesCount");
418
+ l(this, "sampleDurations", []);
419
+ l(this, "sampleSizes", []);
420
+ l(this, "sampleFlags", []);
421
+ l(this, "sampleCts", []);
422
+ this.dataOffset = e, this.firstSampleFlags = n, this.samplesCount = t;
423
+ }
424
+ is_sync_sample(t) {
425
+ const e = O.FLAG_SAMPLE_FLAG_IS_NON_SYNC | O.FLAG_SAMPLE_DEPENDS_YES, n = this.sampleFlags[t];
426
+ if (typeof n != "undefined")
427
+ return (n & e) === 0;
428
+ if (t === 0 && this.firstSampleFlags)
429
+ return (this.firstSampleFlags & e) === 0;
430
+ }
431
+ static decodeData(t) {
432
+ const { flags: e } = Zt(t), n = t.readUint32();
433
+ let r, a;
434
+ e & O.TRUN_DATA_OFFSET && (r = t.readUint32()), e & O.TRUN_FIRST_SAMPLE_FLAGS && (a = t.readUint32());
435
+ const c = new O(n, r, a);
436
+ for (let d = 0; d < n; d++)
437
+ e & O.SAMPLE_DURATION && c.sampleDurations.push(t.readUint32()), e & O.SAMPLE_SIZE && c.sampleSizes.push(t.readUint32()), e & O.SAMPLE_FLAGS && c.sampleFlags.push(t.readUint32()), e & O.SAMPLE_CTS && c.sampleCts.push(t.readUint32());
438
+ return c;
439
+ }
440
+ };
441
+ l(O, "TRUN_DATA_OFFSET", 1), l(O, "TRUN_FIRST_SAMPLE_FLAGS", 4), l(O, "SAMPLE_DURATION", 256), l(O, "SAMPLE_SIZE", 512), l(O, "SAMPLE_FLAGS", 1024), l(O, "SAMPLE_CTS", 2048), l(O, "FLAG_SAMPLE_FLAG_IS_NON_SYNC", 65536), l(O, "FLAG_SAMPLE_DEPENDS_NO", 33554432), l(O, "FLAG_SAMPLE_DEPENDS_YES", 16777216), l(O, "type", "trun");
442
+ let _s = O;
443
+ const js = class js {
444
+ constructor(t, e) {
445
+ l(this, "type", js.type);
446
+ l(this, "tfdt");
447
+ l(this, "trun");
448
+ this.tfdt = t, this.trun = e;
449
+ }
450
+ static decodeData(t) {
451
+ let e, n;
452
+ for (; t.remaining() > 0; ) {
453
+ const r = wt(t);
454
+ r instanceof dn && (e = r), r instanceof _s && (n = r);
455
+ }
456
+ return new js(e, n);
457
+ }
458
+ };
459
+ l(js, "type", "traf");
460
+ let fn = js;
461
+ const Gs = class Gs {
462
+ constructor(t) {
463
+ l(this, "type", Gs.type);
464
+ l(this, "traf");
465
+ this.traf = t;
466
+ }
467
+ static decodeData(t) {
468
+ let e;
469
+ for (; t.remaining() > 0; ) {
470
+ const n = wt(t);
471
+ n instanceof fn && (e = n);
472
+ }
473
+ if (!e)
474
+ throw new Error("No traf found");
475
+ return new Gs(e);
476
+ }
477
+ };
478
+ l(Gs, "type", "moof");
479
+ let wn = Gs;
480
+ const Ns = class Ns {
481
+ constructor() {
482
+ l(this, "type", Ns.type);
483
+ }
484
+ static decodeData(t) {
485
+ return new Ns();
486
+ }
487
+ };
488
+ l(Ns, "type", "mvhd");
489
+ let pn = Ns;
490
+ const Fs = class Fs {
491
+ constructor(t) {
492
+ l(this, "type", Fs.type);
493
+ l(this, "fourCC");
494
+ this.fourCC = t;
495
+ }
496
+ mediaType() {
497
+ switch (this.fourCC) {
498
+ case "vide":
499
+ return "video";
500
+ case "soun":
501
+ return "audio";
502
+ case "sbtl":
503
+ return "text";
504
+ default:
505
+ throw new Error("Unknown media type");
506
+ }
507
+ }
508
+ static decodeData(t) {
509
+ Zt(t), t.readUint32();
510
+ const e = String.fromCharCode(...t.readBytes(4));
511
+ return new Fs(e);
512
+ }
513
+ };
514
+ l(Fs, "type", "hdlr");
515
+ let mn = Fs;
516
+ const Pe = class Pe {
517
+ constructor(t, e, n, r) {
518
+ l(this, "type", Pe.type);
519
+ l(this, "creationTime");
520
+ l(this, "modificationTime");
521
+ l(this, "timescale");
522
+ l(this, "duration");
523
+ this.creationTime = t, this.modificationTime = e, this.timescale = n, this.duration = r;
524
+ }
525
+ static decodeData(t) {
526
+ const { version: e } = Zt(t);
527
+ if (e === 1) {
528
+ const d = t.readUint64(), f = t.readUint64(), p = t.readUint32(), b = t.readUint64();
529
+ return new Pe(d, f, p, b);
530
+ }
531
+ const n = t.readUint32(), r = t.readUint32(), a = t.readUint32(), c = t.readUint32();
532
+ return new Pe(n, r, a, c);
533
+ }
534
+ };
535
+ l(Pe, "type", "mdhd");
536
+ let bn = Pe;
537
+ const Ws = class Ws {
538
+ constructor(t, e, n, r) {
539
+ l(this, "type", Ws.type);
540
+ l(this, "av01");
541
+ l(this, "avc1");
542
+ l(this, "opus");
543
+ l(this, "codec");
544
+ this.avc1 = t, this.av01 = e, this.opus = n, this.codec = r;
545
+ }
546
+ mediaType() {
547
+ return this.avc1 || this.av01 ? "video" : "audio";
548
+ }
549
+ width() {
550
+ var t;
551
+ return (t = this.avc1) == null ? void 0 : t.width;
552
+ }
553
+ height() {
554
+ var t;
555
+ return (t = this.avc1) == null ? void 0 : t.height;
556
+ }
557
+ static decodeData(t) {
558
+ Zt(t);
559
+ const e = t.readUint32();
560
+ let n, r, a, c;
561
+ for (let d = 0; d < e; d++)
562
+ for (; t.remaining() > 0; ) {
563
+ const f = wt(t);
564
+ switch (f.type) {
565
+ case "avc1":
566
+ n = "h264", r = f;
567
+ break;
568
+ case "av01":
569
+ n = "av1", c = f;
570
+ break;
571
+ case "mp4a":
572
+ n = "aac";
573
+ break;
574
+ case "Opus":
575
+ n = "opus", a = f;
576
+ break;
577
+ }
578
+ }
579
+ return new Ws(r, c, a, n);
580
+ }
581
+ };
582
+ l(Ws, "type", "stsd");
583
+ let yn = Ws;
584
+ const $s = class $s {
585
+ constructor(t) {
586
+ l(this, "type", $s.type);
587
+ l(this, "stsd");
588
+ this.stsd = t;
589
+ }
590
+ static decodeData(t) {
591
+ let e;
592
+ for (; t.remaining() > 0; ) {
593
+ const n = wt(t);
594
+ n instanceof yn && (e = n);
595
+ }
596
+ if (!e)
597
+ throw new Error("No stsd found");
598
+ return new $s(e);
599
+ }
600
+ };
601
+ l($s, "type", "stbl");
602
+ let gn = $s;
603
+ const zs = class zs {
604
+ constructor(t) {
605
+ l(this, "type", zs.type);
606
+ l(this, "stbl");
607
+ this.stbl = t;
608
+ }
609
+ static decodeData(t) {
610
+ let e;
611
+ for (; t.remaining() > 0; ) {
612
+ const n = wt(t);
613
+ n instanceof gn && (e = n);
614
+ }
615
+ if (!e)
616
+ throw new Error("No stbl found");
617
+ return new zs(e);
618
+ }
619
+ };
620
+ l(zs, "type", "minf");
621
+ let vn = zs;
622
+ const Ms = class Ms {
623
+ constructor(t, e, n) {
624
+ l(this, "type", Ms.type);
625
+ l(this, "hdlr");
626
+ l(this, "minf");
627
+ l(this, "mdhd");
628
+ this.hdlr = t, this.minf = e, this.mdhd = n;
629
+ }
630
+ static decodeData(t) {
631
+ let e, n, r;
632
+ for (; t.remaining() > 0; ) {
633
+ const a = wt(t);
634
+ a instanceof mn && (e = a), a instanceof vn && (n = a), a instanceof bn && (r = a);
635
+ }
636
+ if (!e)
637
+ throw new Error("No hdlr found");
638
+ if (!n)
639
+ throw new Error("No minf found");
640
+ if (!r)
641
+ throw new Error("No mdhd found");
642
+ return new Ms(e, n, r);
643
+ }
644
+ };
645
+ l(Ms, "type", "mdia");
646
+ let kn = Ms;
647
+ const Hs = class Hs {
648
+ constructor(t, e, n, r, a, c, d, f) {
649
+ l(this, "type", Hs.type);
650
+ l(this, "modificationTime");
651
+ l(this, "creationTime");
652
+ l(this, "trackId");
653
+ l(this, "duration");
654
+ l(this, "alternateGroup");
655
+ l(this, "volume");
656
+ l(this, "width");
657
+ l(this, "height");
658
+ this.modificationTime = t, this.creationTime = e, this.trackId = n, this.duration = r, this.alternateGroup = a, this.volume = c, this.width = d, this.height = f;
659
+ }
660
+ static decodeData(t) {
661
+ const e = Zt(t);
662
+ let n = 0, r = 0;
663
+ e.version === 1 ? (n = t.readUint64(), r = t.readUint64()) : (n = t.readUint32(), r = t.readUint32());
664
+ const a = t.readUint32();
665
+ t.readUint32();
666
+ const c = t.readUint32();
667
+ t.readUint32(), t.readUint32(), t.readUint16();
668
+ const d = t.readUint16(), f = t.readUint16();
669
+ t.readUint16(), new Array(9).fill(0).map(() => t.readUint32());
670
+ const p = t.readUint16();
671
+ t.readUint16();
672
+ const b = t.readUint16();
673
+ return t.readUint16(), new Hs(n, r, a, c, d, f, p, b);
674
+ }
675
+ };
676
+ l(Hs, "type", "tkhd");
677
+ let In = Hs;
678
+ const Xs = class Xs {
679
+ constructor(t, e) {
680
+ l(this, "type", Xs.type);
681
+ l(this, "tkhd");
682
+ l(this, "mdia");
683
+ this.tkhd = t, this.mdia = e;
684
+ }
685
+ static decodeData(t) {
686
+ let e, n;
687
+ for (; t.remaining() > 0; ) {
688
+ const r = wt(t);
689
+ r instanceof In && (e = r), r instanceof kn && (n = r);
690
+ }
691
+ if (!e)
692
+ throw new Error("No tkhd found");
693
+ if (!n)
694
+ throw new Error("No mdia found");
695
+ return new Xs(e, n);
696
+ }
697
+ };
698
+ l(Xs, "type", "trak");
699
+ let Sn = Xs;
700
+ const Zs = class Zs {
701
+ constructor(t, e) {
702
+ l(this, "type", Zs.type);
703
+ l(this, "mvhd");
704
+ l(this, "traks");
705
+ this.mvhd = t, this.traks = e;
706
+ }
707
+ static decodeData(t) {
708
+ let e;
709
+ const n = [];
710
+ for (; t.remaining() > 0; ) {
711
+ const r = wt(t);
712
+ r instanceof Sn && n.push(r), r instanceof pn && (e = r);
713
+ }
714
+ if (!e)
715
+ throw new Error("No mvhd found");
716
+ return new Zs(e, n);
717
+ }
718
+ };
719
+ l(Zs, "type", "moov");
720
+ let Un = Zs;
721
+ const Ys = class Ys {
722
+ constructor(t, e, n, r, a, c, d, f) {
723
+ l(this, "type", Ys.type);
724
+ l(this, "configurationVersion");
725
+ l(this, "avcProfileIndication");
726
+ l(this, "profileCompatibility");
727
+ l(this, "avcLevelIndication");
728
+ l(this, "lengthSizeMinusOne");
729
+ l(this, "sequenceParameterSets");
730
+ l(this, "pictureParameterSets");
731
+ l(this, "bytes");
732
+ this.configurationVersion = t, this.avcProfileIndication = e, this.profileCompatibility = n, this.avcLevelIndication = r, this.lengthSizeMinusOne = a, this.sequenceParameterSets = c, this.pictureParameterSets = d, this.bytes = f;
733
+ }
734
+ static decodeData(t) {
735
+ const e = t.buffer(), n = t.readUint8(), r = t.readUint8(), a = t.readUint8(), c = t.readUint8(), d = t.readUint8() & 3, f = t.readUint8() & 31, p = [];
736
+ for (let I = 0; I < f; I++) {
737
+ const y = t.readBytes(t.readUint16());
738
+ p.push(y);
739
+ }
740
+ const b = t.readUint8(), m = [];
741
+ for (let I = 0; I < b; I++) {
742
+ const y = t.readBytes(t.readUint16());
743
+ m.push(y);
744
+ }
745
+ return new Ys(
746
+ n,
747
+ r,
748
+ a,
749
+ c,
750
+ d,
751
+ p,
752
+ m,
753
+ e
754
+ );
755
+ }
756
+ };
757
+ l(Ys, "type", "avcC");
758
+ let fr = Ys;
759
+ const Js = class Js {
760
+ constructor(t, e, n, r, a) {
761
+ l(this, "type", Js.type);
762
+ l(this, "avcC");
763
+ l(this, "width");
764
+ l(this, "height");
765
+ l(this, "horizontalResolution");
766
+ l(this, "verticalResolution");
767
+ this.avcC = t, this.width = e, this.height = n, this.horizontalResolution = r, this.verticalResolution = a;
768
+ }
769
+ static decodeData(t) {
770
+ t.readUint32(), t.readUint16(), t.readUint16(), t.readUint32(), t.readUint64(), t.readUint32();
771
+ const e = t.readUint16(), n = t.readUint16(), r = t.readUint32(), a = t.readUint32();
772
+ t.readUint32(), t.readUint16(), t.readBytes(32), t.readUint16(), t.readUint16();
773
+ let c;
774
+ for (; t.remaining() > 0; ) {
775
+ const d = wt(t);
776
+ switch (d.type) {
777
+ case "avcC":
778
+ c = d;
779
+ break;
780
+ }
781
+ }
782
+ if (!c)
783
+ throw new Error("no avcC");
784
+ return new Js(c, e, n, r, a);
785
+ }
786
+ };
787
+ l(Js, "type", "avc1");
788
+ let wr = Js;
789
+ const Ks = class Ks {
790
+ constructor() {
791
+ l(this, "type", Ks.type);
792
+ }
793
+ static decodeData(t) {
794
+ return new Ks();
795
+ }
796
+ };
797
+ l(Ks, "type", "dOps");
798
+ let pr = Ks;
799
+ const Qs = class Qs {
800
+ constructor(t, e, n) {
801
+ l(this, "type", Qs.type);
802
+ l(this, "dops");
803
+ l(this, "channelCount");
804
+ l(this, "sampleRate");
805
+ this.dops = t, this.channelCount = e, this.sampleRate = n;
806
+ }
807
+ static decodeData(t) {
808
+ t.readUint32(), t.readUint16(), t.readUint16();
809
+ const e = t.readUint16();
810
+ t.readUint16(), t.readUint32();
811
+ const n = t.readUint16();
812
+ t.readUint16(), t.readUint32();
813
+ const r = t.readUint16();
814
+ t.readUint16(), e === 1 && (t.readUint64(), t.readUint64());
815
+ const a = No(pr, t);
816
+ return new Qs(a, n, r);
817
+ }
818
+ };
819
+ l(Qs, "type", "Opus");
820
+ let mr = Qs;
821
+ const Re = class Re {
822
+ constructor(t, e) {
823
+ l(this, "type", Re.type);
824
+ l(this, "ntpTimestamp");
825
+ l(this, "mediaTime");
826
+ this.ntpTimestamp = t, this.mediaTime = e;
827
+ }
828
+ static decodeData(t) {
829
+ const { version: e } = Zt(t);
830
+ t.readUint32();
831
+ const n = t.readUint32(), r = t.readUint32();
832
+ if (e === 1) {
833
+ const c = t.readUint64();
834
+ return new Re([n, r], c);
835
+ }
836
+ const a = t.readUint32();
837
+ return new Re([n, r], a);
838
+ }
839
+ };
840
+ l(Re, "type", "prft");
841
+ let Tn = Re;
842
+ var si, ii;
843
+ class Fo {
844
+ constructor(t, e) {
845
+ o(this, si);
846
+ o(this, ii);
847
+ u(this, si, t), u(this, ii, e.readBytes(t.size));
848
+ }
849
+ data() {
850
+ return s(this, ii);
851
+ }
852
+ get type() {
853
+ return s(this, si).type;
854
+ }
855
+ }
856
+ si = new WeakMap(), ii = new WeakMap();
857
+ const Wo = {
858
+ moov: Un,
859
+ trak: Sn,
860
+ tkhd: In,
861
+ mvhd: pn,
862
+ moof: wn,
863
+ traf: fn,
864
+ tfdt: dn,
865
+ trun: _s,
866
+ mdat: ln,
867
+ mdia: kn,
868
+ hdlr: mn,
869
+ minf: vn,
870
+ stbl: gn,
871
+ mdhd: bn,
872
+ stsd: yn,
873
+ prft: Tn,
874
+ avc1: wr,
875
+ avcC: fr,
876
+ Opus: mr,
877
+ emsg: hn
878
+ };
879
+ function wt(i) {
880
+ const t = Ea(i), e = Wo[t.type], n = new tr(i.readBytes(t.size));
881
+ if (!e) {
882
+ const a = new Fo(t, n);
883
+ return n.readRemaining(), a;
884
+ }
885
+ const r = e.decodeData(n);
886
+ return n.readRemaining(), r;
887
+ }
888
+ function $o(i) {
889
+ if (i.byteLength < 8)
890
+ throw new Error("Buffer too small");
891
+ const t = new tr(i), e = /* @__PURE__ */ new Map();
892
+ for (; t.remaining() > 0; ) {
893
+ const a = wt(t);
894
+ e.set(a.type, a);
895
+ }
896
+ const n = e.get("ftyp"), r = e.get("moov");
897
+ if (!n)
898
+ throw new Error("ftyp atom not found");
899
+ if (!r || !(r instanceof Un))
900
+ throw new Error("moov atom not found");
901
+ return {
902
+ ftyp: n,
903
+ moov: r
904
+ };
905
+ }
906
+ function zo(i) {
907
+ if (i.byteLength < 8)
908
+ throw new Error("Buffer too small");
909
+ const t = new tr(i), e = /* @__PURE__ */ new Map(), n = [];
910
+ for (; t.remaining() > 0; ) {
911
+ const d = wt(t);
912
+ d instanceof hn && n.push(d), e.set(d.type, d);
913
+ }
914
+ const r = e.get("moof"), a = e.get("mdat"), c = e.get("prft");
915
+ if (!r || !(r instanceof wn))
916
+ throw new Error("moof atom not found");
917
+ if (!a || !(a instanceof ln))
918
+ throw new Error("mdat atom not found");
919
+ if (c && !(c instanceof Tn))
920
+ throw new Error("invalid prft found");
921
+ return {
922
+ moof: r,
923
+ mdat: a,
924
+ prft: c,
925
+ emsgs: n
926
+ };
927
+ }
928
+ var ni, ri;
929
+ class Mo {
930
+ constructor(t) {
931
+ o(this, ni);
932
+ o(this, ri);
933
+ u(this, ni, t), u(this, ri, $o(t));
934
+ }
935
+ rawBytes() {
936
+ return s(this, ni);
937
+ }
938
+ init() {
939
+ return s(this, ri);
940
+ }
941
+ }
942
+ ni = new WeakMap(), ri = new WeakMap();
943
+ var ot, J, D;
944
+ class Ho {
945
+ constructor(t, e) {
946
+ o(this, ot);
947
+ o(this, J);
948
+ o(this, D);
949
+ u(this, ot, e), u(this, J, t), u(this, D, zo(e));
950
+ }
951
+ /**
952
+ * Update the raw bytes of the fragment with the new baseMediaDecodeTime
953
+ * @param baseMediaDecodeTime
954
+ */
955
+ updateBaseMediaDecodeTime(t) {
956
+ const e = new DataView(s(this, ot).buffer, s(this, ot).byteOffset, s(this, ot).byteLength);
957
+ if (s(this, D).moof.traf.tfdt)
958
+ if (s(this, D).moof.traf.tfdt.baseMediaDecodeTime = t, s(this, D).moof.traf.tfdt.extra.version === 1) {
959
+ const n = Math.floor(t / 4294967296), r = (t & 4294967295) >>> 0;
960
+ e.setUint32(s(this, D).moof.traf.tfdt.byteOffset - s(this, ot).byteOffset, n), e.setUint32(s(this, D).moof.traf.tfdt.byteOffset - s(this, ot).byteOffset + 4, r);
961
+ } else
962
+ e.setUint32(s(this, D).moof.traf.tfdt.byteOffset - s(this, ot).byteOffset, t);
963
+ }
964
+ producerReferenceTime() {
965
+ if (!s(this, D).prft)
966
+ return;
967
+ const [t, e] = s(this, D).prft.ntpTimestamp, n = t * 1e3 + e / nr(2, 32) * 1e3, r = new Date(Date.UTC(1900, 0, 1, 0, 0, 0));
968
+ return new Date(r.getTime() + n);
969
+ }
970
+ duration() {
971
+ var t;
972
+ return ((t = s(this, D).moof.traf.trun) == null ? void 0 : t.sampleDurations.reduce((e, n) => e + n, 0)) || 0;
973
+ }
974
+ baseMediaDecodeTime() {
975
+ var e;
976
+ const t = (e = s(this, D).moof.traf.tfdt) == null ? void 0 : e.baseMediaDecodeTime;
977
+ if (!t)
978
+ throw new Error("no baseMediaDecodeTime");
979
+ return t;
980
+ }
981
+ startsWithKeyframe() {
982
+ const t = s(this, D).moof.traf.trun, e = (t == null ? void 0 : t.firstSampleFlags) || (t == null ? void 0 : t.sampleFlags[0]);
983
+ return e ? (e & _s.FLAG_SAMPLE_DEPENDS_NO) !== 0 : !1;
984
+ }
985
+ timescale() {
986
+ const t = s(this, J).init().moov.traks[0];
987
+ if (!t)
988
+ throw new Error("no tracks");
989
+ return t.mdia.mdhd.timescale;
990
+ }
991
+ mediaType() {
992
+ var e;
993
+ const t = (e = s(this, J).init().moov.traks[0]) == null ? void 0 : e.mdia.hdlr.mediaType();
994
+ if (!t)
995
+ throw new Error("no media type");
996
+ return t;
997
+ }
998
+ header() {
999
+ return s(this, J);
1000
+ }
1001
+ fragment() {
1002
+ return s(this, D);
1003
+ }
1004
+ samplesCount() {
1005
+ var t;
1006
+ return ((t = s(this, D).moof.traf.trun) == null ? void 0 : t.samplesCount) || 0;
1007
+ }
1008
+ sample(t) {
1009
+ var y, E, P, H, T, g, Y, S, Tt, Us, Ki, Qi, Hr, Xr, Zr;
1010
+ const e = (y = s(this, J).init().moov.traks[0]) == null ? void 0 : y.mdia.minf.stbl.stsd.codec, n = ((E = s(this, D).moof.traf.trun) == null ? void 0 : E.samplesCount) || 0, r = (P = s(this, D).moof.traf.tfdt) == null ? void 0 : P.baseMediaDecodeTime;
1011
+ if (t >= n || typeof r == "undefined" || !e)
1012
+ return;
1013
+ const a = ((H = s(this, D).moof.traf.trun) == null ? void 0 : H.sampleDurations[t]) || 0, c = ((T = s(this, D).moof.traf.trun) == null ? void 0 : T.sampleDurations.slice(0, t).reduce((Ts, Es) => Ts + Es, 0)) || 0, d = r + c, f = ((g = s(this, J).init().moov.traks[0]) == null ? void 0 : g.mdia.mdhd.timescale) || 1e3, p = ((Y = s(this, D).moof.traf.trun) == null ? void 0 : Y.sampleSizes[t]) || s(this, D).mdat.data.byteLength, b = ((S = s(this, D).moof.traf.trun) == null ? void 0 : S.sampleSizes.slice(0, t).reduce((Ts, Es) => Ts + Es, 0)) || 0, m = s(this, D).mdat.data.subarray(b, b + p), I = ((Tt = s(this, D).moof.traf.trun) == null ? void 0 : Tt.is_sync_sample(t)) || !1;
1014
+ if (this.mediaType() === "video") {
1015
+ const Ts = ((Us = s(this, J).init().moov.traks[0]) == null ? void 0 : Us.tkhd.width) || 0, Es = ((Ki = s(this, J).init().moov.traks[0]) == null ? void 0 : Ki.tkhd.height) || 0;
1016
+ return {
1017
+ type: "video",
1018
+ codec: e,
1019
+ width: Ts,
1020
+ height: Es,
1021
+ duration: a,
1022
+ isSync: I,
1023
+ timescale: f,
1024
+ timestamp: d,
1025
+ data: m
1026
+ };
1027
+ }
1028
+ return {
1029
+ type: "audio",
1030
+ codec: e,
1031
+ channels: ((Hr = (Qi = s(this, J).init().moov.traks[0]) == null ? void 0 : Qi.mdia.minf.stbl.stsd.opus) == null ? void 0 : Hr.channelCount) || 0,
1032
+ sampleRate: ((Zr = (Xr = s(this, J).init().moov.traks[0]) == null ? void 0 : Xr.mdia.minf.stbl.stsd.opus) == null ? void 0 : Zr.sampleRate) || 0,
1033
+ duration: a,
1034
+ isSync: I,
1035
+ timestamp: d,
1036
+ data: m,
1037
+ timescale: f
1038
+ };
1039
+ }
1040
+ /**
1041
+ * @returns the raw bytes of the cmaf fragment
1042
+ */
1043
+ rawBytes() {
1044
+ return s(this, ot);
1045
+ }
1046
+ }
1047
+ ot = new WeakMap(), J = new WeakMap(), D = new WeakMap();
1048
+ var We;
1049
+ class ta {
1050
+ constructor(t) {
1051
+ o(this, We);
1052
+ u(this, We, new Mo(t));
1053
+ }
1054
+ header() {
1055
+ return s(this, We);
1056
+ }
1057
+ createFragment(t) {
1058
+ return new Ho(s(this, We), t);
1059
+ }
1060
+ }
1061
+ We = new WeakMap();
1062
+ var Gt, ai;
1063
+ class Xo {
1064
+ constructor(t, e) {
1065
+ o(this, Gt);
1066
+ o(this, ai);
1067
+ u(this, Gt, t), u(this, ai, e);
1068
+ }
1069
+ start(t) {
1070
+ s(this, Gt).addEventListener("message", (e) => {
1071
+ if (typeof e.data == "object" && e.data instanceof ArrayBuffer) {
1072
+ const n = new Uint8Array(e.data);
1073
+ n[0] == s(this, ai) && t.enqueue(n.subarray(1));
1074
+ }
1075
+ }), s(this, Gt).addEventListener("error", (e) => t.error(e)), s(this, Gt).addEventListener("close", () => Ta(() => t.close()));
1076
+ }
1077
+ cancel(t) {
1078
+ s(this, Gt).close(void 0, t);
1079
+ }
1080
+ }
1081
+ Gt = new WeakMap(), ai = new WeakMap();
1082
+ var yt, ee, se, ie;
1083
+ class Zo {
1084
+ constructor(t) {
1085
+ o(this, yt);
1086
+ o(this, ee, null);
1087
+ o(this, se, null);
1088
+ o(this, ie, null);
1089
+ u(this, yt, t);
1090
+ }
1091
+ start(t) {
1092
+ u(this, ee, (e) => {
1093
+ if (typeof e.data == "object" && e.data instanceof ArrayBuffer) {
1094
+ const n = new Uint8Array(e.data), r = n[0] || 0, a = r & 127, c = (r >> 7 & 1) > 0;
1095
+ if (a && a !== 0) {
1096
+ const d = n.subarray(1);
1097
+ t.enqueue([c, a, d]);
1098
+ }
1099
+ }
1100
+ }), u(this, se, () => Ta(() => t.close())), u(this, ie, (e) => t.error(e)), s(this, yt).addEventListener("message", s(this, ee)), s(this, yt).addEventListener("error", s(this, ie)), s(this, yt).addEventListener("close", s(this, se));
1101
+ }
1102
+ cancel(t) {
1103
+ s(this, ee) && s(this, yt).removeEventListener("message", s(this, ee)), s(this, ie) && s(this, yt).removeEventListener("error", s(this, ie)), s(this, se) && s(this, yt).removeEventListener("close", s(this, se));
1104
+ }
1105
+ }
1106
+ yt = new WeakMap(), ee = new WeakMap(), se = new WeakMap(), ie = new WeakMap();
1107
+ var gt, oi, $e, vt, xn, U, Vs, en, qt, sn, Lt;
1108
+ class En {
1109
+ constructor(t, e) {
1110
+ o(this, U);
1111
+ o(this, gt);
1112
+ o(this, oi);
1113
+ o(this, $e);
1114
+ o(this, vt, 0);
1115
+ o(this, xn, new TextDecoder());
1116
+ u(this, gt, t), u(this, oi, e), u(this, $e, e.getReader());
1117
+ }
1118
+ readUnsigned8() {
1119
+ return h(this, null, function* () {
1120
+ return yield w(this, U, qt).call(this, 1), w(this, U, Lt).call(this, 1)[0];
1121
+ });
1122
+ }
1123
+ readString() {
1124
+ return h(this, null, function* () {
1125
+ const t = yield this.readVarInt(), e = yield this.read(t);
1126
+ return s(this, xn).decode(e);
1127
+ });
1128
+ }
1129
+ readVarInt() {
1130
+ return h(this, null, function* () {
1131
+ const t = yield this.readBigVarInt();
1132
+ if (t > Number.MAX_SAFE_INTEGER)
1133
+ throw new Error("VarInt is too large");
1134
+ return Number(t);
1135
+ });
1136
+ }
1137
+ readBigVarInt() {
1138
+ return h(this, null, function* () {
1139
+ yield w(this, U, qt).call(this, 1);
1140
+ const t = (w(this, U, sn).call(this, 1)[0] & 192) >> 6;
1141
+ switch (s(this, gt)[s(this, vt)] = w(this, U, sn).call(this, 1)[0] & 63, t) {
1142
+ case 0:
1143
+ return k(w(this, U, Lt).call(this, 1)[0]);
1144
+ case 1: {
1145
+ yield w(this, U, qt).call(this, 2);
1146
+ const e = w(this, U, Lt).call(this, 2), n = new DataView(e.buffer, e.byteOffset, e.byteLength);
1147
+ return k(n.getUint16(0));
1148
+ }
1149
+ case 2: {
1150
+ yield w(this, U, qt).call(this, 4);
1151
+ const e = w(this, U, Lt).call(this, 4), n = new DataView(e.buffer, e.byteOffset, e.byteLength);
1152
+ return k(n.getUint32(0));
1153
+ }
1154
+ case 3: {
1155
+ yield w(this, U, qt).call(this, 8);
1156
+ const e = w(this, U, Lt).call(this, 8), n = new DataView(e.buffer, e.byteOffset, e.byteLength);
1157
+ if (typeof n.getBigUint64 != "undefined")
1158
+ return k(n.getBigUint64(0));
1159
+ const r = Ao(e, 0, 7);
1160
+ return k(r);
1161
+ }
1162
+ default:
1163
+ throw new Error("Invalid VarInt size");
1164
+ }
1165
+ });
1166
+ }
1167
+ read(t) {
1168
+ return h(this, null, function* () {
1169
+ return yield w(this, U, qt).call(this, t), w(this, U, Lt).call(this, t);
1170
+ });
1171
+ }
1172
+ readAll() {
1173
+ return h(this, null, function* () {
1174
+ for (; yield w(this, U, en).call(this); )
1175
+ ;
1176
+ return w(this, U, Lt).call(this, w(this, U, Vs).call(this));
1177
+ });
1178
+ }
1179
+ isDone() {
1180
+ return h(this, null, function* () {
1181
+ return w(this, U, Vs).call(this) > 0 ? !1 : (yield w(this, U, en).call(this)) == 0;
1182
+ });
1183
+ }
1184
+ close() {
1185
+ return h(this, null, function* () {
1186
+ return s(this, $e).releaseLock(), s(this, oi).cancel();
1187
+ });
1188
+ }
1189
+ }
1190
+ gt = new WeakMap(), oi = new WeakMap(), $e = new WeakMap(), vt = new WeakMap(), xn = new WeakMap(), U = new WeakSet(), Vs = function() {
1191
+ return s(this, gt).length - s(this, vt);
1192
+ }, en = function() {
1193
+ return h(this, null, function* () {
1194
+ const { value: t, done: e } = yield s(this, $e).read();
1195
+ if (e)
1196
+ return Promise.resolve(0);
1197
+ if (w(this, U, Vs).call(this) === 0)
1198
+ u(this, gt, t);
1199
+ else {
1200
+ const r = s(this, gt).subarray(s(this, vt)), a = new Uint8Array(r.length + t.length);
1201
+ a.set(r), a.set(t, r.byteLength), u(this, gt, a);
1202
+ }
1203
+ return u(this, vt, 0), Promise.resolve(t.length);
1204
+ });
1205
+ }, qt = function(t) {
1206
+ return h(this, null, function* () {
1207
+ for (; w(this, U, Vs).call(this) < t; )
1208
+ if ((yield w(this, U, en).call(this)) === 0)
1209
+ throw new Error("Read failed");
1210
+ });
1211
+ }, sn = function(t) {
1212
+ return s(this, gt).subarray(s(this, vt), s(this, vt) + t);
1213
+ }, Lt = function(t) {
1214
+ const e = w(this, U, sn).call(this, t);
1215
+ return u(this, vt, s(this, vt) + e.length), e;
1216
+ };
1217
+ var ze, Me, At, Pn;
1218
+ class Yo {
1219
+ constructor(t) {
1220
+ o(this, ze, new Uint8Array(8));
1221
+ o(this, Me);
1222
+ o(this, At);
1223
+ o(this, Pn, new TextEncoder());
1224
+ u(this, Me, t), u(this, At, s(this, Me).getWriter());
1225
+ }
1226
+ writeString(t) {
1227
+ return h(this, null, function* () {
1228
+ const e = s(this, Pn).encode(t);
1229
+ return yield this.writeVarInt(e.length), this.write(e);
1230
+ });
1231
+ }
1232
+ write(t) {
1233
+ return s(this, At).write(t);
1234
+ }
1235
+ writeUnsigned8(t) {
1236
+ return s(this, At).write(sr(t, s(this, ze)));
1237
+ }
1238
+ writeVarInt(t) {
1239
+ return s(this, At).write(Pa(t, s(this, ze)));
1240
+ }
1241
+ writeBigVarInt(t) {
1242
+ return s(this, At).write(Ra(t, s(this, ze)));
1243
+ }
1244
+ flush() {
1245
+ return h(this, null, function* () {
1246
+ });
1247
+ }
1248
+ close() {
1249
+ return h(this, null, function* () {
1250
+ s(this, At).releaseLock(), yield s(this, Me).close();
1251
+ });
1252
+ }
1253
+ }
1254
+ ze = new WeakMap(), Me = new WeakMap(), At = new WeakMap(), Pn = new WeakMap();
1255
+ var Z, K, He, Rn;
1256
+ const qs = class qs {
1257
+ constructor(t) {
1258
+ o(this, Z, 0);
1259
+ o(this, K, new Uint8Array(qs.DEFAULT_BUFFER_SIZE));
1260
+ o(this, He);
1261
+ o(this, Rn, new TextEncoder());
1262
+ u(this, He, t);
1263
+ }
1264
+ writeString(t) {
1265
+ return h(this, null, function* () {
1266
+ const e = s(this, Rn).encode(t);
1267
+ return yield this.writeVarInt(e.length), this.write(e);
1268
+ });
1269
+ }
1270
+ ensureBufferSpace(t) {
1271
+ if (s(this, K).length - s(this, Z) >= t)
1272
+ return;
1273
+ const e = new Uint8Array(s(this, K).length * 2);
1274
+ e.set(s(this, K)), u(this, K, e);
1275
+ }
1276
+ write(t) {
1277
+ return this.ensureBufferSpace(t.length), s(this, K).set(t, s(this, Z)), u(this, Z, s(this, Z) + t.byteLength), Promise.resolve();
1278
+ }
1279
+ writeUnsigned8(t) {
1280
+ return this.ensureBufferSpace(1), sr(t, s(this, K).subarray(s(this, Z))), u(this, Z, s(this, Z) + 1), Promise.resolve();
1281
+ }
1282
+ writeVarInt(t) {
1283
+ if (t < 0)
1284
+ throw new Error(`VarInt can not be negative: ${t}`);
1285
+ return this.ensureBufferSpace(8), u(this, Z, s(this, Z) + Pa(t, s(this, K).subarray(s(this, Z))).byteLength), Promise.resolve();
1286
+ }
1287
+ writeBigVarInt(t) {
1288
+ if (t < 0)
1289
+ throw new Error(`VarInt can not be negative: ${t}`);
1290
+ return this.ensureBufferSpace(8), u(this, Z, s(this, Z) + Ra(t, s(this, K).subarray(s(this, Z))).byteLength), Promise.resolve();
1291
+ }
1292
+ flush() {
1293
+ return s(this, He).send(s(this, K).subarray(0, s(this, Z))), u(this, Z, 0), u(this, K, new Uint8Array(qs.DEFAULT_BUFFER_SIZE)), Promise.resolve();
1294
+ }
1295
+ close() {
1296
+ return s(this, He).close(), Promise.resolve();
1297
+ }
1298
+ };
1299
+ Z = new WeakMap(), K = new WeakMap(), He = new WeakMap(), Rn = new WeakMap(), l(qs, "DEFAULT_BUFFER_SIZE", 1024);
1300
+ let Dn = qs;
1301
+ const Da = Math.pow(2, 6) - 1, Aa = Math.pow(2, 14) - 1, Oa = Math.pow(2, 30) - 1, Jo = Number.MAX_SAFE_INTEGER, Ko = typeof BigInt == "function" ? nr(k(2), k(62)) - k(1) : k(Number.MAX_SAFE_INTEGER);
1302
+ function sr(i, t) {
1303
+ return t[0] = i, t.subarray(0, 1);
1304
+ }
1305
+ function Va(i, t) {
1306
+ const e = new DataView(t.buffer, t.byteOffset, 2);
1307
+ return e.setUint16(0, i), new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
1308
+ }
1309
+ function Ca(i, t) {
1310
+ const e = new DataView(t.buffer, t.byteOffset, 4);
1311
+ return e.setUint32(0, i), new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
1312
+ }
1313
+ function Ba(i, t) {
1314
+ const e = new DataView(t.buffer, t.byteOffset, 8);
1315
+ return e.setBigUint64(0, i), new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
1316
+ }
1317
+ function xa(i, t) {
1318
+ const e = new DataView(t.buffer, t.byteOffset, 8);
1319
+ return e.setUint32(0, i / 4294967296), e.setUint32(4, i & 4294967295), t.set([192], 0), new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
1320
+ }
1321
+ function Pa(i, t) {
1322
+ if (i <= Da)
1323
+ return sr(i, t);
1324
+ if (i <= Aa)
1325
+ return Va(i | 16384, t);
1326
+ if (i <= Oa)
1327
+ return Ca(i | 2147483648, t);
1328
+ if (i <= Jo)
1329
+ return typeof BigInt == "function" ? Ba(BigInt(i) | BigInt(3221225472) << BigInt(32), t) : xa(Number(i), t);
1330
+ throw new Error(`overflow, value larger than 53-bits: ${i}`);
1331
+ }
1332
+ function Ra(i, t) {
1333
+ if (i < Da)
1334
+ return sr(Number(i), t);
1335
+ if (i < Aa)
1336
+ return Va(Number(i) | 16384, t);
1337
+ if (i <= Oa)
1338
+ return Ca(Number(i) | 2147483648, t);
1339
+ if (i <= Ko)
1340
+ return typeof BigInt == "function" ? Ba(BigInt(i) | BigInt(3221225472) << BigInt(32), t) : xa(Number(i), t);
1341
+ throw new Error(`overflow, value larger than 62-bits: ${i}`);
1342
+ }
1343
+ var v = /* @__PURE__ */ ((i) => (i[i.SubscribeUpdate = 2] = "SubscribeUpdate", i[i.Subscribe = 3] = "Subscribe", i[i.SubscribeOk = 4] = "SubscribeOk", i[i.SubscribeError = 5] = "SubscribeError", i[i.Announce = 6] = "Announce", i[i.AnnounceOk = 7] = "AnnounceOk", i[i.AnnounceError = 8] = "AnnounceError", i[i.Unannounce = 9] = "Unannounce", i[i.Unsubscribe = 10] = "Unsubscribe", i[i.SubscribeDone = 11] = "SubscribeDone", i[i.AnnounceCancel = 12] = "AnnounceCancel", i[i.TrackStatusRequest = 13] = "TrackStatusRequest", i[i.TrackStatus = 14] = "TrackStatus", i[i.Goaway = 16] = "Goaway", i[i.ClientSetup = 64] = "ClientSetup", i[i.ServerSetup = 65] = "ServerSetup", i[i.Unknown = 255] = "Unknown", i))(v || {});
1344
+ function La(i) {
1345
+ return h(this, null, function* () {
1346
+ const t = yield i.readVarInt();
1347
+ if (t < 1 || t > 32)
1348
+ throw new Error(`namespace must be between 1 and 32, got ${t}`);
1349
+ const e = [];
1350
+ for (let n = 0; n < t; n++)
1351
+ e.push(yield i.readString());
1352
+ return e;
1353
+ });
1354
+ }
1355
+ function ja(i, t) {
1356
+ return h(this, null, function* () {
1357
+ yield i.writeVarInt(t.length);
1358
+ for (const e of t)
1359
+ yield i.writeString(e);
1360
+ });
1361
+ }
1362
+ function Qo(i, t) {
1363
+ return h(this, null, function* () {
1364
+ yield ja(i, t.namespace);
1365
+ });
1366
+ }
1367
+ const ea = k(2);
1368
+ function Yi(i) {
1369
+ return h(this, null, function* () {
1370
+ const t = yield i.readVarInt(), e = /* @__PURE__ */ new Map();
1371
+ for (let n = 0; n < t; n++) {
1372
+ const r = yield i.readBigVarInt(), a = yield i.read(yield i.readVarInt());
1373
+ e.set(r, { type: r, payload: a });
1374
+ }
1375
+ return e;
1376
+ });
1377
+ }
1378
+ function Ji(i, t) {
1379
+ return h(this, null, function* () {
1380
+ yield i.writeVarInt(t.size);
1381
+ for (const [e, n] of t)
1382
+ yield i.writeBigVarInt(e), yield i.writeVarInt(n.payload.length), yield i.write(n.payload);
1383
+ });
1384
+ }
1385
+ const Ga = {
1386
+ Publisher: 0,
1387
+ Subscriber: 1,
1388
+ Both: 2
1389
+ }, An = {
1390
+ Role: k(0)
1391
+ }, Na = {
1392
+ Draft07: 4278190087
1393
+ };
1394
+ function Fa(i) {
1395
+ return h(this, null, function* () {
1396
+ const t = yield i.readVarInt();
1397
+ switch (t) {
1398
+ case Na.Draft07:
1399
+ return { type: "known", value: t };
1400
+ default:
1401
+ return { type: "unknown", value: t };
1402
+ }
1403
+ });
1404
+ }
1405
+ function qo(i, t) {
1406
+ return h(this, null, function* () {
1407
+ yield i.writeVarInt(t.supportedVersions.length);
1408
+ for (const e of t.supportedVersions)
1409
+ yield i.writeVarInt(e.value);
1410
+ yield Ji(i, t.parameters);
1411
+ });
1412
+ }
1413
+ function _o(i) {
1414
+ return h(this, null, function* () {
1415
+ const t = [], e = yield i.readVarInt();
1416
+ for (let r = 0; r < e; r++)
1417
+ t.push(yield Fa(i));
1418
+ const n = yield Yi(i);
1419
+ if (!n.has(An.Role))
1420
+ throw new Error("Role parameter is required");
1421
+ return {
1422
+ type: v.ClientSetup,
1423
+ supportedVersions: t,
1424
+ parameters: n
1425
+ };
1426
+ });
1427
+ }
1428
+ function tc(i, t) {
1429
+ return h(this, null, function* () {
1430
+ yield i.writeVarInt(t.selectedVersion.value), yield Ji(i, t.parameters);
1431
+ });
1432
+ }
1433
+ function ec(i) {
1434
+ return h(this, null, function* () {
1435
+ const t = yield Fa(i);
1436
+ if (t.type !== "known")
1437
+ throw new Error("Expected known version");
1438
+ const e = yield Yi(i);
1439
+ if (!e.has(An.Role))
1440
+ throw new Error("Role parameter is required");
1441
+ return {
1442
+ type: v.ServerSetup,
1443
+ selectedVersion: t,
1444
+ parameters: e
1445
+ };
1446
+ });
1447
+ }
1448
+ const sc = {
1449
+ "latest-group": 1,
1450
+ "latest-object": 2,
1451
+ "absolute-start": 3,
1452
+ "absolute-range": 4
1453
+ };
1454
+ function ic(i) {
1455
+ return h(this, null, function* () {
1456
+ const t = yield i.readVarInt();
1457
+ switch (t) {
1458
+ case 1:
1459
+ return { type: "latest-group" };
1460
+ case 2:
1461
+ return { type: "latest-object" };
1462
+ case 3:
1463
+ return {
1464
+ type: "absolute-start",
1465
+ start: {
1466
+ group: yield i.readBigVarInt(),
1467
+ object: yield i.readBigVarInt()
1468
+ }
1469
+ };
1470
+ case 4:
1471
+ return {
1472
+ type: "absolute-range",
1473
+ start: {
1474
+ group: yield i.readBigVarInt(),
1475
+ object: yield i.readBigVarInt()
1476
+ },
1477
+ end: {
1478
+ group: yield i.readBigVarInt(),
1479
+ object: yield i.readBigVarInt()
1480
+ }
1481
+ };
1482
+ default:
1483
+ throw new Error(`Invalid location type ${t}`);
1484
+ }
1485
+ });
1486
+ }
1487
+ function nc(i, t) {
1488
+ return h(this, null, function* () {
1489
+ const e = sc[t.type];
1490
+ switch (yield i.writeVarInt(e), t.type) {
1491
+ case "absolute-range":
1492
+ yield i.writeBigVarInt(t.start.group), yield i.writeBigVarInt(t.start.object), yield i.writeBigVarInt(t.end.group), yield i.writeBigVarInt(t.end.object);
1493
+ break;
1494
+ case "absolute-start":
1495
+ yield i.writeBigVarInt(t.start.group), yield i.writeBigVarInt(t.start.object);
1496
+ break;
1497
+ case "latest-object":
1498
+ case "latest-group":
1499
+ break;
1500
+ default:
1501
+ throw new Error(`Invalid location type ${e}`);
1502
+ }
1503
+ });
1504
+ }
1505
+ function Wa(i) {
1506
+ return h(this, null, function* () {
1507
+ const t = yield i.readUnsigned8();
1508
+ switch (t) {
1509
+ case 0:
1510
+ return "inherit-publisher";
1511
+ case 1:
1512
+ return "ascending";
1513
+ case 2:
1514
+ return "descending";
1515
+ default:
1516
+ throw new Error(`Invalid location type ${t}`);
1517
+ }
1518
+ });
1519
+ }
1520
+ function $a(i, t) {
1521
+ return h(this, null, function* () {
1522
+ switch (t) {
1523
+ case "inherit-publisher":
1524
+ yield i.writeUnsigned8(0);
1525
+ break;
1526
+ case "ascending":
1527
+ yield i.writeUnsigned8(1);
1528
+ break;
1529
+ case "descending":
1530
+ yield i.writeUnsigned8(2);
1531
+ break;
1532
+ }
1533
+ });
1534
+ }
1535
+ function rc(i) {
1536
+ return h(this, null, function* () {
1537
+ const t = yield i.readBigVarInt(), e = yield i.readBigVarInt(), n = yield La(i), r = yield i.readString(), a = yield i.readUnsigned8(), c = yield Wa(i), d = yield ic(i), f = yield Yi(i);
1538
+ if (d.type === "absolute-range") {
1539
+ const p = d.start.group > d.end.group, b = d.start.group === d.end.group && d.start.object > d.end.object;
1540
+ if (p || b)
1541
+ throw new Error("Invalid filter range");
1542
+ }
1543
+ return {
1544
+ type: v.Subscribe,
1545
+ id: t,
1546
+ trackAlias: e,
1547
+ namespace: n,
1548
+ name: r,
1549
+ subscriberPriority: a,
1550
+ groupOrder: c,
1551
+ filterType: d,
1552
+ params: f
1553
+ };
1554
+ });
1555
+ }
1556
+ function ac(i, t) {
1557
+ return h(this, null, function* () {
1558
+ yield i.writeBigVarInt(t.id), yield i.writeBigVarInt(t.trackAlias), yield ja(i, t.namespace), yield i.writeString(t.name), yield i.writeUnsigned8(t.subscriberPriority), yield $a(i, t.groupOrder), yield nc(i, t.filterType), yield Ji(i, t.params);
1559
+ });
1560
+ }
1561
+ const oc = {
1562
+ Unsubscribed: 0,
1563
+ InternalError: 1,
1564
+ Unauthorized: 2,
1565
+ TrackEnded: 3,
1566
+ SubscriptionEnded: 4,
1567
+ GoingAway: 5,
1568
+ Expired: 6
1569
+ };
1570
+ function cc(i) {
1571
+ return h(this, null, function* () {
1572
+ const t = yield i.readBigVarInt(), e = yield i.readVarInt(), n = yield i.readString(), r = (yield i.readUnsigned8()) == 1;
1573
+ let a;
1574
+ return r && (a = {
1575
+ group: yield i.readBigVarInt(),
1576
+ object: yield i.readBigVarInt()
1577
+ }), {
1578
+ type: v.SubscribeDone,
1579
+ id: t,
1580
+ errorCode: e,
1581
+ reason: n,
1582
+ finalInfo: a
1583
+ };
1584
+ });
1585
+ }
1586
+ function uc(i, t) {
1587
+ return h(this, null, function* () {
1588
+ yield i.writeBigVarInt(t.id), yield i.writeVarInt(t.errorCode), yield i.writeString(t.reason), yield i.writeUnsigned8(t.finalInfo ? 1 : 0), t.finalInfo && (yield i.writeBigVarInt(t.finalInfo.group), yield i.writeBigVarInt(t.finalInfo.object));
1589
+ });
1590
+ }
1591
+ function hc(i) {
1592
+ return h(this, null, function* () {
1593
+ const t = yield i.readBigVarInt(), e = yield i.readBigVarInt(), n = yield Wa(i), r = (yield i.readUnsigned8()) == 1;
1594
+ let a;
1595
+ if (n == "inherit-publisher")
1596
+ throw new Error("SusbcribeOk cannot have inherit publisher group order");
1597
+ r && (a = {
1598
+ group: yield i.readBigVarInt(),
1599
+ object: yield i.readBigVarInt()
1600
+ });
1601
+ const c = yield Yi(i);
1602
+ return {
1603
+ type: v.SubscribeOk,
1604
+ id: t,
1605
+ groupOrder: n,
1606
+ expires: e,
1607
+ largestInfo: a,
1608
+ params: c
1609
+ };
1610
+ });
1611
+ }
1612
+ function lc(i, t) {
1613
+ return h(this, null, function* () {
1614
+ yield i.writeBigVarInt(t.id), yield i.writeBigVarInt(t.expires), yield $a(i, t.groupOrder), yield i.writeUnsigned8(t.largestInfo ? 1 : 0), t.largestInfo && (yield i.writeBigVarInt(t.largestInfo.group), yield i.writeBigVarInt(t.largestInfo.object)), yield Ji(i, t.params);
1615
+ });
1616
+ }
1617
+ function dc(i, t) {
1618
+ return h(this, null, function* () {
1619
+ yield i.writeBigVarInt(t.id), yield i.writeBigVarInt(t.start.group), yield i.writeBigVarInt(t.start.object), yield i.writeBigVarInt(t.end.group), yield i.writeBigVarInt(t.end.object), yield i.writeUnsigned8(t.subscriberPriority), yield Ji(i, t.params);
1620
+ });
1621
+ }
1622
+ function fc(i) {
1623
+ return h(this, null, function* () {
1624
+ return {
1625
+ type: v.Unsubscribe,
1626
+ id: yield i.readBigVarInt()
1627
+ };
1628
+ });
1629
+ }
1630
+ function wc(i, t) {
1631
+ return h(this, null, function* () {
1632
+ yield i.writeBigVarInt(t.id);
1633
+ });
1634
+ }
1635
+ var Ot, Xe, L, Ma, Ha, Xa, Za, Ya, Ja, Ka, Qa;
1636
+ class za {
1637
+ constructor(t) {
1638
+ o(this, L);
1639
+ o(this, Ot);
1640
+ // Temporary buffer that holds the message before it is written to the stream
1641
+ // This way we can calculate the byte length of the message before writing it
1642
+ o(this, Xe, new Uint8Array());
1643
+ u(this, Ot, t);
1644
+ }
1645
+ write(t) {
1646
+ return h(this, null, function* () {
1647
+ yield s(this, Ot).writeVarInt(t.type);
1648
+ const e = new Dn({
1649
+ close: () => {
1650
+ },
1651
+ send: (n) => {
1652
+ u(this, Xe, new Uint8Array(n));
1653
+ }
1654
+ });
1655
+ switch (t.type) {
1656
+ case v.Subscribe:
1657
+ yield w(this, L, Xa).call(this, e, t);
1658
+ break;
1659
+ case v.SubscribeOk:
1660
+ yield w(this, L, Za).call(this, e, t);
1661
+ break;
1662
+ case v.SubscribeUpdate:
1663
+ yield w(this, L, Ya).call(this, e, t);
1664
+ break;
1665
+ case v.SubscribeDone:
1666
+ yield w(this, L, Ja).call(this, e, t);
1667
+ break;
1668
+ case v.Unsubscribe:
1669
+ yield w(this, L, Ka).call(this, e, t);
1670
+ break;
1671
+ case v.ClientSetup:
1672
+ yield w(this, L, Ma).call(this, e, t);
1673
+ break;
1674
+ case v.ServerSetup:
1675
+ yield w(this, L, Ha).call(this, e, t);
1676
+ break;
1677
+ case v.AnnounceOk:
1678
+ yield w(this, L, Qa).call(this, e, t);
1679
+ break;
1680
+ default:
1681
+ throw new Error(`Unknown message type: ${t.type}`);
1682
+ }
1683
+ yield e.flush(), yield s(this, Ot).writeVarInt(s(this, Xe).byteLength), yield s(this, Ot).write(s(this, Xe)), yield s(this, Ot).flush();
1684
+ });
1685
+ }
1686
+ close() {
1687
+ return h(this, null, function* () {
1688
+ return s(this, Ot).close();
1689
+ });
1690
+ }
1691
+ }
1692
+ Ot = new WeakMap(), Xe = new WeakMap(), L = new WeakSet(), Ma = function(t, e) {
1693
+ return h(this, null, function* () {
1694
+ yield qo(t, e);
1695
+ });
1696
+ }, Ha = function(t, e) {
1697
+ return h(this, null, function* () {
1698
+ yield tc(t, e);
1699
+ });
1700
+ }, Xa = function(t, e) {
1701
+ return h(this, null, function* () {
1702
+ yield ac(t, e);
1703
+ });
1704
+ }, Za = function(t, e) {
1705
+ return h(this, null, function* () {
1706
+ yield lc(t, e);
1707
+ });
1708
+ }, Ya = function(t, e) {
1709
+ return h(this, null, function* () {
1710
+ yield dc(t, e);
1711
+ });
1712
+ }, Ja = function(t, e) {
1713
+ return h(this, null, function* () {
1714
+ yield uc(t, e);
1715
+ });
1716
+ }, Ka = function(t, e) {
1717
+ return h(this, null, function* () {
1718
+ yield wc(t, e);
1719
+ });
1720
+ }, Qa = function(t, e) {
1721
+ return h(this, null, function* () {
1722
+ yield Qo(t, e);
1723
+ });
1724
+ };
1725
+ var Ze, ci, ui;
1726
+ class pc {
1727
+ constructor(t, e) {
1728
+ o(this, Ze);
1729
+ o(this, ci);
1730
+ o(this, ui);
1731
+ u(this, Ze, t), u(this, ci, new za(t)), u(this, ui, e);
1732
+ }
1733
+ write(t) {
1734
+ return h(this, null, function* () {
1735
+ yield s(this, Ze).write(s(this, ui)), yield s(this, ci).write(t);
1736
+ });
1737
+ }
1738
+ close() {
1739
+ return s(this, Ze).close();
1740
+ }
1741
+ }
1742
+ Ze = new WeakMap(), ci = new WeakMap(), ui = new WeakMap();
1743
+ function mc(i) {
1744
+ return h(this, null, function* () {
1745
+ return {
1746
+ type: v.Announce,
1747
+ namespace: yield La(i),
1748
+ params: yield Yi(i)
1749
+ };
1750
+ });
1751
+ }
1752
+ function bc(i) {
1753
+ return h(this, null, function* () {
1754
+ return {
1755
+ type: v.SubscribeError,
1756
+ id: yield i.readBigVarInt(),
1757
+ errorCode: yield i.readBigVarInt(),
1758
+ reason: yield i.readString(),
1759
+ trackAlias: yield i.readBigVarInt()
1760
+ };
1761
+ });
1762
+ }
1763
+ function yc(i, t, e) {
1764
+ return h(this, null, function* () {
1765
+ return {
1766
+ type: v.Unknown,
1767
+ messageType: t,
1768
+ payload: yield i.read(e)
1769
+ };
1770
+ });
1771
+ }
1772
+ var W;
1773
+ class sa {
1774
+ constructor(t) {
1775
+ o(this, W);
1776
+ u(this, W, t);
1777
+ }
1778
+ cancel() {
1779
+ return s(this, W).close();
1780
+ }
1781
+ read() {
1782
+ return h(this, null, function* () {
1783
+ const t = yield s(this, W).readVarInt(), e = yield s(this, W).readVarInt();
1784
+ switch (t) {
1785
+ case v.ServerSetup:
1786
+ return ec(s(this, W));
1787
+ case v.ClientSetup:
1788
+ return _o(s(this, W));
1789
+ case v.Subscribe:
1790
+ return rc(s(this, W));
1791
+ case v.SubscribeOk:
1792
+ return hc(s(this, W));
1793
+ case v.SubscribeDone:
1794
+ return cc(s(this, W));
1795
+ case v.SubscribeError:
1796
+ return bc(s(this, W));
1797
+ case v.Unsubscribe:
1798
+ return fc(s(this, W));
1799
+ case v.Announce:
1800
+ return mc(s(this, W));
1801
+ }
1802
+ return yc(s(this, W), k(t), e);
1803
+ });
1804
+ }
1805
+ }
1806
+ W = new WeakMap();
1807
+ var hi, Ye, Je, li, Ln, qa, jn;
1808
+ const Le = class Le {
1809
+ constructor(t, e) {
1810
+ o(this, Ln);
1811
+ o(this, hi);
1812
+ o(this, Ye);
1813
+ o(this, Je, new x());
1814
+ o(this, li, new x());
1815
+ u(this, hi, t), u(this, Ye, e), s(this, Je).resolve();
1816
+ }
1817
+ write(t) {
1818
+ return h(this, null, function* () {
1819
+ const e = yield w(this, Ln, qa).call(this);
1820
+ try {
1821
+ yield s(this, hi).write(t);
1822
+ } finally {
1823
+ e.resolve();
1824
+ }
1825
+ });
1826
+ }
1827
+ markPostHandshake() {
1828
+ s(this, li).resolve();
1829
+ }
1830
+ postHandshake() {
1831
+ return s(this, li).promise;
1832
+ }
1833
+ // Not "thread" safe (:
1834
+ read() {
1835
+ return h(this, null, function* () {
1836
+ return s(this, Ye).read();
1837
+ });
1838
+ }
1839
+ cancel() {
1840
+ return s(this, Ye).cancel();
1841
+ }
1842
+ static wrapWebsocket(t) {
1843
+ const e = new ReadableStream(new Xo(t, s(Le, jn))), n = new sa(new En(new Uint8Array([]), e)), r = new pc(new Dn(t), new Uint8Array([0]));
1844
+ return new Le(r, n);
1845
+ }
1846
+ static wrapWebTransport(t) {
1847
+ const e = t.writable, n = t.readable;
1848
+ return new Le(
1849
+ new za(new Yo(e)),
1850
+ new sa(new En(new Uint8Array(), n))
1851
+ );
1852
+ }
1853
+ };
1854
+ hi = new WeakMap(), Ye = new WeakMap(), Je = new WeakMap(), li = new WeakMap(), Ln = new WeakSet(), qa = function() {
1855
+ const t = new x(), e = s(this, Je).promise.then(() => t);
1856
+ return u(this, Je, t), e;
1857
+ }, jn = new WeakMap(), o(Le, jn, 0);
1858
+ let On = Le;
1859
+ function _a(i, t) {
1860
+ return h(this, null, function* () {
1861
+ yield i.write({
1862
+ type: v.ClientSetup,
1863
+ supportedVersions: [{ type: "known", value: Na.Draft07 }],
1864
+ parameters: /* @__PURE__ */ new Map([[An.Role, { type: An.Role, payload: new Uint8Array([t]) }]])
1865
+ });
1866
+ const e = yield i.read();
1867
+ if (i.markPostHandshake(), e.type !== v.ServerSetup)
1868
+ throw new Error("Expected server setup message");
1869
+ if (e.selectedVersion.type !== "known")
1870
+ throw new Error("Expected known version");
1871
+ });
1872
+ }
1873
+ var Ke, Nt, di, Gn, ne, ct;
1874
+ const Nn = class Nn {
1875
+ constructor(t) {
1876
+ l(this, "subscribe");
1877
+ o(this, Ke, new x());
1878
+ o(this, Nt, new x());
1879
+ o(this, di, new x());
1880
+ o(this, Gn, Date.now());
1881
+ o(this, ne, new x());
1882
+ o(this, ct);
1883
+ switch (this.subscribe = t, t.filterType.type) {
1884
+ case "absolute-start":
1885
+ u(this, ct, { startGroup: t.filterType.start.group });
1886
+ break;
1887
+ case "absolute-range":
1888
+ u(this, ct, { startGroup: t.filterType.start.group, endGroup: t.filterType.end.group });
1889
+ break;
1890
+ }
1891
+ }
1892
+ onUpdate(t) {
1893
+ u(this, ct, { startGroup: t.start.group }), t.end.group > k(0) && (s(this, ct).endGroup = t.end.group - k(1));
1894
+ }
1895
+ onError(t) {
1896
+ const e = new Error(t.reason);
1897
+ return s(this, Ke).reject(e), s(this, Nt).reject(e), e;
1898
+ }
1899
+ onDone(t) {
1900
+ t.finalInfo && (s(this, ct) || u(this, ct, { startGroup: k(0) }), s(this, ct).endGroup = t.finalInfo.group), s(this, Nt).resolve(t);
1901
+ }
1902
+ onUnsubscribe(t) {
1903
+ s(this, di).resolve(t);
1904
+ }
1905
+ onOk(t) {
1906
+ const e = Math.max(0, Date.now() - s(this, Gn)), n = Number(t.expires);
1907
+ if (n > 0) {
1908
+ const r = Math.min(n / 10, Nn.maxGraceTime);
1909
+ Promise.race([er(n - r - e), this.done().catch(B)]).then(() => s(this, ne).resolve(this.expiryState())).catch(B);
1910
+ }
1911
+ s(this, Ke).resolve(t);
1912
+ }
1913
+ done() {
1914
+ return s(this, Nt).promise;
1915
+ }
1916
+ ok() {
1917
+ return s(this, Ke).promise;
1918
+ }
1919
+ range() {
1920
+ return s(this, ct);
1921
+ }
1922
+ close() {
1923
+ s(this, ne).promise.catch(B), s(this, ne).reject(new Error("Subscription closed"));
1924
+ }
1925
+ // Returns whether the subscription is still active - i.e. hasn't received a done or unsubscribe
1926
+ expiryState() {
1927
+ return s(this, Nt).resolved && s(this, Nt).resolved.errorCode !== oc.Expired ? "done" : s(this, di).pending ? "active" : "unsubscribed";
1928
+ }
1929
+ /**
1930
+ * Returns a promise that resolves when the subscription is about to expire (15 seconds before expiry).
1931
+
1932
+ */
1933
+ expiryNotification() {
1934
+ return s(this, ne).promise;
1935
+ }
1936
+ };
1937
+ Ke = new WeakMap(), Nt = new WeakMap(), di = new WeakMap(), Gn = new WeakMap(), ne = new WeakMap(), ct = new WeakMap(), l(Nn, "maxGraceTime", 15e3);
1938
+ let br = Nn;
1939
+ function gc(i, t) {
1940
+ const e = new br(t), [n, r] = Rr(100), a = new vc(e, n), c = new to(i, e, r);
1941
+ return [a, c];
1942
+ }
1943
+ var re;
1944
+ class vc {
1945
+ constructor(t, e) {
1946
+ l(this, "state");
1947
+ o(this, re);
1948
+ this.state = t, u(this, re, e);
1949
+ }
1950
+ onDone(t) {
1951
+ this.state.onDone(t);
1952
+ }
1953
+ onData(t) {
1954
+ return s(this, re).push(t);
1955
+ }
1956
+ onError(t) {
1957
+ const e = this.state.onError(t);
1958
+ s(this, re).abort(e);
1959
+ }
1960
+ /**
1961
+ * Closes the subscription producer so that no more objects an be emitted
1962
+ */
1963
+ close() {
1964
+ this.state.close(), s(this, re).close();
1965
+ }
1966
+ }
1967
+ re = new WeakMap();
1968
+ var ua, Qe, j, qe, _e, hr, ts, Cs;
1969
+ class to {
1970
+ constructor(t, e, n) {
1971
+ Ce(hr, 5, this);
1972
+ o(this, ts);
1973
+ o(this, Qe);
1974
+ o(this, j);
1975
+ o(this, qe);
1976
+ o(this, _e, new x());
1977
+ u(this, Qe, t), u(this, j, e), u(this, qe, n);
1978
+ }
1979
+ get id() {
1980
+ return s(this, j).subscribe.id;
1981
+ }
1982
+ get trackAlias() {
1983
+ return s(this, j).subscribe.trackAlias;
1984
+ }
1985
+ get name() {
1986
+ return s(this, j).subscribe.name;
1987
+ }
1988
+ range() {
1989
+ return s(this, j).range();
1990
+ }
1991
+ expiryNotification() {
1992
+ return s(this, j).expiryNotification();
1993
+ }
1994
+ /**
1995
+ * Update the subscription range
1996
+ * @param startGroup the start group to subscribe to
1997
+ * @param endGroup the end group to subscribe to
1998
+ */
1999
+ update(t, e) {
2000
+ return h(this, null, function* () {
2001
+ const n = {
2002
+ type: v.SubscribeUpdate,
2003
+ id: s(this, j).subscribe.id,
2004
+ start: { group: t, object: k(0) },
2005
+ end: { group: e + k(1), object: k(0) },
2006
+ params: /* @__PURE__ */ new Map(),
2007
+ subscriberPriority: 0
2008
+ };
2009
+ s(this, j).onUpdate(n), yield s(this, Qe).push(n);
2010
+ });
2011
+ }
2012
+ unsubscribe() {
2013
+ return h(this, null, function* () {
2014
+ const t = { type: v.Unsubscribe, id: s(this, j).subscribe.id };
2015
+ s(this, j).onUnsubscribe(t), yield s(this, Qe).push(t);
2016
+ });
2017
+ }
2018
+ /// Closes the object reader so any pending readData calls are resolved
2019
+ close() {
2020
+ var t, e;
2021
+ return s(this, _e).resolve(), (e = (t = s(this, qe)).return) == null ? void 0 : e.call(t);
2022
+ }
2023
+ /// Closed is resolved when the subscription has been fully consumed which means no more objects will be available
2024
+ closed() {
2025
+ return s(this, _e).promise;
2026
+ }
2027
+ /// Await this subscription to become done
2028
+ /// Done does not mean that the subscription is closed,
2029
+ /// it means that the server has confirmed our unsubscribe request
2030
+ done() {
2031
+ return s(this, j).done();
2032
+ }
2033
+ expiryState() {
2034
+ return s(this, j).expiryState();
2035
+ }
2036
+ return() {
2037
+ return h(this, null, function* () {
2038
+ return s(this, _e).resolve(), yield this.unsubscribe(), { done: !0, value: void 0 };
2039
+ });
2040
+ }
2041
+ groups() {
2042
+ return Dt(this, null, function* () {
2043
+ var t, e;
2044
+ try {
2045
+ for (var y = C(s(this, qe)), E, P, H; E = !(P = yield new A(y.next())).done; E = !1) {
2046
+ var d = P.value;
2047
+ var f = [];
2048
+ try {
2049
+ const T = mt(f, d, !0);
2050
+ try {
2051
+ for (var n = C(T.groups()), r, a, c; r = !(a = yield new A(n.next())).done; r = !1) {
2052
+ const g = a.value;
2053
+ const Y = (t = s(this, j).range()) == null ? void 0 : t.startGroup, S = (e = s(this, j).range()) == null ? void 0 : e.endGroup;
2054
+ if (Y && g.groupId() < Y)
2055
+ return { done: !0, value: void 0 };
2056
+ if (S && g.groupId() > S)
2057
+ return { done: !0, value: void 0 };
2058
+ yield g;
2059
+ }
2060
+ } catch (a) {
2061
+ c = [a];
2062
+ } finally {
2063
+ try {
2064
+ r && (a = n.return) && (yield new A(a.call(n)));
2065
+ } finally {
2066
+ if (c)
2067
+ throw c[0];
2068
+ }
2069
+ }
2070
+ } catch (p) {
2071
+ var b = p, m = !0;
2072
+ } finally {
2073
+ var I = bt(f, b, m);
2074
+ I && (yield new A(I));
2075
+ }
2076
+ }
2077
+ } catch (P) {
2078
+ H = [P];
2079
+ } finally {
2080
+ try {
2081
+ E && (P = y.return) && (yield new A(P.call(y)));
2082
+ } finally {
2083
+ if (H)
2084
+ throw H[0];
2085
+ }
2086
+ }
2087
+ });
2088
+ }
2089
+ [Symbol.asyncIterator]() {
2090
+ return this.groups();
2091
+ }
2092
+ /**
2093
+ * @returns the next object from the subscription
2094
+ */
2095
+ objects() {
2096
+ return Dt(this, null, function* () {
2097
+ try {
2098
+ for (var a = C(this.groups()), c, d, f; c = !(d = yield new A(a.next())).done; c = !1) {
2099
+ const p = d.value;
2100
+ try {
2101
+ for (var t = C(p), e, n, r; e = !(n = yield new A(t.next())).done; e = !1) {
2102
+ const b = n.value;
2103
+ yield b;
2104
+ }
2105
+ } catch (n) {
2106
+ r = [n];
2107
+ } finally {
2108
+ try {
2109
+ e && (n = t.return) && (yield new A(n.call(t)));
2110
+ } finally {
2111
+ if (r)
2112
+ throw r[0];
2113
+ }
2114
+ }
2115
+ }
2116
+ } catch (d) {
2117
+ f = [d];
2118
+ } finally {
2119
+ try {
2120
+ c && (d = a.return) && (yield new A(d.call(a)));
2121
+ } finally {
2122
+ if (f)
2123
+ throw f[0];
2124
+ }
2125
+ }
2126
+ });
2127
+ }
2128
+ [(ua = [_({ context: "SubscriptionConsumer", enter: "info" })], Oe())]() {
2129
+ return w(this, ts, Cs).call(this);
2130
+ }
2131
+ [Symbol.asyncDispose]() {
2132
+ return w(this, ts, Cs).call(this);
2133
+ }
2134
+ }
2135
+ hr = Ve(null), Qe = new WeakMap(), j = new WeakMap(), qe = new WeakMap(), _e = new WeakMap(), ts = new WeakSet(), Cs = function() {
2136
+ return h(this, null, function* () {
2137
+ return yield this.close(), this.unsubscribe();
2138
+ });
2139
+ }, Cs = X(hr, 17, "#dispose", ua, ts, Cs), Jt(hr, to);
2140
+ const kc = 2e3;
2141
+ var ha, la, da, fa, wa, pa, st, Q, ae, oe, Qt, R, nn, Bs, xs, Be;
2142
+ class yr {
2143
+ constructor(t, e) {
2144
+ Ce(Qt, 5, this);
2145
+ o(this, R);
2146
+ // The owner session of the subscriber
2147
+ o(this, st);
2148
+ // The next subscribe id
2149
+ l(this, "nextSubscribeId", k(0));
2150
+ // The active subscriptions
2151
+ o(this, Q, new ft(/* @__PURE__ */ new Map()));
2152
+ o(this, ae);
2153
+ o(this, oe, Xt.get().createContext("Subscriber"));
2154
+ u(this, st, t), u(this, ae, e), w(this, R, nn).call(this).catch(B), s(this, st).closed().then(() => w(this, R, xs).call(this)).catch(B);
2155
+ }
2156
+ [(pa = [_({ context: "Session", return: "debug" })], wa = [_({ context: "Session", enter: "debug" })], Ua())]() {
2157
+ w(this, R, Bs).call(this);
2158
+ }
2159
+ [(fa = Symbol.dispose, da = [_({ context: "Session", enter: "info", error: "error" })], la = [_({ context: "Session", enter: "debug" })], ha = [_({ context: "Session", enter: "debug" })], fa)]() {
2160
+ w(this, R, Bs).call(this);
2161
+ }
2162
+ subscribe(t, e) {
2163
+ return h(this, null, function* () {
2164
+ const n = this.nextSubscribeId++, r = /* @__PURE__ */ new Map(), a = s(this, st).authToken.current();
2165
+ a && r.set(ea, { type: ea, payload: new TextEncoder().encode(a) });
2166
+ const c = {
2167
+ type: v.Subscribe,
2168
+ namespace: t,
2169
+ name: e.name,
2170
+ id: n,
2171
+ trackAlias: n,
2172
+ groupOrder: e.groupOrder,
2173
+ subscriberPriority: e.priority,
2174
+ filterType: e.filterType,
2175
+ params: r
2176
+ }, [d, f] = gc(s(this, ae), c);
2177
+ if (s(this, Q).update((b) => b.set(n, d)), yield s(this, ae).push(c), !(yield Promise.race([d.state.ok(), s(this, st).closed()])))
2178
+ throw new Error("Session closed");
2179
+ return f.closed().then(() => Promise.race([er(kc), this.closed()])).then(() => w(this, R, Be).call(this, f.id)).catch(() => w(this, R, Be).call(this, f.id)), f;
2180
+ });
2181
+ }
2182
+ closed() {
2183
+ return s(this, st).closed();
2184
+ }
2185
+ close() {
2186
+ s(this, st).close();
2187
+ }
2188
+ updateAuthToken(t) {
2189
+ s(this, st).authToken.update(t);
2190
+ }
2191
+ transportType() {
2192
+ return s(this, st).transportType();
2193
+ }
2194
+ url() {
2195
+ return s(this, st).url();
2196
+ }
2197
+ onMessage(t) {
2198
+ return h(this, null, function* () {
2199
+ switch (t.type) {
2200
+ case v.Announce:
2201
+ yield s(this, ae).push({
2202
+ type: v.AnnounceOk,
2203
+ namespace: t.namespace
2204
+ });
2205
+ break;
2206
+ case v.SubscribeOk:
2207
+ {
2208
+ const e = s(this, Q).current().get(t.id);
2209
+ e && e.state.onOk(t);
2210
+ }
2211
+ break;
2212
+ case v.SubscribeError:
2213
+ {
2214
+ const e = s(this, Q).current().get(t.id);
2215
+ e || s(this, oe).debug("No subscription found", t), e == null || e.onError(t), w(this, R, Be).call(this, t.id);
2216
+ }
2217
+ break;
2218
+ case v.SubscribeDone:
2219
+ {
2220
+ const e = s(this, Q).current().get(t.id);
2221
+ e || s(this, oe).debug("No subscription found", t), e == null || e.onDone(t);
2222
+ }
2223
+ break;
2224
+ }
2225
+ });
2226
+ }
2227
+ onObjectReader(t) {
2228
+ return h(this, null, function* () {
2229
+ const e = s(this, Q).current().get(t.subscribeId());
2230
+ if (!e) {
2231
+ s(this, oe).warn("No subscription found", t.subscribeId());
2232
+ return;
2233
+ }
2234
+ yield e.onData(t);
2235
+ });
2236
+ }
2237
+ }
2238
+ Qt = Ve(null), st = new WeakMap(), Q = new WeakMap(), ae = new WeakMap(), oe = new WeakMap(), R = new WeakSet(), nn = function() {
2239
+ return h(this, null, function* () {
2240
+ try {
2241
+ for (var t = C(s(this, Q)), e, n, r; e = !(n = yield t.next()).done; e = !1) {
2242
+ const a = n.value;
2243
+ const c = [...a.values()].map((d) => d.state.subscribe);
2244
+ s(this, oe).debug("current subscriptions", c);
2245
+ }
2246
+ } catch (n) {
2247
+ r = [n];
2248
+ } finally {
2249
+ try {
2250
+ e && (n = t.return) && (yield n.call(t));
2251
+ } finally {
2252
+ if (r)
2253
+ throw r[0];
2254
+ }
2255
+ }
2256
+ });
2257
+ }, Bs = function() {
2258
+ w(this, R, xs).call(this);
2259
+ }, xs = function() {
2260
+ s(this, Q).current().forEach((t) => t.close()), s(this, Q).close();
2261
+ }, Be = function(t) {
2262
+ s(this, Q).isClosed() || s(this, Q).update((e) => (e.delete(t), e));
2263
+ }, nn = X(Qt, 17, "#observeChanges", pa, R, nn), Bs = X(Qt, 17, "#dispose", wa, R, Bs), X(Qt, 1, "subscribe", da, yr), xs = X(Qt, 17, "#close", la, R, xs), Be = X(Qt, 17, "#deleteSubscription", ha, R, Be), Jt(Qt, yr);
2264
+ var ma, ba, ya, ut, fi, ce, es, ss, M, eo, so, As, rn, an, on;
2265
+ ya = [_({ context: "Session", return: "info", error: "error" })], ba = [_({ context: "Session", return: "info", error: "error" })], ma = [_({ context: "Session", return: "info", error: "error" })];
2266
+ const Fn = class Fn {
2267
+ constructor(t, e, n) {
2268
+ Ce(As, 5, this);
2269
+ o(this, M);
2270
+ // The underlying transport implementation
2271
+ o(this, ut);
2272
+ // The background "thread" running the background tasks
2273
+ o(this, fi);
2274
+ // Outgoing messages
2275
+ o(this, ce);
2276
+ // If the session has a subscriber role this is set - otherwise undefined
2277
+ o(this, es);
2278
+ o(this, ss, Xt.get().createContext("Subscriber"));
2279
+ l(this, "authToken");
2280
+ u(this, ut, t), u(this, ce, e), u(this, fi, w(this, M, so).call(this)), this.authToken = new ft(n);
2281
+ }
2282
+ static subscriber(t, e) {
2283
+ const [n, r] = Rr(100), a = new Fn(t, r, e), c = new yr(a, n);
2284
+ return u(a, es, c), c;
2285
+ }
2286
+ transportType() {
2287
+ return s(this, ut).transportType();
2288
+ }
2289
+ url() {
2290
+ return s(this, ut).url();
2291
+ }
2292
+ closed() {
2293
+ return s(this, fi);
2294
+ }
2295
+ close() {
2296
+ try {
2297
+ s(this, ce).cancel("closing"), s(this, ut).close();
2298
+ } catch (t) {
2299
+ s(this, ss).warn("Error closing session", t);
2300
+ }
2301
+ }
2302
+ };
2303
+ As = Ve(null), ut = new WeakMap(), fi = new WeakMap(), ce = new WeakMap(), es = new WeakMap(), ss = new WeakMap(), M = new WeakSet(), eo = function(t) {
2304
+ return h(this, null, function* () {
2305
+ var e;
2306
+ switch (s(this, ss).debug("received message", t), yield (e = s(this, es)) == null ? void 0 : e.onMessage(t), t.type) {
2307
+ case v.Goaway:
2308
+ break;
2309
+ }
2310
+ });
2311
+ }, so = function() {
2312
+ return h(this, null, function* () {
2313
+ return (yield Promise.all([w(this, M, an).call(this), w(this, M, on).call(this), w(this, M, rn).call(this)])).find((e) => e instanceof Error);
2314
+ });
2315
+ }, rn = function() {
2316
+ return h(this, null, function* () {
2317
+ try {
2318
+ try {
2319
+ for (var t = C(s(this, ce)), e, n, r; e = !(n = yield t.next()).done; e = !1) {
2320
+ const a = n.value;
2321
+ s(this, ss).debug("sending message", a), yield s(this, ut).writeMessage(a);
2322
+ }
2323
+ } catch (n) {
2324
+ r = [n];
2325
+ } finally {
2326
+ try {
2327
+ e && (n = t.return) && (yield n.call(t));
2328
+ } finally {
2329
+ if (r)
2330
+ throw r[0];
2331
+ }
2332
+ }
2333
+ } catch (a) {
2334
+ return a;
2335
+ }
2336
+ });
2337
+ }, an = function() {
2338
+ return h(this, null, function* () {
2339
+ yield s(this, ut).afterHandshake();
2340
+ try {
2341
+ for (; ; ) {
2342
+ const t = yield s(this, ut).readMessage().catch(() => {
2343
+ });
2344
+ if (!t)
2345
+ break;
2346
+ yield w(this, M, eo).call(this, t);
2347
+ }
2348
+ } catch (t) {
2349
+ return t;
2350
+ } finally {
2351
+ s(this, ce).cancel("closing");
2352
+ }
2353
+ });
2354
+ }, on = function() {
2355
+ return h(this, null, function* () {
2356
+ var t;
2357
+ try {
2358
+ for (; ; ) {
2359
+ const e = yield s(this, ut).objectStream();
2360
+ if (!e)
2361
+ break;
2362
+ yield (t = s(this, es)) == null ? void 0 : t.onObjectReader(e);
2363
+ }
2364
+ } catch (e) {
2365
+ return e;
2366
+ }
2367
+ });
2368
+ }, rn = X(As, 17, "#runOutgoingMessages", ya, M, rn), an = X(As, 17, "#runControl", ba, M, an), on = X(As, 17, "#runObjects", ma, M, on), Jt(As, Fn);
2369
+ let Vn = Fn;
2370
+ var gr = /* @__PURE__ */ ((i) => (i[i.StreamHeaderGroup = 4] = "StreamHeaderGroup", i[i.FetchHeader = 5] = "FetchHeader", i[i.StreamHeaderTrack = 60] = "StreamHeaderTrack", i))(gr || {});
2371
+ const $ = {
2372
+ Normal: 0,
2373
+ ObjectDoesNotExist: 1,
2374
+ GroupDoesNotExist: 2,
2375
+ EndOfGroup: 3,
2376
+ EndOfTrackAndGroup: 4
2377
+ };
2378
+ function io(i) {
2379
+ switch (i) {
2380
+ case $.Normal:
2381
+ case $.ObjectDoesNotExist:
2382
+ case $.GroupDoesNotExist:
2383
+ case $.EndOfGroup:
2384
+ case $.EndOfTrackAndGroup:
2385
+ return;
2386
+ }
2387
+ throw new Error("Unknown object status " + i);
2388
+ }
2389
+ var kt, is, ns, wi, pi, rs, mi;
2390
+ class Ic {
2391
+ constructor(t, e, n, r, a) {
2392
+ o(this, kt);
2393
+ o(this, is);
2394
+ o(this, ns);
2395
+ o(this, wi);
2396
+ o(this, pi);
2397
+ o(this, rs, new x());
2398
+ o(this, mi, 0);
2399
+ u(this, kt, t), u(this, is, e), u(this, ns, n), u(this, wi, r), u(this, pi, a);
2400
+ }
2401
+ endStatus() {
2402
+ return s(this, rs).promise;
2403
+ }
2404
+ groupId() {
2405
+ return s(this, is);
2406
+ }
2407
+ subscribeId() {
2408
+ return s(this, ns);
2409
+ }
2410
+ next() {
2411
+ return h(this, null, function* () {
2412
+ if (!s(this, rs).pending)
2413
+ return { done: !0, value: void 0 };
2414
+ if (yield s(this, kt).isDone())
2415
+ return { done: !0, value: void 0 };
2416
+ const t = s(this, mi) === 0 ? s(this, is) : yield s(this, kt).readBigVarInt(), e = yield s(this, kt).readBigVarInt(), n = yield s(this, kt).readVarInt();
2417
+ let r = 0, a = new Uint8Array();
2418
+ return n > 0 ? a = yield s(this, kt).read(n) : r = yield s(this, kt).readVarInt(), io(r), (r === $.EndOfTrackAndGroup || r === $.EndOfGroup) && s(this, rs).resolve(r), _r(this, mi)._++, {
2419
+ done: !1,
2420
+ value: {
2421
+ subscribeId: s(this, ns),
2422
+ trackAlias: s(this, wi),
2423
+ groupId: t,
2424
+ subGroupId: k(0),
2425
+ objectId: e,
2426
+ subscriberPriority: s(this, pi),
2427
+ objectStatus: r,
2428
+ payload: a
2429
+ }
2430
+ };
2431
+ });
2432
+ }
2433
+ return() {
2434
+ return h(this, null, function* () {
2435
+ for (; !(yield this.next()).done; )
2436
+ ;
2437
+ return { done: !0, value: void 0 };
2438
+ });
2439
+ }
2440
+ [Symbol.asyncIterator]() {
2441
+ return this;
2442
+ }
2443
+ [Oe()]() {
2444
+ return Promise.resolve();
2445
+ }
2446
+ [Symbol.asyncDispose]() {
2447
+ return Promise.resolve();
2448
+ }
2449
+ }
2450
+ kt = new WeakMap(), is = new WeakMap(), ns = new WeakMap(), wi = new WeakMap(), pi = new WeakMap(), rs = new WeakMap(), mi = new WeakMap();
2451
+ var Vt, as, bi, yi, Ee, no, vr;
2452
+ class Sc {
2453
+ constructor(t, e, n, r) {
2454
+ o(this, Ee);
2455
+ o(this, Vt);
2456
+ o(this, as);
2457
+ o(this, bi);
2458
+ o(this, yi);
2459
+ u(this, Vt, t), u(this, as, e), u(this, bi, n), u(this, yi, r);
2460
+ }
2461
+ groups() {
2462
+ return w(this, Ee, no).call(this);
2463
+ }
2464
+ subscribeId() {
2465
+ return s(this, as);
2466
+ }
2467
+ return() {
2468
+ return h(this, null, function* () {
2469
+ return yield s(this, Vt).close(), { done: !0, value: void 0 };
2470
+ });
2471
+ }
2472
+ [Symbol.asyncIterator]() {
2473
+ return this;
2474
+ }
2475
+ [Oe()]() {
2476
+ return w(this, Ee, vr).call(this);
2477
+ }
2478
+ [Symbol.asyncDispose]() {
2479
+ return w(this, Ee, vr).call(this);
2480
+ }
2481
+ }
2482
+ Vt = new WeakMap(), as = new WeakMap(), bi = new WeakMap(), yi = new WeakMap(), Ee = new WeakSet(), no = function() {
2483
+ return Dt(this, null, function* () {
2484
+ for (; !(yield new A(s(this, Vt).isDone())); ) {
2485
+ const t = yield new A(s(this, Vt).readBigVarInt()), e = new Ic(
2486
+ s(this, Vt),
2487
+ t,
2488
+ s(this, as),
2489
+ s(this, bi),
2490
+ s(this, yi)
2491
+ );
2492
+ if (yield e, (yield new A(e.endStatus())) === $.EndOfTrackAndGroup)
2493
+ return;
2494
+ }
2495
+ });
2496
+ }, vr = function() {
2497
+ return s(this, Vt).close().catch(() => {
2498
+ });
2499
+ };
2500
+ var ht, os, gi, cs, vi, ki, Ii, Wn, De, ro, kr;
2501
+ class Uc {
2502
+ constructor(t, e, n, r, a, c) {
2503
+ o(this, De);
2504
+ o(this, ht);
2505
+ o(this, os);
2506
+ o(this, gi);
2507
+ o(this, cs);
2508
+ o(this, vi);
2509
+ o(this, ki);
2510
+ o(this, Ii, !1);
2511
+ o(this, Wn, Xt.get().createContext("GroupReader"));
2512
+ u(this, ht, t), u(this, os, e), u(this, gi, n), u(this, cs, r), u(this, vi, a), u(this, ki, c);
2513
+ }
2514
+ groupId() {
2515
+ return s(this, cs);
2516
+ }
2517
+ subscribeId() {
2518
+ return s(this, os);
2519
+ }
2520
+ next() {
2521
+ return h(this, null, function* () {
2522
+ try {
2523
+ if ((yield s(this, ht).isDone()) || s(this, Ii))
2524
+ return { done: !0, value: void 0 };
2525
+ const t = yield s(this, ht).readBigVarInt(), e = yield s(this, ht).readVarInt();
2526
+ let n = 0, r = new Uint8Array();
2527
+ return e > 0 ? r = yield s(this, ht).read(e) : n = yield s(this, ht).readVarInt(), io(n), n === $.EndOfGroup && u(this, Ii, !0), {
2528
+ done: !1,
2529
+ value: {
2530
+ subscribeId: s(this, os),
2531
+ trackAlias: s(this, gi),
2532
+ groupId: s(this, cs),
2533
+ subGroupId: s(this, vi),
2534
+ subscriberPriority: s(this, ki),
2535
+ objectId: t,
2536
+ objectStatus: n,
2537
+ payload: r
2538
+ }
2539
+ };
2540
+ } catch (t) {
2541
+ return s(this, Wn).info("Error reading object", { error: t }), { done: !0, value: void 0 };
2542
+ }
2543
+ });
2544
+ }
2545
+ return() {
2546
+ return h(this, null, function* () {
2547
+ return yield s(this, ht).close().catch(() => {
2548
+ }), { done: !0, value: void 0 };
2549
+ });
2550
+ }
2551
+ groups() {
2552
+ return w(this, De, ro).call(this);
2553
+ }
2554
+ [Symbol.asyncIterator]() {
2555
+ return this;
2556
+ }
2557
+ [Oe()]() {
2558
+ return w(this, De, kr).call(this);
2559
+ }
2560
+ [Symbol.asyncDispose]() {
2561
+ return w(this, De, kr).call(this);
2562
+ }
2563
+ }
2564
+ ht = new WeakMap(), os = new WeakMap(), gi = new WeakMap(), cs = new WeakMap(), vi = new WeakMap(), ki = new WeakMap(), Ii = new WeakMap(), Wn = new WeakMap(), De = new WeakSet(), ro = function() {
2565
+ return Dt(this, null, function* () {
2566
+ yield this;
2567
+ });
2568
+ }, kr = function() {
2569
+ return s(this, ht).close().catch(() => {
2570
+ });
2571
+ };
2572
+ function ao(i) {
2573
+ return h(this, null, function* () {
2574
+ const t = yield i.readVarInt();
2575
+ switch (t) {
2576
+ case gr.StreamHeaderGroup: {
2577
+ const e = yield i.readBigVarInt(), n = yield i.readBigVarInt(), r = yield i.readBigVarInt(), a = yield i.readBigVarInt(), c = yield i.readUnsigned8();
2578
+ return new Uc(i, e, n, r, a, c);
2579
+ }
2580
+ case gr.StreamHeaderTrack: {
2581
+ const e = yield i.readBigVarInt(), n = yield i.readBigVarInt(), r = yield i.readUnsigned8();
2582
+ return new Sc(i, e, n, r);
2583
+ }
2584
+ default:
2585
+ throw new Error("Unexpected message type " + t);
2586
+ }
2587
+ });
2588
+ }
2589
+ var ue, Ft, us, he, Ct;
2590
+ class Tc {
2591
+ constructor(t, e) {
2592
+ o(this, ue);
2593
+ o(this, Ft);
2594
+ o(this, us);
2595
+ o(this, he);
2596
+ o(this, Ct, /* @__PURE__ */ new Map());
2597
+ u(this, ue, t), u(this, Ft, e), u(this, us, new ReadableStream(new Zo(t))), s(this, ue).addEventListener("close", () => {
2598
+ s(this, Ct).forEach((n) => n.close());
2599
+ });
2600
+ }
2601
+ transportType() {
2602
+ return "websocket";
2603
+ }
2604
+ url() {
2605
+ return s(this, ue).url;
2606
+ }
2607
+ afterHandshake() {
2608
+ return s(this, Ft).postHandshake();
2609
+ }
2610
+ objectStream() {
2611
+ return h(this, null, function* () {
2612
+ var t;
2613
+ for (; ; ) {
2614
+ u(this, he, s(this, us).getReader());
2615
+ try {
2616
+ const { value: e, done: n } = yield s(this, he).read();
2617
+ if (n)
2618
+ return;
2619
+ const [r, a, c] = e;
2620
+ if (s(this, Ct).has(k(a))) {
2621
+ const d = s(this, Ct).get(k(a));
2622
+ if (!d)
2623
+ throw new Error("Stream not found");
2624
+ c.length > 0 && (yield d.push(c)), r || (d.close(), s(this, Ct).delete(k(a)));
2625
+ } else {
2626
+ let b;
2627
+ const [d, f] = Rr(100), p = new ReadableStream({
2628
+ pull(m) {
2629
+ return h(this, null, function* () {
2630
+ const I = yield f.pop();
2631
+ I ? m.enqueue(I) : m.close();
2632
+ });
2633
+ }
2634
+ });
2635
+ if (s(this, Ct).set(k(a), d), r || (yield p.cancel(), s(this, Ct).delete(k(a))), c.length > 0)
2636
+ return yield ao(new En(c, p));
2637
+ }
2638
+ } finally {
2639
+ (t = s(this, he)) == null || t.releaseLock();
2640
+ }
2641
+ }
2642
+ });
2643
+ }
2644
+ close() {
2645
+ var t;
2646
+ return s(this, Ft).cancel().catch(B), s(this, us).cancel("closing").catch(B), (t = s(this, he)) == null || t.cancel("closing").catch(B), s(this, ue).close();
2647
+ }
2648
+ closed() {
2649
+ return Promise.resolve();
2650
+ }
2651
+ writeMessage(t) {
2652
+ return h(this, null, function* () {
2653
+ yield s(this, Ft).write(t);
2654
+ });
2655
+ }
2656
+ readMessage() {
2657
+ return h(this, null, function* () {
2658
+ return s(this, Ft).read();
2659
+ });
2660
+ }
2661
+ }
2662
+ ue = new WeakMap(), Ft = new WeakMap(), us = new WeakMap(), he = new WeakMap(), Ct = new WeakMap();
2663
+ var le, de, fe, Si, $n, zn, oo;
2664
+ class Ec {
2665
+ constructor(t, e, n) {
2666
+ o(this, zn);
2667
+ o(this, le);
2668
+ o(this, de);
2669
+ o(this, fe, new Lr(100));
2670
+ o(this, Si);
2671
+ o(this, $n, Xt.get().createContext("WebTransportConnection"));
2672
+ u(this, Si, n), u(this, le, t), u(this, de, e), w(this, zn, oo).call(this).catch((r) => {
2673
+ s(this, $n).debug("Incoming streams handling ended with error", r), s(this, fe).close();
2674
+ });
2675
+ }
2676
+ transportType() {
2677
+ return "webtransport";
2678
+ }
2679
+ url() {
2680
+ return s(this, Si);
2681
+ }
2682
+ afterHandshake() {
2683
+ return s(this, de).postHandshake();
2684
+ }
2685
+ closed() {
2686
+ return h(this, null, function* () {
2687
+ yield s(this, le).closed;
2688
+ });
2689
+ }
2690
+ close() {
2691
+ s(this, le).close();
2692
+ }
2693
+ writeMessage(t) {
2694
+ return h(this, null, function* () {
2695
+ yield s(this, de).write(t);
2696
+ });
2697
+ }
2698
+ readMessage() {
2699
+ return h(this, null, function* () {
2700
+ return s(this, de).read();
2701
+ });
2702
+ }
2703
+ objectStream() {
2704
+ return h(this, null, function* () {
2705
+ return s(this, fe).pop();
2706
+ });
2707
+ }
2708
+ }
2709
+ le = new WeakMap(), de = new WeakMap(), fe = new WeakMap(), Si = new WeakMap(), $n = new WeakMap(), zn = new WeakSet(), oo = function() {
2710
+ return h(this, null, function* () {
2711
+ const t = s(this, le).incomingUnidirectionalStreams.getReader();
2712
+ for (; ; ) {
2713
+ const { value: e, done: n } = yield t.read();
2714
+ if (n) {
2715
+ s(this, fe).close();
2716
+ return;
2717
+ }
2718
+ const r = new En(new Uint8Array(), e);
2719
+ yield s(this, fe).push(ao(r));
2720
+ }
2721
+ });
2722
+ };
2723
+ function cr(i) {
2724
+ return h(this, null, function* () {
2725
+ const t = new WebSocket(i.url);
2726
+ t.binaryType = "arraybuffer", yield new Promise((a, c) => {
2727
+ t.addEventListener("error", c, { once: !0 }), t.addEventListener("open", a, { once: !0 });
2728
+ });
2729
+ const e = On.wrapWebsocket(t);
2730
+ _a(e, Ga.Subscriber).catch(() => {
2731
+ t.close();
2732
+ });
2733
+ const n = new Tc(t, e);
2734
+ return Vn.subscriber(n, i.authToken);
2735
+ });
2736
+ }
2737
+ function ia(i) {
2738
+ return h(this, null, function* () {
2739
+ const t = "60b82e8021689e163c1041b4475ef9c86e7565bc45d1a0aa43f5148769f461c7", e = new Uint8Array(t.length / 2);
2740
+ for (let f = 0; f < e.length; f += 1)
2741
+ e[f] = parseInt(t.slice(2 * f, 2 * f + 2), 16);
2742
+ const n = new WebTransport(i.url, {
2743
+ congestionControl: "low-latency"
2744
+ // serverCertificateHashes: [{ algorithm: "sha-256", value: hexBytes }],
2745
+ });
2746
+ yield Promise.race([n.ready, n.closed.then(() => Promise.reject(new Error("WebTransport closed")))]);
2747
+ const r = yield n.createBidirectionalStream(), a = On.wrapWebTransport(r);
2748
+ _a(a, Ga.Subscriber).catch(() => {
2749
+ n.close();
2750
+ });
2751
+ const c = new Ec(n, a, i.url.toString());
2752
+ return Vn.subscriber(c, i.authToken);
2753
+ });
2754
+ }
2755
+ function Dc(i) {
2756
+ return h(this, null, function* () {
2757
+ if (self.WebTransport && (i == null ? void 0 : i.preferredTransport) !== "websocket" && i.url.protocol.startsWith("https")) {
2758
+ if (!i.websocketFallbackTimeoutMs)
2759
+ return ia(i);
2760
+ const t = ia(i).catch(() => cr(i)), e = yield Promise.race([t, er(i.websocketFallbackTimeoutMs)]);
2761
+ return e || cr(i);
2762
+ }
2763
+ return cr(i);
2764
+ });
2765
+ }
2766
+ var Bt;
2767
+ class Rt {
2768
+ constructor() {
2769
+ o(this, Bt, {
2770
+ name: "",
2771
+ priority: 0,
2772
+ groupOrder: "descending",
2773
+ filterType: { type: "latest-group" }
2774
+ });
2775
+ }
2776
+ name(t) {
2777
+ return s(this, Bt).name = t, this;
2778
+ }
2779
+ priority(t) {
2780
+ return s(this, Bt).priority = t, this;
2781
+ }
2782
+ groupOrder(t) {
2783
+ return s(this, Bt).groupOrder = t, this;
2784
+ }
2785
+ /**
2786
+ * @param startGroup the group to start the subscription at
2787
+ * @returns the builder
2788
+ */
2789
+ startGroup(t) {
2790
+ return s(this, Bt).filterType = {
2791
+ type: "absolute-start",
2792
+ start: { group: t, object: k(0) }
2793
+ }, this;
2794
+ }
2795
+ range(t, e) {
2796
+ return s(this, Bt).filterType = {
2797
+ type: "absolute-range",
2798
+ start: { group: t, object: k(0) },
2799
+ end: { group: e, object: k(0) }
2800
+ }, this;
2801
+ }
2802
+ build() {
2803
+ return s(this, Bt);
2804
+ }
2805
+ }
2806
+ Bt = new WeakMap();
2807
+ var hs, Ui;
2808
+ class co {
2809
+ constructor(t, e) {
2810
+ o(this, hs);
2811
+ o(this, Ui);
2812
+ u(this, hs, t), u(this, Ui, e);
2813
+ }
2814
+ subscribe(t) {
2815
+ return s(this, hs).subscribe(this.namespace(), t);
2816
+ }
2817
+ closed() {
2818
+ return s(this, hs).closed();
2819
+ }
2820
+ namespace() {
2821
+ return s(this, Ui).namespace;
2822
+ }
2823
+ }
2824
+ hs = new WeakMap(), Ui = new WeakMap();
2825
+ function Kt(i) {
2826
+ const t = i.at(1);
2827
+ if (!t)
2828
+ throw new Error("namespace must contain a channel ID");
2829
+ return t;
2830
+ }
2831
+ function Ac(i) {
2832
+ return "tracks" in i;
2833
+ }
2834
+ function Oc(i) {
2835
+ const t = new TextDecoder().decode(i);
2836
+ return JSON.parse(t);
2837
+ }
2838
+ var q, It, we, it, Ti, Mn, Ei, Ir;
2839
+ const Gr = class Gr {
2840
+ constructor(t, e) {
2841
+ o(this, Ei);
2842
+ o(this, q);
2843
+ // The largest group id seen so far - used to switch seamlessly between tracks
2844
+ o(this, It);
2845
+ // We keep track of the most recent groups to ensure we haven't missed any due to re-ordering before we close subscriptions
2846
+ o(this, we, new Pr(100));
2847
+ // This contains the unconsumed groups if this track has an absolute range
2848
+ o(this, it);
2849
+ o(this, Ti);
2850
+ o(this, Mn, (t) => h(this, null, function* () {
2851
+ if (!t)
2852
+ return s(this, q).close();
2853
+ if (s(this, it))
2854
+ return;
2855
+ const e = s(this, we).items().reduce((n, r) => n < r ? n : r, t);
2856
+ u(this, it, w(this, Ei, Ir).call(this, e, t)), s(this, it).size === 0 && (yield s(this, q).close());
2857
+ }));
2858
+ u(this, q, t), u(this, It, e), t.done().then((n) => h(this, null, function* () {
2859
+ var r;
2860
+ return s(this, Mn).call(this, (r = n.finalInfo) == null ? void 0 : r.group);
2861
+ })).catch(B), u(this, Ti, t.groups());
2862
+ }
2863
+ static subscribe(t, e) {
2864
+ return h(this, null, function* () {
2865
+ const n = yield t.subscribe(e);
2866
+ return new Gr(n, void 0);
2867
+ });
2868
+ }
2869
+ subscribeId() {
2870
+ return s(this, q).id;
2871
+ }
2872
+ name() {
2873
+ return s(this, q).name;
2874
+ }
2875
+ largestGroupId() {
2876
+ return s(this, It);
2877
+ }
2878
+ // The subscription needs renewal if it is still active and aren't finishing up the unconsumed group IDs.
2879
+ // If we are just finishing up the unconsumed group IDs we assume we'll finish up before the expiry.
2880
+ needsRenewal() {
2881
+ return s(this, q).expiryState() === "active" && s(this, it) === void 0;
2882
+ }
2883
+ /** Set the endGroup as the end of group.
2884
+ * This lets the subscription end when the endGroup is reached.
2885
+ */
2886
+ endOfTrack(t) {
2887
+ const e = s(this, we).items().reduce((n, r) => n < r ? n : r, t);
2888
+ return this.update(e, t);
2889
+ }
2890
+ update(t, e) {
2891
+ return h(this, null, function* () {
2892
+ return u(this, it, w(this, Ei, Ir).call(this, t, e)), s(this, it).size === 0 && (yield s(this, q).close()), s(this, q).update(t, e);
2893
+ });
2894
+ }
2895
+ unsubscribe() {
2896
+ return s(this, q).unsubscribe();
2897
+ }
2898
+ next() {
2899
+ return h(this, null, function* () {
2900
+ var n;
2901
+ if (s(this, it) && s(this, it).size === 0)
2902
+ return { done: !0, value: void 0 };
2903
+ const t = yield s(this, Ti).next();
2904
+ if (t.done)
2905
+ return t;
2906
+ const e = t.value.groupId();
2907
+ return (n = s(this, it)) == null || n.delete(e), s(this, we).push(e), s(this, It) || u(this, It, e), u(this, It, s(this, It) < e ? e : s(this, It)), t;
2908
+ });
2909
+ }
2910
+ return() {
2911
+ return s(this, q).return();
2912
+ }
2913
+ [Symbol.asyncIterator]() {
2914
+ return this;
2915
+ }
2916
+ };
2917
+ q = new WeakMap(), It = new WeakMap(), we = new WeakMap(), it = new WeakMap(), Ti = new WeakMap(), Mn = new WeakMap(), Ei = new WeakSet(), Ir = function(t, e) {
2918
+ const n = /* @__PURE__ */ new Set();
2919
+ for (let r = t; r <= e; r++)
2920
+ n == null || n.add(r);
2921
+ return s(this, we).items().forEach((r) => {
2922
+ n == null || n.delete(r);
2923
+ }), n;
2924
+ };
2925
+ let Cn = Gr;
2926
+ var St, pe, xt, Wt, Di;
2927
+ const Nr = class Nr {
2928
+ constructor(t) {
2929
+ // The current active subscription
2930
+ o(this, St);
2931
+ // The current group iterator - gets replaced by the next in #groups when it runs out
2932
+ o(this, pe);
2933
+ // The next group iterators to switch to when the current one runs out
2934
+ o(this, xt, new Lr(10));
2935
+ o(this, Wt);
2936
+ o(this, Di, (t, e) => h(this, null, function* () {
2937
+ var m = [];
2938
+ try {
2939
+ const n = mt(m, yield s(this, St).lock());
2940
+ const r = { subscribeId: n.value.subscribeId() };
2941
+ if (!n.value.needsRenewal()) {
2942
+ s(this, Wt).debug("Subscription does not need renewal", r);
2943
+ return;
2944
+ }
2945
+ const a = n.value.largestGroupId();
2946
+ const c = a !== void 0;
2947
+ const d = new Rt().name(e.name).priority(e.priority).groupOrder(e.groupOrder);
2948
+ r.largestGroupId = a;
2949
+ s(this, Wt).debug("Renewing subscription", r);
2950
+ switch (e.filterType.type) {
2951
+ case "absolute-range":
2952
+ s(this, Wt).debug("Absolute range is not renewed", r);
2953
+ return;
2954
+ case "absolute-start":
2955
+ case "latest-group":
2956
+ case "latest-object":
2957
+ c && d.startGroup(a + k(1));
2958
+ break;
2959
+ }
2960
+ const f = d.build();
2961
+ r.newTrack = f;
2962
+ const [p] = yield Promise.all([
2963
+ t.subscribe(f),
2964
+ c ? n.value.update(a, a) : n.value.unsubscribe()
2965
+ ]);
2966
+ p.expiryNotification().then(() => s(this, Di).call(this, t, f)).catch(B);
2967
+ const b = new Cn(p, a);
2968
+ n.value = b;
2969
+ yield s(this, xt).push(b);
2970
+ s(this, Wt).info("Subscription renewed", r);
2971
+ } catch (I) {
2972
+ var y = I, E = !0;
2973
+ } finally {
2974
+ bt(m, y, E);
2975
+ }
2976
+ }));
2977
+ u(this, St, new Go(t)), u(this, pe, t), u(this, Wt, Xt.get().createContext(`Renewable '${t.name()}'`));
2978
+ }
2979
+ static subscribe(t, e, n) {
2980
+ return h(this, null, function* () {
2981
+ const r = yield t.subscribe(e), a = new Nr(new Cn(r, n));
2982
+ return r.expiryNotification().then(() => {
2983
+ var c;
2984
+ return s(c = a, Di).call(c, t, e);
2985
+ }).catch(B), a;
2986
+ });
2987
+ }
2988
+ largestGroupId() {
2989
+ return s(this, St).unsafeValue().largestGroupId();
2990
+ }
2991
+ update(t, e) {
2992
+ return h(this, null, function* () {
2993
+ var r = [];
2994
+ try {
2995
+ const n = mt(r, yield s(this, St).lock());
2996
+ s(this, xt).close();
2997
+ return n.value.update(t, e);
2998
+ } catch (a) {
2999
+ var c = a, d = !0;
3000
+ } finally {
3001
+ bt(r, c, d);
3002
+ }
3003
+ });
3004
+ }
3005
+ endOfTrack(t) {
3006
+ return h(this, null, function* () {
3007
+ var n = [];
3008
+ try {
3009
+ const e = mt(n, yield s(this, St).lock());
3010
+ s(this, xt).close();
3011
+ return e.value.endOfTrack(t);
3012
+ } catch (r) {
3013
+ var a = r, c = !0;
3014
+ } finally {
3015
+ bt(n, a, c);
3016
+ }
3017
+ });
3018
+ }
3019
+ unsubscribe() {
3020
+ return h(this, null, function* () {
3021
+ var e = [];
3022
+ try {
3023
+ const t = mt(e, yield s(this, St).lock());
3024
+ s(this, xt).close();
3025
+ return t.value.unsubscribe();
3026
+ } catch (n) {
3027
+ var r = n, a = !0;
3028
+ } finally {
3029
+ bt(e, r, a);
3030
+ }
3031
+ });
3032
+ }
3033
+ return() {
3034
+ return h(this, null, function* () {
3035
+ var e = [];
3036
+ try {
3037
+ const t = mt(e, yield s(this, St).lock());
3038
+ s(this, xt).close();
3039
+ return t.value.return();
3040
+ } catch (n) {
3041
+ var r = n, a = !0;
3042
+ } finally {
3043
+ bt(e, r, a);
3044
+ }
3045
+ });
3046
+ }
3047
+ next() {
3048
+ return h(this, null, function* () {
3049
+ var e, n;
3050
+ const t = yield s(this, pe).next();
3051
+ if (t.done) {
3052
+ yield (n = (e = s(this, pe)).return) == null ? void 0 : n.call(e);
3053
+ const r = yield s(this, xt).pop();
3054
+ if (r)
3055
+ return u(this, pe, r), this.next();
3056
+ }
3057
+ return t;
3058
+ });
3059
+ }
3060
+ [Symbol.asyncIterator]() {
3061
+ return this;
3062
+ }
3063
+ objects() {
3064
+ return Dt(this, null, function* () {
3065
+ try {
3066
+ for (var d = C(this), f, p, b; f = !(p = yield new A(d.next())).done; f = !1) {
3067
+ var t = p.value;
3068
+ var e = [];
3069
+ try {
3070
+ const m = mt(e, t, !0);
3071
+ yield* or(m);
3072
+ } catch (n) {
3073
+ var r = n, a = !0;
3074
+ } finally {
3075
+ var c = bt(e, r, a);
3076
+ c && (yield new A(c));
3077
+ }
3078
+ }
3079
+ } catch (p) {
3080
+ b = [p];
3081
+ } finally {
3082
+ try {
3083
+ f && (p = d.return) && (yield new A(p.call(d)));
3084
+ } finally {
3085
+ if (b)
3086
+ throw b[0];
3087
+ }
3088
+ }
3089
+ });
3090
+ }
3091
+ };
3092
+ St = new WeakMap(), pe = new WeakMap(), xt = new WeakMap(), Wt = new WeakMap(), Di = new WeakMap();
3093
+ let Ht = Nr;
3094
+ const Vc = "catalog";
3095
+ function na(i) {
3096
+ const t = Oc(i.payload);
3097
+ if (!Ac(t))
3098
+ throw new Error("unexpected catalog type");
3099
+ return t;
3100
+ }
3101
+ var me, Ai, Oi, Vi, Hn, uo;
3102
+ const Xn = class Xn {
3103
+ constructor(t, e, n) {
3104
+ o(this, Hn);
3105
+ o(this, me);
3106
+ o(this, Ai);
3107
+ o(this, Oi);
3108
+ o(this, Vi);
3109
+ u(this, Ai, t), u(this, me, e), u(this, Oi, n), u(this, Vi, w(this, Hn, uo).call(this));
3110
+ }
3111
+ catalog() {
3112
+ return s(this, me);
3113
+ }
3114
+ closed() {
3115
+ return s(this, Vi);
3116
+ }
3117
+ close() {
3118
+ return h(this, null, function* () {
3119
+ return s(this, me).close(), (yield s(this, Ai).promise).unsubscribe();
3120
+ });
3121
+ }
3122
+ static start(t, e) {
3123
+ return h(this, null, function* () {
3124
+ const n = x.fromPromise(
3125
+ Ht.subscribe(
3126
+ t,
3127
+ new Rt().name(e.catalogName || Vc).groupOrder("ascending").build()
3128
+ )
3129
+ ), r = x.fromPromise(n.promise.then((f) => f.objects()));
3130
+ if (e.catalog)
3131
+ return new Xn(n, new ft(e.catalog), r);
3132
+ const c = yield (yield r.promise).next();
3133
+ if (!c.value)
3134
+ throw new Error("No catalog found");
3135
+ const d = na(c.value);
3136
+ return new Xn(n, new ft(d), r);
3137
+ });
3138
+ }
3139
+ };
3140
+ me = new WeakMap(), Ai = new WeakMap(), Oi = new WeakMap(), Vi = new WeakMap(), Hn = new WeakSet(), uo = function() {
3141
+ return h(this, null, function* () {
3142
+ const t = yield s(this, Oi).promise;
3143
+ try {
3144
+ for (var e = C(t), n, r, a; n = !(r = yield e.next()).done; n = !1) {
3145
+ const c = r.value;
3146
+ if (c.objectStatus !== $.Normal)
3147
+ continue;
3148
+ const d = na(c);
3149
+ s(this, me).update(d);
3150
+ }
3151
+ } catch (r) {
3152
+ a = [r];
3153
+ } finally {
3154
+ try {
3155
+ n && (r = e.return) && (yield r.call(e));
3156
+ } finally {
3157
+ if (a)
3158
+ throw a[0];
3159
+ }
3160
+ }
3161
+ });
3162
+ };
3163
+ let Sr = Xn;
3164
+ function ho(i) {
3165
+ const t = atob(i), e = new Uint8Array(t.length);
3166
+ for (let n = 0; n < t.length; n++)
3167
+ e[n] = t.charCodeAt(n);
3168
+ return e.buffer;
3169
+ }
3170
+ var Ci, ls, Bi, ds, xi, Ur;
3171
+ class Cc {
3172
+ constructor(t, e, n, r) {
3173
+ o(this, xi);
3174
+ o(this, Ci);
3175
+ o(this, ls);
3176
+ o(this, Bi);
3177
+ l(this, "track");
3178
+ o(this, ds, Xt.get().createContext("CmafGroup"));
3179
+ this.track = r, u(this, Ci, n), u(this, ls, t), u(this, Bi, e);
3180
+ }
3181
+ [Symbol.asyncIterator]() {
3182
+ return Dt(this, null, function* () {
3183
+ const t = { name: this.track.trackObject.name, namespace: this.track.namespace };
3184
+ s(this, ds).debug("start", Yt({}, t));
3185
+ try {
3186
+ for (var e = C(s(this, ls)), n, r, a; n = !(r = yield new A(e.next())).done; n = !1) {
3187
+ const c = r.value;
3188
+ if (c.objectStatus === $.EndOfTrackAndGroup && (yield new A(this.track.endOfTrack(c.groupId))), c.objectStatus !== $.Normal)
3189
+ continue;
3190
+ const d = s(this, Bi).createFragment(c.payload), f = d.timescale(), p = d.baseMediaDecodeTime() / f * 1e3, b = d.duration() / f * 1e3, m = p + b, I = s(this, Ci) / 1e3 * f;
3191
+ d.updateBaseMediaDecodeTime(d.baseMediaDecodeTime() - I);
3192
+ const y = this.track.timestampRange();
3193
+ if (y && p >= y[1])
3194
+ break;
3195
+ s(this, ds).debug("fragment", rr(Yt({}, t), {
3196
+ startTime: p,
3197
+ endTime: m,
3198
+ subscribeId: c.subscribeId,
3199
+ groupId: c.groupId,
3200
+ objectId: c.objectId
3201
+ })), yield [c.groupId, d];
3202
+ }
3203
+ } catch (r) {
3204
+ a = [r];
3205
+ } finally {
3206
+ try {
3207
+ n && (r = e.return) && (yield new A(r.call(e)));
3208
+ } finally {
3209
+ if (a)
3210
+ throw a[0];
3211
+ }
3212
+ }
3213
+ s(this, ds).debug("end", Yt({}, t));
3214
+ });
3215
+ }
3216
+ [Oe()]() {
3217
+ return w(this, xi, Ur).call(this);
3218
+ }
3219
+ [Symbol.asyncDispose]() {
3220
+ return w(this, xi, Ur).call(this);
3221
+ }
3222
+ }
3223
+ Ci = new WeakMap(), ls = new WeakMap(), Bi = new WeakMap(), ds = new WeakMap(), xi = new WeakSet(), Ur = function() {
3224
+ return h(this, null, function* () {
3225
+ var t, e;
3226
+ return yield (e = (t = s(this, ls)).return) == null ? void 0 : e.call(t), Promise.resolve();
3227
+ });
3228
+ };
3229
+ var Pi, Ut, Ri, Li, Zn, lo;
3230
+ const je = class je {
3231
+ constructor(t, e, n, r, a) {
3232
+ o(this, Pi);
3233
+ o(this, Ut);
3234
+ // A static offset that will be applied to all fragments
3235
+ o(this, Ri);
3236
+ // Stop consuming the track after we have passed thig timestamp
3237
+ o(this, Li);
3238
+ l(this, "trackObject");
3239
+ l(this, "namespace");
3240
+ this.trackObject = t, this.namespace = e, u(this, Ut, n), u(this, Pi, r), u(this, Ri, a);
3241
+ }
3242
+ static subscribe(t, e, n, r) {
3243
+ return h(this, null, function* () {
3244
+ var b;
3245
+ if (e.format !== "cmaf")
3246
+ throw new Error("format must be cmaf");
3247
+ const a = new Rt().name(e.name);
3248
+ r && a.startGroup(r);
3249
+ const c = a.build();
3250
+ if (e.initTrack) {
3251
+ const m = new Rt().name(e.initTrack).build(), [I, y] = yield Promise.all([
3252
+ w(b = je, Zn, lo).call(b, t, m),
3253
+ Ht.subscribe(t, c, r ? r - k(1) : void 0)
3254
+ ]), E = new ta(I);
3255
+ return new je(e, t.namespace(), y, E, n);
3256
+ }
3257
+ Sa(e.initData, "no init data found on track");
3258
+ const d = ho(e.initData), f = new ta(new Uint8Array(d)), p = yield Ht.subscribe(t, c, r ? r - k(1) : void 0);
3259
+ return new je(e, t.namespace(), p, f, n);
3260
+ });
3261
+ }
3262
+ largestGroupId() {
3263
+ return s(this, Ut).largestGroupId();
3264
+ }
3265
+ stopAfterTimestampReached(t) {
3266
+ u(this, Li, [0, t]);
3267
+ }
3268
+ timestampRange() {
3269
+ return s(this, Li);
3270
+ }
3271
+ endOfTrack(t) {
3272
+ return s(this, Ut).endOfTrack(t);
3273
+ }
3274
+ update(t, e) {
3275
+ return s(this, Ut).update(t, e);
3276
+ }
3277
+ unsubscribe() {
3278
+ return h(this, null, function* () {
3279
+ return s(this, Ut).unsubscribe();
3280
+ });
3281
+ }
3282
+ next() {
3283
+ return h(this, null, function* () {
3284
+ const t = yield s(this, Ut).next();
3285
+ return t.done ? t : {
3286
+ done: !1,
3287
+ value: new Cc(t.value, s(this, Pi), s(this, Ri), this)
3288
+ };
3289
+ });
3290
+ }
3291
+ return() {
3292
+ return h(this, null, function* () {
3293
+ return yield s(this, Ut).return(), { done: !0, value: void 0 };
3294
+ });
3295
+ }
3296
+ [Symbol.asyncIterator]() {
3297
+ return this;
3298
+ }
3299
+ [Oe()]() {
3300
+ return this.unsubscribe();
3301
+ }
3302
+ [Symbol.asyncDispose]() {
3303
+ return h(this, null, function* () {
3304
+ return this.unsubscribe();
3305
+ });
3306
+ }
3307
+ };
3308
+ Pi = new WeakMap(), Ut = new WeakMap(), Ri = new WeakMap(), Li = new WeakMap(), Zn = new WeakSet(), lo = function(t, e) {
3309
+ return h(this, null, function* () {
3310
+ const n = yield t.subscribe(e), r = yield n.objects().next();
3311
+ if (r.done)
3312
+ throw new Error("No init object");
3313
+ return yield n.close(), r.value.payload;
3314
+ });
3315
+ }, o(je, Zn);
3316
+ let Tr = je;
3317
+ const ra = 1e4, Bc = 3e4;
3318
+ var Yn, be, ye, ji, Gi, Ni, Ae, Dr, fo;
3319
+ const Fr = class Fr {
3320
+ constructor(t, e, n) {
3321
+ o(this, Ae);
3322
+ o(this, Yn, Xt.get().createContext("Timeline"));
3323
+ o(this, be, new ft([]));
3324
+ o(this, ye);
3325
+ o(this, ji);
3326
+ o(this, Gi);
3327
+ o(this, Ni);
3328
+ u(this, ji, t), u(this, Gi, n), u(this, ye, e), u(this, Ni, w(this, Ae, Dr).call(this, s(this, ye)));
3329
+ }
3330
+ closed() {
3331
+ return s(this, Ni);
3332
+ }
3333
+ close() {
3334
+ return h(this, null, function* () {
3335
+ return (yield s(this, ye).promise).unsubscribe();
3336
+ });
3337
+ }
3338
+ timeline() {
3339
+ const [t, e] = s(this, be).value();
3340
+ return t;
3341
+ }
3342
+ /**
3343
+ * Returns the offset between the wallclock time and media timestamps.
3344
+ * This is useful for time aligning two streams based on the common wallclock time
3345
+ */
3346
+ timestampWallclockOffset() {
3347
+ return Oo(this.timeline().map((t) => t.mediaPts - t.wallclock));
3348
+ }
3349
+ static start(t, e) {
3350
+ const n = x.fromPromise(
3351
+ Ht.subscribe(t, new Rt().name(e).groupOrder("ascending").build())
3352
+ );
3353
+ return new Fr(t, n, e);
3354
+ }
3355
+ waitForWallclockTime(t) {
3356
+ return h(this, null, function* () {
3357
+ return yield s(this, be).waitFor((e) => !!e.find((n) => n.wallclock >= t)), this.timeline();
3358
+ });
3359
+ }
3360
+ waitForTimelineToHaveMinDuration() {
3361
+ return h(this, null, function* () {
3362
+ return yield s(this, be).waitFor((t) => {
3363
+ const e = t[0], n = t[t.length - 1];
3364
+ return !e || !n ? !1 : n.wallclock - e.wallclock > ra;
3365
+ }), this.timeline();
3366
+ });
3367
+ }
3368
+ };
3369
+ Yn = new WeakMap(), be = new WeakMap(), ye = new WeakMap(), ji = new WeakMap(), Gi = new WeakMap(), Ni = new WeakMap(), Ae = new WeakSet(), Dr = function(t) {
3370
+ return h(this, null, function* () {
3371
+ const e = yield t.promise;
3372
+ try {
3373
+ for (var y = C(e), E, P, H; E = !(P = yield y.next()).done; E = !1) {
3374
+ var d = P.value;
3375
+ var f = [];
3376
+ try {
3377
+ const T = mt(f, d, !0);
3378
+ try {
3379
+ for (var n = C(T), r, a, c; r = !(a = yield n.next()).done; r = !1) {
3380
+ const g = a.value;
3381
+ if (g.objectStatus !== $.Normal)
3382
+ continue;
3383
+ const Y = xc(g.payload);
3384
+ s(this, be).update((S) => {
3385
+ var Tt, Us;
3386
+ for (S.push(...Y), S.sort((Ki, Qi) => Ki.wallclock - Qi.wallclock); S[0] && ((Us = (Tt = S[S.length - 1]) == null ? void 0 : Tt.wallclock) != null ? Us : 0) - S[0].wallclock > Bc; )
3387
+ S.shift();
3388
+ return S;
3389
+ }), e === s(this, ye).resolved && g.groupId > k(0) && g.objectId == k(0) && w(this, Ae, fo).call(this, g.groupId).catch((S) => {
3390
+ s(this, Yn).warn("backfill failed", S);
3391
+ });
3392
+ }
3393
+ } catch (a) {
3394
+ c = [a];
3395
+ } finally {
3396
+ try {
3397
+ r && (a = n.return) && (yield a.call(n));
3398
+ } finally {
3399
+ if (c)
3400
+ throw c[0];
3401
+ }
3402
+ }
3403
+ } catch (p) {
3404
+ var b = p, m = !0;
3405
+ } finally {
3406
+ var I = bt(f, b, m);
3407
+ I && (yield I);
3408
+ }
3409
+ }
3410
+ } catch (P) {
3411
+ H = [P];
3412
+ } finally {
3413
+ try {
3414
+ E && (P = y.return) && (yield P.call(y));
3415
+ } finally {
3416
+ if (H)
3417
+ throw H[0];
3418
+ }
3419
+ }
3420
+ });
3421
+ }, fo = function(t) {
3422
+ return h(this, null, function* () {
3423
+ const e = t - k(1), n = this.timeline(), r = n[0], a = n[n.length - 1];
3424
+ if (!r || !a || a.wallclock - r.wallclock > ra)
3425
+ return;
3426
+ const c = x.fromPromise(
3427
+ Ht.subscribe(
3428
+ s(this, ji),
3429
+ new Rt().name(s(this, Gi)).groupOrder("ascending").range(e, e).build()
3430
+ )
3431
+ );
3432
+ return w(this, Ae, Dr).call(this, c);
3433
+ });
3434
+ };
3435
+ let Er = Fr;
3436
+ function xc(i) {
3437
+ var e;
3438
+ const t = new TextDecoder("utf-8").decode(i).split(`
3439
+ `);
3440
+ return (e = t[0]) != null && e.startsWith("MEDIA_PTS") && t.shift(), t.filter((n) => n.length > 0).map((n) => {
3441
+ const [r, a, c, d, f] = n.split(",");
3442
+ if (!r || !d)
3443
+ throw new Error(`invalid timeline row: ${n}`);
3444
+ return {
3445
+ mediaPts: parseInt(r),
3446
+ groupId: a ? parseInt(a) : void 0,
3447
+ objectId: c ? parseInt(c) : void 0,
3448
+ wallclock: parseInt(d),
3449
+ metadata: f
3450
+ };
3451
+ });
3452
+ }
3453
+ function Pc(i) {
3454
+ return typeof i.language == "string";
3455
+ }
3456
+ var Jn, Fi, $t, fs;
3457
+ const Wr = class Wr {
3458
+ constructor(t, e, n, r, a) {
3459
+ o(this, Jn, new Vo());
3460
+ o(this, Fi);
3461
+ o(this, $t);
3462
+ o(this, fs, 0);
3463
+ l(this, "trackObject");
3464
+ l(this, "namespace");
3465
+ u(this, $t, t), u(this, Fi, e), this.trackObject = n, this.namespace = r, u(this, fs, a);
3466
+ }
3467
+ static subscribe(t, e, n) {
3468
+ return h(this, null, function* () {
3469
+ if (!Pc(e))
3470
+ throw new Error("track object language is required");
3471
+ const r = new Rt().name(e.name).build(), a = yield Ht.subscribe(t, r), c = a.objects();
3472
+ return new Wr(a, c, e, t.namespace(), n);
3473
+ });
3474
+ }
3475
+ largestGroupId() {
3476
+ return s(this, $t).largestGroupId();
3477
+ }
3478
+ update(t, e) {
3479
+ return s(this, $t).update(t, e);
3480
+ }
3481
+ unsubscribe() {
3482
+ return s(this, $t).unsubscribe();
3483
+ }
3484
+ next() {
3485
+ return h(this, null, function* () {
3486
+ for (; ; ) {
3487
+ const t = yield s(this, Fi).next();
3488
+ if (t.done)
3489
+ return t;
3490
+ if (t.value.objectStatus !== $.Normal)
3491
+ continue;
3492
+ const e = new TextDecoder().decode(t.value.payload), n = s(this, Jn).parse(e).map((a) => (a.startTime -= s(this, fs) / 1e3, a.endTime -= s(this, fs) / 1e3, a));
3493
+ return {
3494
+ done: !1,
3495
+ value: { language: this.trackObject.language, cues: n }
3496
+ };
3497
+ }
3498
+ });
3499
+ }
3500
+ return() {
3501
+ return h(this, null, function* () {
3502
+ return yield s(this, $t).return(), { done: !0, value: void 0 };
3503
+ });
3504
+ }
3505
+ [Symbol.asyncIterator]() {
3506
+ return this;
3507
+ }
3508
+ [Oe()]() {
3509
+ return this.unsubscribe();
3510
+ }
3511
+ [Symbol.asyncDispose]() {
3512
+ return this.unsubscribe();
3513
+ }
3514
+ };
3515
+ Jn = new WeakMap(), Fi = new WeakMap(), $t = new WeakMap(), fs = new WeakMap();
3516
+ let Ar = Wr;
3517
+ var ga, ge, ve, ws, zt, lr, ps, cn;
3518
+ ga = [_({ context: "Channel", enter: "info" })];
3519
+ const Ge = class Ge {
3520
+ constructor(t, e, n, r, a) {
3521
+ o(this, ps);
3522
+ l(this, "namespace");
3523
+ o(this, ge);
3524
+ o(this, ve);
3525
+ o(this, ws);
3526
+ o(this, zt);
3527
+ this.namespace = r, u(this, ge, t), u(this, ve, e), u(this, ws, n), u(this, zt, a);
3528
+ }
3529
+ static start(t, e) {
3530
+ return h(this, null, function* () {
3531
+ const n = new co(t, { namespace: e.namespace }), [r, a] = yield Promise.all([
3532
+ Er.start(n, "timeline"),
3533
+ Sr.start(n, { catalog: e.catalog, namespace: e.namespace })
3534
+ ]);
3535
+ return new Ge(n, r, a, e.namespace, 0);
3536
+ });
3537
+ }
3538
+ catalog() {
3539
+ return s(this, ws).catalog();
3540
+ }
3541
+ timestampWallclockOffset() {
3542
+ return s(this, ve).timestampWallclockOffset();
3543
+ }
3544
+ timestampOffsetMs() {
3545
+ return s(this, zt);
3546
+ }
3547
+ setTimestampOffsetMs(t) {
3548
+ u(this, zt, t);
3549
+ }
3550
+ waitForWallclockTime(t) {
3551
+ return s(this, ve).waitForWallclockTime(t);
3552
+ }
3553
+ subscribeCmafTrack(t, e) {
3554
+ const r = this.catalog().current().tracks.find(
3555
+ (a) => a["com.vindral.variant_uid"] === t["com.vindral.variant_uid"]
3556
+ );
3557
+ return w(this, ps, cn).call(this, () => Tr.subscribe(s(this, ge), r != null ? r : t, s(this, zt), e));
3558
+ }
3559
+ subscribeWebVttTrack(t) {
3560
+ return w(this, ps, cn).call(this, () => Ar.subscribe(s(this, ge), t, s(this, zt)));
3561
+ }
3562
+ subscribeTrack(t) {
3563
+ return w(this, ps, cn).call(this, () => s(this, ge).subscribe(t));
3564
+ }
3565
+ /**
3566
+ * Closes the channel subscriptions
3567
+ */
3568
+ close() {
3569
+ return Promise.all([s(this, ws).close(), s(this, ve).close()]);
3570
+ }
3571
+ };
3572
+ lr = Ve(null), ge = new WeakMap(), ve = new WeakMap(), ws = new WeakMap(), zt = new WeakMap(), ps = new WeakSet(), cn = function(t) {
3573
+ return h(this, null, function* () {
3574
+ const [e, n] = this.catalog().value();
3575
+ try {
3576
+ return yield t();
3577
+ } catch (r) {
3578
+ if (e === this.catalog().current() && n && (yield Promise.race([n, er(500)])), e !== this.catalog().current())
3579
+ return t();
3580
+ throw r;
3581
+ }
3582
+ });
3583
+ }, X(lr, 9, "start", ga, Ge), Jt(lr, Ge), Ce(lr, 3, Ge);
3584
+ let Bn = Ge;
3585
+ var ke, Wi, Kn, wo;
3586
+ const $r = class $r {
3587
+ constructor(t) {
3588
+ o(this, Kn);
3589
+ o(this, ke);
3590
+ o(this, Wi);
3591
+ const [e, n] = t.value.value();
3592
+ u(this, ke, {
3593
+ createdAt: /* @__PURE__ */ new Date(),
3594
+ wallclock: new Date(e.ntpTimestamp),
3595
+ rtt: e.rtt
3596
+ }), u(this, Wi, w(this, Kn, wo).call(this, t));
3597
+ }
3598
+ /**
3599
+ * @returns returns the current wallclock time in milliseconds based on the ntp timestamp of the stats track + the elapsed time since the last stats track.
3600
+ */
3601
+ wallclock() {
3602
+ const e = Date.now() - s(this, ke).createdAt.getTime();
3603
+ return s(this, ke).wallclock.getTime() + e;
3604
+ }
3605
+ closed() {
3606
+ return s(this, Wi);
3607
+ }
3608
+ static start(t) {
3609
+ return new $r(t);
3610
+ }
3611
+ };
3612
+ ke = new WeakMap(), Wi = new WeakMap(), Kn = new WeakSet(), wo = function(t) {
3613
+ return h(this, null, function* () {
3614
+ try {
3615
+ for (var e = C(t.value), n, r, a; n = !(r = yield e.next()).done; n = !1) {
3616
+ const c = r.value;
3617
+ u(this, ke, {
3618
+ createdAt: /* @__PURE__ */ new Date(),
3619
+ wallclock: new Date(c.ntpTimestamp),
3620
+ rtt: c.rtt
3621
+ });
3622
+ }
3623
+ } catch (r) {
3624
+ a = [r];
3625
+ } finally {
3626
+ try {
3627
+ n && (r = e.return) && (yield r.call(e));
3628
+ } finally {
3629
+ if (a)
3630
+ throw a[0];
3631
+ }
3632
+ }
3633
+ });
3634
+ };
3635
+ let Or = $r;
3636
+ function tn(i) {
3637
+ return typeof i == "string" || i === null || i === void 0;
3638
+ }
3639
+ function Rc(i) {
3640
+ return "provider" in i && typeof i.provider == "string" && (!("widevineLicenseUrl" in i) || tn(i.widevineLicenseUrl)) && (!("playreadyLicenseUrl" in i) || tn(i.playreadyLicenseUrl)) && (!("fairplayLicenseUrl" in i) || tn(i.fairplayLicenseUrl)) && (!("fairplayCertificate" in i) || tn(i.fairplayCertificate));
3641
+ }
3642
+ function Lc(i) {
3643
+ try {
3644
+ return ho(i);
3645
+ } catch (t) {
3646
+ throw new Error("Failed to convert fairplayCertificate");
3647
+ }
3648
+ }
3649
+ function jc(i) {
3650
+ const t = new TextDecoder().decode(i), e = JSON.parse(t);
3651
+ if (!Rc(e))
3652
+ throw new Error("Invalid drm object");
3653
+ const a = e, { fairplayCertificate: n } = a, r = Qr(a, ["fairplayCertificate"]);
3654
+ return rr(Yt({}, r), {
3655
+ fairplayCertificate: n ? Lc(n) : void 0
3656
+ });
3657
+ }
3658
+ class jr {
3659
+ constructor(t) {
3660
+ l(this, "value");
3661
+ this.value = t;
3662
+ }
3663
+ static create(t) {
3664
+ return h(this, null, function* () {
3665
+ var c = [];
3666
+ try {
3667
+ const e = mt(c, yield t.subscribeTrack(new Rt().name("drm").build()), !0);
3668
+ const n = e.objects();
3669
+ const r = yield n.next();
3670
+ if (r.done)
3671
+ throw new Error("No drm object received");
3672
+ const a = jc(r.value.payload);
3673
+ return new jr(a);
3674
+ } catch (d) {
3675
+ var f = d, p = !0;
3676
+ } finally {
3677
+ var b = bt(c, f, p);
3678
+ b && (yield b);
3679
+ }
3680
+ });
3681
+ }
3682
+ }
3683
+ function Gc(i) {
3684
+ return "rtt" in i && typeof i.rtt == "number" && "ntpTimestamp" in i && typeof i.ntpTimestamp == "number" && "estimatedBandwidth" in i && typeof i.estimatedBandwidth == "number";
3685
+ }
3686
+ function aa(i) {
3687
+ const t = new TextDecoder().decode(i), e = JSON.parse(t);
3688
+ if (!Gc(e))
3689
+ throw new Error("Invalid stats object");
3690
+ return e;
3691
+ }
3692
+ const Nc = 1e4;
3693
+ var $i, Qn, po;
3694
+ const zr = class zr {
3695
+ constructor(t, e, n) {
3696
+ o(this, Qn);
3697
+ l(this, "ip");
3698
+ l(this, "value");
3699
+ o(this, $i);
3700
+ this.ip = n, this.value = new ft(e), u(this, $i, w(this, Qn, po).call(this, t));
3701
+ }
3702
+ closed() {
3703
+ return s(this, $i);
3704
+ }
3705
+ idleTimeout() {
3706
+ return h(this, null, function* () {
3707
+ for (; ; ) {
3708
+ const [t, e] = this.value.value();
3709
+ try {
3710
+ yield Promise.race([Co(Nc, new Error("Idle timeout")), e]);
3711
+ } catch (n) {
3712
+ return n;
3713
+ }
3714
+ }
3715
+ });
3716
+ }
3717
+ static start(t) {
3718
+ return h(this, null, function* () {
3719
+ const n = (yield t.subscribe(new Rt().name("stats").groupOrder("ascending").build())).objects(), r = yield n.next();
3720
+ if (r.done)
3721
+ throw new Error("No stats object received");
3722
+ const a = aa(r.value.payload);
3723
+ if (!a.ip)
3724
+ throw new Error("Expected IP in initial stats object");
3725
+ return new zr(n, a, a.ip);
3726
+ });
3727
+ }
3728
+ };
3729
+ $i = new WeakMap(), Qn = new WeakSet(), po = function(t) {
3730
+ return h(this, null, function* () {
3731
+ try {
3732
+ for (var e = C(t), n, r, a; n = !(r = yield e.next()).done; n = !1) {
3733
+ const c = r.value;
3734
+ if (c.objectStatus !== $.Normal)
3735
+ continue;
3736
+ const d = aa(c.payload);
3737
+ this.value.update(d);
3738
+ }
3739
+ } catch (r) {
3740
+ a = [r];
3741
+ } finally {
3742
+ try {
3743
+ n && (r = e.return) && (yield r.call(e));
3744
+ } finally {
3745
+ if (a)
3746
+ throw a[0];
3747
+ }
3748
+ }
3749
+ });
3750
+ };
3751
+ let Vr = zr;
3752
+ var ms, zi, Mi;
3753
+ class ur {
3754
+ constructor(t, e) {
3755
+ o(this, ms, Xt.get().createContext("TracksIterator"));
3756
+ o(this, zi);
3757
+ o(this, Mi);
3758
+ u(this, zi, t), u(this, Mi, e);
3759
+ }
3760
+ [Symbol.asyncIterator]() {
3761
+ return Dt(this, null, function* () {
3762
+ const t = s(this, Mi);
3763
+ try {
3764
+ for (var e = C(s(this, zi)), n, r, a; n = !(r = yield new A(e.next())).done; n = !1) {
3765
+ const c = r.value;
3766
+ if (!c)
3767
+ continue;
3768
+ const d = {
3769
+ name: c.trackObject.name,
3770
+ namespace: c.namespace
3771
+ };
3772
+ s(this, ms).debug("track start", Yt({ mediaType: t }, d)), yield* or(c), s(this, ms).debug("track end", Yt({ mediaType: t }, d));
3773
+ }
3774
+ } catch (r) {
3775
+ a = [r];
3776
+ } finally {
3777
+ try {
3778
+ n && (r = e.return) && (yield new A(r.call(e)));
3779
+ } finally {
3780
+ if (a)
3781
+ throw a[0];
3782
+ }
3783
+ }
3784
+ s(this, ms).debug("tracks ended", { mediaType: t });
3785
+ });
3786
+ }
3787
+ }
3788
+ ms = new WeakMap(), zi = new WeakMap(), Mi = new WeakMap();
3789
+ var va, ka, Ia, bs, ys, Ie, G, lt, dt, Mt, Hi, Os, z, un, Ps, mo, Br;
3790
+ Ia = [_({ context: "Player", enter: "info" })], ka = [_({ context: "Player", enter: "info", return: "info" })], va = [_({ context: "Player", enter: "info" })];
3791
+ const Ne = class Ne {
3792
+ constructor(t, e, n) {
3793
+ Ce(Os, 5, this);
3794
+ o(this, z);
3795
+ o(this, bs);
3796
+ o(this, ys);
3797
+ o(this, Ie);
3798
+ o(this, G);
3799
+ o(this, lt, new ft(void 0));
3800
+ o(this, dt, new ft(void 0));
3801
+ o(this, Mt, new ft(void 0));
3802
+ o(this, Hi);
3803
+ l(this, "subtitles", new ur(s(this, Mt), "subtitles"));
3804
+ l(this, "video", new ur(s(this, dt), "video"));
3805
+ l(this, "audio", new ur(s(this, lt), "audio"));
3806
+ u(this, bs, t), u(this, ys, Or.start(n)), u(this, Ie, n), u(this, G, new ft(e)), u(this, Hi, Promise.race([n.idleTimeout(), w(this, z, mo).call(this)])), s(this, bs).closed().then(() => this.close()).catch(B);
3807
+ }
3808
+ closed() {
3809
+ return s(this, Hi);
3810
+ }
3811
+ static start(t, e) {
3812
+ return h(this, null, function* () {
3813
+ const n = e.namespace, r = new co(t, { namespace: n }), [[a, c, d], f] = yield Promise.all([
3814
+ Bn.start(t, e).then((b) => Promise.all([
3815
+ Promise.resolve(b),
3816
+ e.videoTrack ? b.subscribeCmafTrack(e.videoTrack) : void 0,
3817
+ e.audioTrack ? b.subscribeCmafTrack(e.audioTrack) : void 0
3818
+ ])),
3819
+ Vr.start(r)
3820
+ ]), p = new Ne(t, a, f);
3821
+ return d && s(p, lt).update(d), c && s(p, dt).update(c), p;
3822
+ });
3823
+ }
3824
+ connectionInfo() {
3825
+ const t = s(this, Ie).value.current();
3826
+ return {
3827
+ ip: s(this, Ie).ip,
3828
+ rtt: t.rtt,
3829
+ estimatedBandwidth: t.estimatedBandwidth
3830
+ };
3831
+ }
3832
+ stats() {
3833
+ return s(this, Ie).value;
3834
+ }
3835
+ catalog() {
3836
+ return s(this, G).current().catalog();
3837
+ }
3838
+ namespace() {
3839
+ return s(this, G).current().namespace;
3840
+ }
3841
+ videoTrack() {
3842
+ var t;
3843
+ return (t = s(this, dt).current()) == null ? void 0 : t.trackObject;
3844
+ }
3845
+ audioTrack() {
3846
+ var t;
3847
+ return (t = s(this, lt).current()) == null ? void 0 : t.trackObject;
3848
+ }
3849
+ referenceClock() {
3850
+ return s(this, ys);
3851
+ }
3852
+ drm() {
3853
+ return h(this, null, function* () {
3854
+ return jr.create(s(this, G).current()).catch(B);
3855
+ });
3856
+ }
3857
+ close() {
3858
+ return Promise.all([
3859
+ // Close the channel subscription
3860
+ s(this, G).current().close(),
3861
+ // Close the channel ObservableValue
3862
+ s(this, G).close(),
3863
+ // Close the consumers so that the iterators will stop
3864
+ w(this, z, un).call(this, s(this, lt)),
3865
+ w(this, z, un).call(this, s(this, dt)),
3866
+ w(this, z, un).call(this, s(this, Mt))
3867
+ ]);
3868
+ }
3869
+ zap(t, e) {
3870
+ return h(this, null, function* () {
3871
+ var P, H;
3872
+ const n = yield Bn.start(s(this, bs), t), r = s(this, ys).wallclock() - e, a = s(this, G).current(), c = a.timestampWallclockOffset(), [d, f] = yield Promise.all([
3873
+ n.waitForWallclockTime(r),
3874
+ s(this, G).current().close()
3875
+ ]), p = d.toReversed().find((T) => T.wallclock <= r), b = p != null && p.mediaPts ? p.mediaPts - a.timestampOffsetMs() : void 0, y = n.timestampWallclockOffset() - c + a.timestampOffsetMs();
3876
+ n.setTimestampOffsetMs(y);
3877
+ const E = p != null && p.groupId ? k(p.groupId) : void 0;
3878
+ b && ((P = s(this, dt).current()) == null || P.stopAfterTimestampReached(b), (H = s(this, lt).current()) == null || H.stopAfterTimestampReached(b)), s(this, G).update(n), yield Promise.all([
3879
+ t.videoTrack ? this.setVideoTrack(t.videoTrack, E) : void 0,
3880
+ t.audioTrack ? this.setAudioTrack(t.audioTrack, E) : void 0
3881
+ ]);
3882
+ });
3883
+ }
3884
+ setSubtitleTrack(t) {
3885
+ return h(this, null, function* () {
3886
+ var n, r;
3887
+ if (!t) {
3888
+ yield (n = s(this, Mt).current()) == null ? void 0 : n.unsubscribe();
3889
+ return;
3890
+ }
3891
+ const [e] = yield Promise.all([
3892
+ s(this, G).current().subscribeWebVttTrack(t),
3893
+ (r = s(this, Mt).current()) == null ? void 0 : r.unsubscribe()
3894
+ ]);
3895
+ s(this, Mt).update(e);
3896
+ });
3897
+ }
3898
+ setVideoTrack(t, e) {
3899
+ return h(this, null, function* () {
3900
+ const n = yield w(this, z, Ps).call(this, s(this, G).current(), t, s(this, dt).current(), e);
3901
+ s(this, dt).update(n);
3902
+ });
3903
+ }
3904
+ setAudioTrack(t, e) {
3905
+ return h(this, null, function* () {
3906
+ const n = yield w(this, z, Ps).call(this, s(this, G).current(), t, s(this, lt).current(), e);
3907
+ s(this, lt).update(n);
3908
+ });
3909
+ }
3910
+ };
3911
+ Os = Ve(null), bs = new WeakMap(), ys = new WeakMap(), Ie = new WeakMap(), G = new WeakMap(), lt = new WeakMap(), dt = new WeakMap(), Mt = new WeakMap(), Hi = new WeakMap(), z = new WeakSet(), un = function(t) {
3912
+ const e = t.current(), n = e == null ? void 0 : e.largestGroupId();
3913
+ return t.isClosed() || t.update(void 0), t.close(), n ? e == null ? void 0 : e.update(n, n) : e == null ? void 0 : e.unsubscribe();
3914
+ }, Ps = function(t, e, n, r) {
3915
+ return h(this, null, function* () {
3916
+ const a = n == null ? void 0 : n.largestGroupId(), [c, d] = yield Promise.all([
3917
+ t.subscribeCmafTrack(
3918
+ e,
3919
+ r || (a ? a + k(1) : void 0)
3920
+ ),
3921
+ a ? n == null ? void 0 : n.update(a, a) : n == null ? void 0 : n.unsubscribe()
3922
+ ]);
3923
+ return c;
3924
+ });
3925
+ }, mo = function() {
3926
+ return h(this, null, function* () {
3927
+ try {
3928
+ for (var a = C(s(this, G)), c, d, f; c = !(d = yield a.next()).done; c = !1) {
3929
+ const p = d.value;
3930
+ try {
3931
+ for (var t = C(p.catalog()), e, n, r; e = !(n = yield t.next()).done; e = !1) {
3932
+ const b = n.value;
3933
+ yield Promise.all([
3934
+ w(this, z, Br).call(this, b, s(this, dt)),
3935
+ w(this, z, Br).call(this, b, s(this, lt))
3936
+ ]);
3937
+ }
3938
+ } catch (n) {
3939
+ r = [n];
3940
+ } finally {
3941
+ try {
3942
+ e && (n = t.return) && (yield n.call(t));
3943
+ } finally {
3944
+ if (r)
3945
+ throw r[0];
3946
+ }
3947
+ }
3948
+ }
3949
+ } catch (d) {
3950
+ f = [d];
3951
+ } finally {
3952
+ try {
3953
+ c && (d = a.return) && (yield d.call(a));
3954
+ } finally {
3955
+ if (f)
3956
+ throw f[0];
3957
+ }
3958
+ }
3959
+ });
3960
+ }, Br = function(t, e) {
3961
+ return h(this, null, function* () {
3962
+ const n = e.current();
3963
+ if (!n)
3964
+ return;
3965
+ const r = n.trackObject.name, a = n.trackObject["com.vindral.variant_uid"], c = t.tracks.find((f) => f.name === r), d = t.tracks.find((f) => f["com.vindral.variant_uid"] === a);
3966
+ if (!c) {
3967
+ if (!d) {
3968
+ e.update(void 0);
3969
+ return;
3970
+ }
3971
+ e.update(yield s(this, G).current().subscribeCmafTrack(d));
3972
+ }
3973
+ });
3974
+ }, X(Os, 1, "close", Ia, Ne), X(Os, 1, "zap", ka, Ne), Ps = X(Os, 17, "#replaceTrack", va, z, Ps), Jt(Os, Ne);
3975
+ let Cr = Ne;
3976
+ function Fc(i, t, e) {
3977
+ const n = new URL("/voq/subscribe", typeof i == "string" ? i : i.moqUrl || i.moqWsUrl);
3978
+ return n.searchParams.set("sessionId", t.sessionId), n.searchParams.set("clientId", t.clientId), n.searchParams.set("channelId", t.channelId), e && n.searchParams.set("authToken", e), n;
3979
+ }
3980
+ var N, F, nt, Se, gs, vs, V, Ue, Xi, qn, ks, tt, bo, Is, Zi, Ss, yo, go, vo, xr;
3981
+ const Mr = class Mr {
3982
+ constructor(t, e, n, r, a) {
3983
+ o(this, tt);
3984
+ o(this, N);
3985
+ o(this, F);
3986
+ o(this, nt);
3987
+ o(this, Se, "disconnected");
3988
+ o(this, gs);
3989
+ o(this, vs);
3990
+ o(this, V);
3991
+ o(this, Ue, /* @__PURE__ */ new Map());
3992
+ o(this, Xi, new Pr(10));
3993
+ o(this, qn, Number.MAX_SAFE_INTEGER);
3994
+ o(this, ks, /* @__PURE__ */ new Map());
3995
+ o(this, Is, (t) => {
3996
+ if (!t) {
3997
+ s(this, V).setSubtitleTrack(void 0).catch(B);
3998
+ return;
3999
+ }
4000
+ const e = s(this, Ue).get(Kt(s(this, V).namespace())), n = e == null ? void 0 : e.getTextTrack(t);
4001
+ n && s(this, V).setSubtitleTrack(n).catch(B);
4002
+ });
4003
+ o(this, Zi, (t) => {
4004
+ switch (t.type) {
4005
+ case "subscribe":
4006
+ {
4007
+ if (s(this, Ss)) {
4008
+ s(this, F).info("Ignoring - we are already switching");
4009
+ return;
4010
+ }
4011
+ u(this, Ss, !0), w(this, tt, yo).call(this, t.subscription).catch((e) => s(this, F).error("error handling subscription", e)).finally(() => u(this, Ss, !1));
4012
+ }
4013
+ break;
4014
+ case "telemetry":
4015
+ Ro(new URL("/api/telemetry", s(this, nt).url().replace("wss://", "https://")), {
4016
+ body: t.body,
4017
+ headers: { "Content-Type": "text/plain" }
4018
+ }).catch(B);
4019
+ break;
4020
+ case "refresh auth":
4021
+ s(this, nt).updateAuthToken(t.token);
4022
+ break;
4023
+ }
4024
+ });
4025
+ o(this, Ss, !1);
4026
+ l(this, "disconnect", (t = "Disconnect Requested") => {
4027
+ s(this, F).info("Disconnecting", t), s(this, nt).close(), s(this, V).close().catch(B), u(this, ks, /* @__PURE__ */ new Map()), u(this, Se, "disconnected");
4028
+ });
4029
+ u(this, N, t), u(this, F, e), u(this, nt, n), u(this, V, r), u(this, Ue, a), s(this, N).on("send signal", s(this, Zi)), s(this, N).on("disconnect", this.disconnect), s(this, N).on("text track", s(this, Is)), w(this, tt, bo).call(this).catch(B), w(this, tt, go).call(this).catch(B);
4030
+ }
4031
+ get estimatedBandwidth() {
4032
+ return s(this, qn);
4033
+ }
4034
+ get firstConnectionTime() {
4035
+ return s(this, gs);
4036
+ }
4037
+ get lastConnectionTime() {
4038
+ return s(this, vs);
4039
+ }
4040
+ unload() {
4041
+ s(this, N).off("send signal", s(this, Zi)), s(this, N).off("disconnect", this.disconnect), s(this, N).off("text track", s(this, Is)), this.disconnect();
4042
+ }
4043
+ suspend() {
4044
+ }
4045
+ unsuspend() {
4046
+ }
4047
+ getStatistics() {
4048
+ const e = s(this, V).connectionInfo().estimatedBandwidth;
4049
+ return {
4050
+ rtt: Bo(s(this, Xi).items()),
4051
+ estimatedBandwidth: e,
4052
+ connectCount: 0,
4053
+ connectionAttemptCount: 0,
4054
+ edgeUrl: s(this, nt).url(),
4055
+ connectionProtocol: "moq"
4056
+ };
4057
+ }
4058
+ static start(t, e, n) {
4059
+ return h(this, null, function* () {
4060
+ var E, P, H, T;
4061
+ const r = new Map(
4062
+ n.connectInfo.channels.map((g) => [
4063
+ Kt(g.catalog.namespace),
4064
+ new ca(new ft(g.catalog))
4065
+ ])
4066
+ ), a = yield n.onConnectInfo(n.connectInfo), c = Fc(n.edgeUrl, a, n.options.options.authenticationToken), d = (E = n.connectInfo.channels.find((g) => g.channelId === a.channelId)) == null ? void 0 : E.catalog;
4067
+ e.debug("Resolved edge url", { edgeUrl: c }), Sa(d, "no catalog found");
4068
+ const f = (P = r.get(Kt(d.namespace))) == null ? void 0 : P.getVideoTrack(a.video), p = (H = r.get(Kt(d.namespace))) == null ? void 0 : H.getAudioTrack(a.audio), b = yield Dc({
4069
+ url: new URL(c),
4070
+ handshakePipelining: !0,
4071
+ authToken: n.options.get("authenticationToken")
4072
+ }), m = yield Cr.start(b, {
4073
+ namespace: d.namespace,
4074
+ catalog: d,
4075
+ videoTrack: f == null ? void 0 : f.track,
4076
+ audioTrack: p == null ? void 0 : p.track
4077
+ }), I = new ca(m.catalog());
4078
+ r.set(Kt(d.namespace), I), t.emit("received signal", {
4079
+ type: "client ip",
4080
+ ip: m.connectionInfo().ip
4081
+ }), m.drm().then((g) => {
4082
+ g && t.emit("received drm data", g.value);
4083
+ });
4084
+ const y = new Mr(t, e, b, m, r);
4085
+ return a.textTrack && s(T = y, Is).call(T, a.textTrack), y;
4086
+ });
4087
+ }
4088
+ getState() {
4089
+ return s(this, Se);
4090
+ }
4091
+ get rtt() {
4092
+ var t;
4093
+ return (t = s(this, V)) == null ? void 0 : t.connectionInfo().rtt;
4094
+ }
4095
+ close() {
4096
+ var t;
4097
+ (t = s(this, nt)) == null || t.close();
4098
+ }
4099
+ closed() {
4100
+ var t;
4101
+ return (t = s(this, nt)) == null ? void 0 : t.closed();
4102
+ }
4103
+ };
4104
+ N = new WeakMap(), F = new WeakMap(), nt = new WeakMap(), Se = new WeakMap(), gs = new WeakMap(), vs = new WeakMap(), V = new WeakMap(), Ue = new WeakMap(), Xi = new WeakMap(), qn = new WeakMap(), ks = new WeakMap(), tt = new WeakSet(), bo = function() {
4105
+ return h(this, null, function* () {
4106
+ try {
4107
+ for (var t = C(s(this, V).stats()), e, n, r; e = !(n = yield t.next()).done; e = !1) {
4108
+ const { rtt: a } = n.value;
4109
+ s(this, Xi).push(a);
4110
+ }
4111
+ } catch (n) {
4112
+ r = [n];
4113
+ } finally {
4114
+ try {
4115
+ e && (n = t.return) && (yield n.call(t));
4116
+ } finally {
4117
+ if (r)
4118
+ throw r[0];
4119
+ }
4120
+ }
4121
+ });
4122
+ }, Is = new WeakMap(), Zi = new WeakMap(), Ss = new WeakMap(), yo = function(t) {
4123
+ return h(this, null, function* () {
4124
+ var d, f, p, b, m, I, y;
4125
+ s(this, F).info("handle subscription", t);
4126
+ const e = s(this, V), n = s(this, nt);
4127
+ if (!e) {
4128
+ s(this, F).info("no player");
4129
+ return;
4130
+ }
4131
+ if (!n) {
4132
+ s(this, F).info("no session");
4133
+ return;
4134
+ }
4135
+ const r = s(this, Ue).get(t.channelId);
4136
+ if (!r) {
4137
+ s(this, F).info("no catalog for ", t.channelId);
4138
+ return;
4139
+ }
4140
+ if (e.namespace().join("/") !== r.namespace().join("/")) {
4141
+ s(this, F).info("changing channel", t.channelId);
4142
+ const E = r.getVideoTrack(t.video), P = r.getAudioTrack(t.audio);
4143
+ yield e.zap(
4144
+ {
4145
+ namespace: r.namespace(),
4146
+ catalog: r.catalog(),
4147
+ videoTrack: E == null ? void 0 : E.track,
4148
+ audioTrack: P == null ? void 0 : P.track
4149
+ },
4150
+ 500
4151
+ ), s(this, F).info("switched channel", t.channelId), (d = s(this, Ue).get(Kt(e.namespace()))) == null || d.updateCatalog(e.catalog()), s(this, N).emit("received signal", {
4152
+ type: "subscription changed",
4153
+ subscription: t
4154
+ });
4155
+ return;
4156
+ }
4157
+ const a = r.getVideoTrack(t.video), c = r.getAudioTrack(t.audio);
4158
+ yield Promise.all([
4159
+ a && a.track.name !== ((p = (f = s(this, V)) == null ? void 0 : f.videoTrack()) == null ? void 0 : p.name) ? (b = s(this, V)) == null ? void 0 : b.setVideoTrack(a.track) : void 0,
4160
+ c && c.track.name !== ((I = (m = s(this, V)) == null ? void 0 : m.audioTrack()) == null ? void 0 : I.name) ? (y = s(this, V)) == null ? void 0 : y.setAudioTrack(c.track) : void 0
4161
+ ]), s(this, N).emit("received signal", {
4162
+ type: "subscription changed",
4163
+ subscription: t
4164
+ });
4165
+ });
4166
+ }, go = function() {
4167
+ return h(this, null, function* () {
4168
+ try {
4169
+ u(this, Se, "connecting"), s(this, F).info("Connecting..."), u(this, vs, Date.now()), s(this, gs) || u(this, gs, s(this, vs)), u(this, Se, "connected"), yield Promise.all([
4170
+ w(this, tt, xr).call(this, s(this, V).referenceClock(), s(this, V).audio),
4171
+ w(this, tt, xr).call(this, s(this, V).referenceClock(), s(this, V).video),
4172
+ w(this, tt, vo).call(this, s(this, V).subtitles)
4173
+ ]), yield s(this, V).closed(), s(this, nt).close(), s(this, F).info("Session closed");
4174
+ } catch (t) {
4175
+ s(this, F).warn("Session error", t);
4176
+ }
4177
+ });
4178
+ }, vo = function(t) {
4179
+ return h(this, null, function* () {
4180
+ try {
4181
+ for (var e = C(t), n, r, a; n = !(r = yield e.next()).done; n = !1) {
4182
+ const c = r.value;
4183
+ s(this, N).emit("text track data", c);
4184
+ }
4185
+ } catch (r) {
4186
+ a = [r];
4187
+ } finally {
4188
+ try {
4189
+ n && (r = e.return) && (yield r.call(e));
4190
+ } finally {
4191
+ if (a)
4192
+ throw a[0];
4193
+ }
4194
+ }
4195
+ });
4196
+ }, xr = function(t, e) {
4197
+ return h(this, null, function* () {
4198
+ let n = "", r = "";
4199
+ try {
4200
+ for (var p = C(e), b, m, I; b = !(m = yield p.next()).done; b = !1) {
4201
+ const y = m.value;
4202
+ const E = Kt(y.track.namespace), P = y.track.trackObject.language;
4203
+ try {
4204
+ for (var a = C(y), c, d, f; c = !(d = yield a.next()).done; c = !1) {
4205
+ const [H, T] = d.value;
4206
+ n !== "" && n !== E && T.mediaType() === "video" && s(this, N).emit("add event", {
4207
+ type: "channel switch",
4208
+ channelId: E,
4209
+ timestamp: T.baseMediaDecodeTime() / T.timescale() * 1e3
4210
+ }), n = E, r !== "" && P && r !== P && T.mediaType() === "audio" && s(this, N).emit("add event", {
4211
+ type: "language switch",
4212
+ language: P,
4213
+ timestamp: T.baseMediaDecodeTime() / T.timescale() * 1e3
4214
+ }), r = P;
4215
+ const g = T.producerReferenceTime(), Y = s(this, ks).get(y.track.namespace) || 0;
4216
+ if (g && Date.now() - Y > 1e3) {
4217
+ s(this, ks).set(y.track.namespace, Date.now());
4218
+ const S = t.wallclock() - g.getTime();
4219
+ s(this, F).info("ti", {
4220
+ medaiType: T.mediaType(),
4221
+ referenceClock: t,
4222
+ delta: S,
4223
+ groupId: H,
4224
+ timestamp: T.baseMediaDecodeTime() / T.timescale() * 1e3 + S,
4225
+ wallclockTime: g.getTime()
4226
+ }), s(this, N).emit("received signal", {
4227
+ type: "timing info",
4228
+ timingInfo: {
4229
+ channelId: E,
4230
+ timestamp: T.baseMediaDecodeTime() / T.timescale() * 1e3 + S,
4231
+ wallclockTime: g.getTime()
4232
+ }
4233
+ });
4234
+ }
4235
+ s(this, N).emit("received moq data", {
4236
+ payload: T,
4237
+ channelId: E,
4238
+ groupId: H,
4239
+ // FIXME: We should replace this with something better than hashing the track name
4240
+ renditionId: Wc(y.track.trackObject.name)
4241
+ });
4242
+ }
4243
+ } catch (d) {
4244
+ f = [d];
4245
+ } finally {
4246
+ try {
4247
+ c && (d = a.return) && (yield d.call(a));
4248
+ } finally {
4249
+ if (f)
4250
+ throw f[0];
4251
+ }
4252
+ }
4253
+ }
4254
+ } catch (m) {
4255
+ I = [m];
4256
+ } finally {
4257
+ try {
4258
+ b && (m = p.return) && (yield m.call(p));
4259
+ } finally {
4260
+ if (I)
4261
+ throw I[0];
4262
+ }
4263
+ }
4264
+ });
4265
+ };
4266
+ let oa = Mr;
4267
+ function Wc(i) {
4268
+ return i.split("").reduce(
4269
+ (e, n) => e = n.charCodeAt(0) + (e << 6) + (e << 16) - e,
4270
+ 0
4271
+ );
4272
+ }
4273
+ var Pt, Te, _n, ko;
4274
+ class ca {
4275
+ constructor(t) {
4276
+ o(this, _n);
4277
+ o(this, Pt);
4278
+ o(this, Te);
4279
+ u(this, Pt, t), u(this, Te, w(this, _n, ko).call(this));
4280
+ }
4281
+ catalog() {
4282
+ return s(this, Pt).current();
4283
+ }
4284
+ namespace() {
4285
+ return s(this, Pt).current().namespace;
4286
+ }
4287
+ updateCatalog(t) {
4288
+ u(this, Pt, t);
4289
+ }
4290
+ getTextTrack(t) {
4291
+ return s(this, Pt).current().tracks.find((e) => e.label === t);
4292
+ }
4293
+ getAudioTrack(t) {
4294
+ return t.codec ? s(this, Te).filter((n) => !(!xo(n) || n.bitRate > t.bitRate || t.codec && n.codec !== t.codec || t.language && n.language !== t.language)).at(-1) : void 0;
4295
+ }
4296
+ getVideoTrack(t) {
4297
+ return t.codec ? s(this, Te).filter((n) => !(!Po(n) || n.bitRate > t.bitRate || t.codec && n.codec !== t.codec)).at(-1) : void 0;
4298
+ }
4299
+ renditions() {
4300
+ return s(this, Te);
4301
+ }
4302
+ }
4303
+ Pt = new WeakMap(), Te = new WeakMap(), _n = new WeakSet(), ko = function() {
4304
+ const [t, e] = s(this, Pt).value();
4305
+ return Lo(t);
4306
+ };
4307
+ export {
4308
+ ca as CatalogObserver,
4309
+ oa as MoqConnectionAdapter
4310
+ };