@ikonai/sdk 0.0.41 → 0.0.43

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.
@@ -0,0 +1,924 @@
1
+ function J(t) {
2
+ const r = O(t), e = new DataView(r.buffer, r.byteOffset, r.byteLength);
3
+ if (r.length < 27)
4
+ throw new Error("Protocol payload too short");
5
+ const n = e.getUint32(0, !0), s = e.getUint32(4, !0), E = e.getUint32(8, !0), _ = e.getUint32(12, !0), I = e.getUint32(16, !0), f = e.getUint32(20, !0), q = e.getUint8(24), j = e.getUint8(25), Q = e.getUint8(26);
6
+ if (27 + f * 4 > r.length)
7
+ throw new Error("Protocol header exceeds payload length");
8
+ const G = [];
9
+ let B = 27;
10
+ for (let b = 0; b < f; b++)
11
+ G.push(e.getUint32(B, !0)), B += 4;
12
+ return {
13
+ length: n,
14
+ opcode: s,
15
+ senderId: E,
16
+ trackId: _,
17
+ sequenceId: I,
18
+ targetIds: G,
19
+ payloadVersion: q,
20
+ payloadType: j,
21
+ flags: Q
22
+ };
23
+ }
24
+ function K(t, r, e) {
25
+ const n = O(t), s = J(n);
26
+ if (r !== void 0 && s.opcode !== r)
27
+ throw new Error(`Unexpected opcode ${s.opcode}`);
28
+ if (s.payloadVersion !== e)
29
+ throw new Error(`Unexpected payload version ${s.payloadVersion}`);
30
+ if (s.payloadType !== 8)
31
+ throw new Error(`Unexpected payload type ${s.payloadType}`);
32
+ const E = 27 + s.targetIds.length * 4;
33
+ return n.subarray(E, s.length);
34
+ }
35
+ var R = /* @__PURE__ */ ((t) => (t[t.Null = 1] = "Null", t[t.Bool = 2] = "Bool", t[t.Int32 = 3] = "Int32", t[t.Int64 = 4] = "Int64", t[t.UInt32 = 5] = "UInt32", t[t.UInt64 = 6] = "UInt64", t[t.Float32 = 7] = "Float32", t[t.Float64 = 8] = "Float64", t[t.Array = 9] = "Array", t[t.Dict = 10] = "Dict", t[t.Object = 11] = "Object", t[t.String = 12] = "String", t[t.Binary = 13] = "Binary", t[t.Guid = 14] = "Guid", t))(R || {});
36
+ const Z = 161, p = 162;
37
+ new TextEncoder();
38
+ const tt = new TextDecoder("utf-8", { fatal: !0 });
39
+ class w {
40
+ constructor(r, e, n) {
41
+ this.buffer = r, this.version = e, this.offset = n, this.end = r.length - 1;
42
+ }
43
+ offset;
44
+ end;
45
+ static create(r) {
46
+ const e = O(r);
47
+ if (e.length < 2)
48
+ throw new Error("Teleport payload too short");
49
+ if (e[0] !== Z || e[e.length - 1] !== p)
50
+ throw new Error("Teleport object missing markers");
51
+ const n = { offset: 1 }, s = T(e, n, "InvalidLength");
52
+ return new w(e, s, n.offset);
53
+ }
54
+ next() {
55
+ if (this.offset >= this.end)
56
+ return null;
57
+ if (this.offset + 5 > this.buffer.length)
58
+ throw new Error("Teleport object truncated");
59
+ const r = st(this.buffer, this.offset);
60
+ this.offset += 4;
61
+ const e = this.buffer[this.offset++], n = e >> 4 & 15;
62
+ if ((e & 15) !== 0)
63
+ throw new Error("Teleport field flags must be zero");
64
+ const s = U(n);
65
+ let E;
66
+ if (s >= 0)
67
+ a(this.buffer, this.offset, s), E = this.buffer.subarray(this.offset, this.offset + s), this.offset += s;
68
+ else {
69
+ const _ = { offset: this.offset }, I = T(this.buffer, _, "InvalidLength");
70
+ a(this.buffer, _.offset, I), E = this.buffer.subarray(_.offset, _.offset + I), this.offset = _.offset + I;
71
+ }
72
+ return new rt(r, n, E);
73
+ }
74
+ }
75
+ class N {
76
+ constructor(r, e) {
77
+ this.type = r, this.payload = e;
78
+ }
79
+ asInt32() {
80
+ return this.ensureType(
81
+ 3
82
+ /* Int32 */
83
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getInt32(0, !0);
84
+ }
85
+ asUInt32() {
86
+ return this.ensureType(
87
+ 5
88
+ /* UInt32 */
89
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getUint32(0, !0);
90
+ }
91
+ asInt64() {
92
+ return this.ensureType(
93
+ 4
94
+ /* Int64 */
95
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigInt64(0, !0);
96
+ }
97
+ asUInt64() {
98
+ return this.ensureType(
99
+ 6
100
+ /* UInt64 */
101
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigUint64(0, !0);
102
+ }
103
+ asFloat32() {
104
+ return this.ensureType(
105
+ 7
106
+ /* Float32 */
107
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getFloat32(0, !0);
108
+ }
109
+ asFloat64() {
110
+ return this.ensureType(
111
+ 8
112
+ /* Float64 */
113
+ ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getFloat64(0, !0);
114
+ }
115
+ asBool() {
116
+ return this.ensureType(
117
+ 2
118
+ /* Bool */
119
+ ), this.payload.length > 0 && this.payload[0] !== 0;
120
+ }
121
+ asBinary() {
122
+ return this.ensureType(
123
+ 13
124
+ /* Binary */
125
+ ), this.payload;
126
+ }
127
+ asUtf8() {
128
+ return this.ensureType(
129
+ 12
130
+ /* String */
131
+ ), this.payload;
132
+ }
133
+ asString() {
134
+ return this.ensureType(
135
+ 12
136
+ /* String */
137
+ ), tt.decode(this.payload);
138
+ }
139
+ asGuid() {
140
+ return this.ensureType(
141
+ 14
142
+ /* Guid */
143
+ ), i.fromBytes(this.payload);
144
+ }
145
+ asObject() {
146
+ return this.ensureType(
147
+ 11
148
+ /* Object */
149
+ ), w.create(this.payload);
150
+ }
151
+ asArray() {
152
+ return this.ensureType(
153
+ 9
154
+ /* Array */
155
+ ), m.create(this.payload);
156
+ }
157
+ asDictionary() {
158
+ return this.ensureType(
159
+ 10
160
+ /* Dict */
161
+ ), F.create(this.payload);
162
+ }
163
+ ensureType(r) {
164
+ if (this.type !== r)
165
+ throw new Error(`Teleport value has type ${R[this.type]}, expected ${R[r]}`);
166
+ }
167
+ }
168
+ class rt extends N {
169
+ constructor(r, e, n) {
170
+ super(e, n), this.fieldId = r;
171
+ }
172
+ get isNull() {
173
+ return this.type === 1;
174
+ }
175
+ }
176
+ class m {
177
+ payload;
178
+ elementType;
179
+ count;
180
+ offset;
181
+ index = 0;
182
+ constructor(r) {
183
+ if (this.payload = r, r.length === 0)
184
+ throw new Error("Array payload too short");
185
+ const e = r[0];
186
+ if (this.elementType = e >> 4 & 15, (e & 15) !== 0)
187
+ throw new Error("Array flags must be zero");
188
+ const n = { offset: 1 };
189
+ this.count = T(r, n, "ArrayMalformed"), this.offset = n.offset;
190
+ }
191
+ static create(r) {
192
+ return new m(O(r));
193
+ }
194
+ next() {
195
+ if (this.index >= this.count) {
196
+ if (this.offset !== this.payload.length)
197
+ throw new Error("Array payload contains trailing data");
198
+ return null;
199
+ }
200
+ const r = this.readValue();
201
+ return this.index++, r;
202
+ }
203
+ readValue() {
204
+ switch (this.elementType) {
205
+ case 3:
206
+ case 5:
207
+ case 7:
208
+ case 8:
209
+ case 2:
210
+ case 4:
211
+ case 6:
212
+ case 14: {
213
+ const r = U(this.elementType);
214
+ a(this.payload, this.offset, r);
215
+ const e = this.payload.subarray(this.offset, this.offset + r);
216
+ return this.offset += r, new D(this.elementType, e);
217
+ }
218
+ case 12:
219
+ case 13: {
220
+ const r = { offset: this.offset }, e = T(this.payload, r, "ArrayMalformed");
221
+ a(this.payload, r.offset, e);
222
+ const n = this.payload.subarray(r.offset, r.offset + e);
223
+ return this.offset = r.offset + e, new D(this.elementType, n);
224
+ }
225
+ case 11: {
226
+ const r = { offset: this.offset }, e = T(this.payload, r, "ArrayMalformed");
227
+ a(this.payload, r.offset, e);
228
+ const n = this.payload.subarray(r.offset, r.offset + e);
229
+ return this.offset = r.offset + e, new D(11, n);
230
+ }
231
+ case 9: {
232
+ const r = V(this.payload, this.offset), e = this.payload.subarray(this.offset, this.offset + r);
233
+ return this.offset += r, new D(9, e);
234
+ }
235
+ case 10: {
236
+ const r = M(this.payload, this.offset), e = this.payload.subarray(this.offset, this.offset + r);
237
+ return this.offset += r, new D(10, e);
238
+ }
239
+ default:
240
+ throw new Error(`Unsupported array element type ${R[this.elementType]}`);
241
+ }
242
+ }
243
+ }
244
+ class D extends N {
245
+ constructor(r, e) {
246
+ super(r, e);
247
+ }
248
+ }
249
+ class F {
250
+ payload;
251
+ keyType;
252
+ valueType;
253
+ count;
254
+ offset;
255
+ index = 0;
256
+ constructor(r) {
257
+ if (this.payload = r, r.length < 2)
258
+ throw new Error("Dictionary payload too short");
259
+ if (this.keyType = r[0] >> 4 & 15, this.valueType = r[1] >> 4 & 15, (r[0] & 15) !== 0 || (r[1] & 15) !== 0)
260
+ throw new Error("Dictionary key/value flags must be zero");
261
+ x(this.keyType);
262
+ const e = { offset: 2 };
263
+ this.count = T(r, e, "DictMalformed"), this.offset = e.offset;
264
+ }
265
+ static create(r) {
266
+ return new F(O(r));
267
+ }
268
+ next() {
269
+ if (this.index >= this.count) {
270
+ if (this.offset !== this.payload.length)
271
+ throw new Error("Dictionary payload contains trailing data");
272
+ return null;
273
+ }
274
+ const r = this.readKey(), e = this.readValue();
275
+ return this.index++, new et(r, e);
276
+ }
277
+ readKey() {
278
+ const r = U(this.keyType);
279
+ if (r >= 0) {
280
+ a(this.payload, this.offset, r);
281
+ const e = this.payload.subarray(this.offset, this.offset + r);
282
+ return this.offset += r, new N(this.keyType, e);
283
+ }
284
+ if (this.keyType === 12 || this.keyType === 13) {
285
+ const e = { offset: this.offset }, n = T(this.payload, e, "DictMalformed");
286
+ a(this.payload, e.offset, n);
287
+ const s = this.payload.subarray(e.offset, e.offset + n);
288
+ return this.offset = e.offset + n, new N(this.keyType, s);
289
+ }
290
+ throw new Error("Unsupported dictionary key type");
291
+ }
292
+ readValue() {
293
+ switch (this.valueType) {
294
+ case 12:
295
+ case 13: {
296
+ const r = { offset: this.offset }, e = T(this.payload, r, "DictMalformed");
297
+ a(this.payload, r.offset, e);
298
+ const n = this.payload.subarray(r.offset, r.offset + e);
299
+ return this.offset = r.offset + e, new N(this.valueType, n);
300
+ }
301
+ case 11: {
302
+ const r = { offset: this.offset }, e = T(this.payload, r, "DictMalformed");
303
+ a(this.payload, r.offset, e);
304
+ const n = this.payload.subarray(r.offset, r.offset + e);
305
+ return this.offset = r.offset + e, new N(11, n);
306
+ }
307
+ case 9: {
308
+ const r = V(this.payload, this.offset), e = this.payload.subarray(this.offset, this.offset + r);
309
+ return this.offset += r, new N(9, e);
310
+ }
311
+ case 10: {
312
+ const r = M(this.payload, this.offset), e = this.payload.subarray(this.offset, this.offset + r);
313
+ return this.offset += r, new N(10, e);
314
+ }
315
+ case 3:
316
+ case 5:
317
+ case 7:
318
+ case 8:
319
+ case 2:
320
+ case 4:
321
+ case 6:
322
+ case 14:
323
+ case 1: {
324
+ const r = U(this.valueType);
325
+ a(this.payload, this.offset, r);
326
+ const e = this.payload.subarray(this.offset, this.offset + r);
327
+ return this.offset += r, new N(this.valueType, e);
328
+ }
329
+ default:
330
+ throw new Error(`Unsupported dictionary value type ${R[this.valueType]}`);
331
+ }
332
+ }
333
+ }
334
+ class et {
335
+ constructor(r, e) {
336
+ this.key = r, this.value = e;
337
+ }
338
+ }
339
+ class i {
340
+ constructor(r) {
341
+ this.bytes = r;
342
+ }
343
+ static fromString(r) {
344
+ if (!r)
345
+ throw new Error("Guid string is empty");
346
+ const e = r.replace(/-/g, "");
347
+ if (e.length !== 32)
348
+ throw new Error("Guid string must be 32 hex characters");
349
+ const n = new Uint8Array(16), s = i.parseHexSlice(e, 0, 8), E = i.parseHexSlice(e, 8, 4), _ = i.parseHexSlice(e, 12, 4);
350
+ i.writeUInt32LE(n, 0, s), i.writeUInt16LE(n, 4, E), i.writeUInt16LE(n, 6, _);
351
+ for (let I = 0; I < 8; I++)
352
+ n[8 + I] = i.parseHexSlice(e, 16 + I * 2, 2);
353
+ return new i(n);
354
+ }
355
+ static fromBytes(r) {
356
+ if (r.length !== 16)
357
+ throw new Error("Guid byte array must be 16 bytes");
358
+ return new i(Uint8Array.from(r));
359
+ }
360
+ static createZero() {
361
+ return new i(new Uint8Array(16));
362
+ }
363
+ static createRandom() {
364
+ const r = new Uint8Array(16), e = globalThis.crypto;
365
+ if (e?.getRandomValues)
366
+ e.getRandomValues(r);
367
+ else
368
+ for (let n = 0; n < r.length; n++)
369
+ r[n] = Math.floor(Math.random() * 256);
370
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, new i(r);
371
+ }
372
+ toString() {
373
+ const r = this.bytes;
374
+ return [
375
+ i.toHex(i.readUInt32LE(r, 0), 8),
376
+ i.toHex(i.readUInt16LE(r, 4), 4),
377
+ i.toHex(i.readUInt16LE(r, 6), 4),
378
+ d(r.subarray(8, 10)),
379
+ d(r.subarray(10, 16))
380
+ ].join("-");
381
+ }
382
+ asBytes() {
383
+ return this.bytes.slice();
384
+ }
385
+ static parseHexSlice(r, e, n) {
386
+ const s = r.substr(e, n), E = Number.parseInt(s, 16);
387
+ if (Number.isNaN(E))
388
+ throw new Error("Guid string contains invalid characters");
389
+ return E >>> 0;
390
+ }
391
+ static writeUInt32LE(r, e, n) {
392
+ const s = n >>> 0;
393
+ r[e] = s & 255, r[e + 1] = s >>> 8 & 255, r[e + 2] = s >>> 16 & 255, r[e + 3] = s >>> 24 & 255;
394
+ }
395
+ static writeUInt16LE(r, e, n) {
396
+ const s = n & 65535;
397
+ r[e] = s & 255, r[e + 1] = s >>> 8 & 255;
398
+ }
399
+ static readUInt32LE(r, e) {
400
+ return (r[e] | r[e + 1] << 8 | r[e + 2] << 16 | r[e + 3] << 24) >>> 0;
401
+ }
402
+ static readUInt16LE(r, e) {
403
+ return (r[e] | r[e + 1] << 8) & 65535;
404
+ }
405
+ static toHex(r, e) {
406
+ return (r >>> 0).toString(16).padStart(e, "0");
407
+ }
408
+ }
409
+ function T(t, r, e) {
410
+ if (r.offset >= t.length)
411
+ throw new Error(e);
412
+ let n = 0, s = 0, E = 0;
413
+ for (; r.offset < t.length; ) {
414
+ const _ = t[r.offset++];
415
+ if (E++, n |= (_ & 127) << s, (_ & 128) === 0) {
416
+ if (E !== nt(n))
417
+ throw new Error("Teleport VarUInt is not canonical");
418
+ return n >>> 0;
419
+ }
420
+ if (s += 7, s >= 35)
421
+ throw new Error("Teleport VarUInt exceeds 32-bit range");
422
+ }
423
+ throw new Error(e);
424
+ }
425
+ function nt(t) {
426
+ return t < 128 ? 1 : t < 16384 ? 2 : t < 2097152 ? 3 : t < 268435456 ? 4 : 5;
427
+ }
428
+ function U(t) {
429
+ switch (t) {
430
+ case 3:
431
+ case 5:
432
+ case 7:
433
+ return 4;
434
+ case 4:
435
+ case 6:
436
+ case 8:
437
+ return 8;
438
+ case 14:
439
+ return 16;
440
+ case 2:
441
+ return 1;
442
+ case 1:
443
+ return 0;
444
+ default:
445
+ return -1;
446
+ }
447
+ }
448
+ function x(t) {
449
+ if (t === 9 || t === 11 || t === 10 || t === 1)
450
+ throw new Error("Dictionary keys must be primitive Teleport types");
451
+ }
452
+ function a(t, r, e) {
453
+ if (r < 0 || e < 0 || r + e > t.length)
454
+ throw new Error("Teleport payload exceeds bounds");
455
+ }
456
+ function st(t, r) {
457
+ return (t[r] | t[r + 1] << 8 | t[r + 2] << 16 | t[r + 3] << 24) >>> 0;
458
+ }
459
+ function V(t, r) {
460
+ if (r >= t.length)
461
+ throw new Error("Array payload exceeds bounds");
462
+ const e = t[r], n = e >> 4 & 15;
463
+ if ((e & 15) !== 0)
464
+ throw new Error("Array flags must be zero");
465
+ const s = { offset: r + 1 }, E = T(t, s, "ArrayMalformed"), _ = U(n);
466
+ if (_ >= 0) {
467
+ const f = _ * E;
468
+ return a(t, s.offset, f), s.offset + f - r;
469
+ }
470
+ let I = s.offset;
471
+ for (let f = 0; f < E; f++)
472
+ I = g(n, t, I, "ArrayMalformed");
473
+ return I - r;
474
+ }
475
+ function M(t, r) {
476
+ if (r + 2 > t.length)
477
+ throw new Error("Dictionary payload too short");
478
+ const e = t[r] >> 4 & 15, n = t[r + 1] >> 4 & 15;
479
+ if ((t[r] & 15) !== 0 || (t[r + 1] & 15) !== 0)
480
+ throw new Error("Dictionary key/value flags must be zero");
481
+ x(e);
482
+ const s = { offset: r + 2 }, E = T(t, s, "DictMalformed");
483
+ let _ = s.offset;
484
+ for (let I = 0; I < E; I++)
485
+ _ = g(e, t, _, "DictMalformed"), _ = g(n, t, _, "DictMalformed");
486
+ return _ - r;
487
+ }
488
+ function g(t, r, e, n) {
489
+ const s = U(t);
490
+ if (s >= 0)
491
+ return a(r, e, s), e + s;
492
+ switch (t) {
493
+ case 12:
494
+ case 13: {
495
+ const E = { offset: e }, _ = T(r, E, n);
496
+ return a(r, E.offset, _), E.offset + _;
497
+ }
498
+ case 11: {
499
+ const E = { offset: e }, _ = T(r, E, n);
500
+ return a(r, E.offset, _), E.offset + _;
501
+ }
502
+ case 9:
503
+ return e + V(r, e);
504
+ case 10:
505
+ return e + M(r, e);
506
+ default:
507
+ throw new Error(`Unsupported Teleport type ${R[t]}`);
508
+ }
509
+ }
510
+ function d(t) {
511
+ return Array.from(t).map((r) => r.toString(16).padStart(2, "0")).join("");
512
+ }
513
+ function O(t) {
514
+ return t instanceof Uint8Array ? t : new Uint8Array(t);
515
+ }
516
+ var u = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.H264 = 1] = "H264", t[t.Vp8 = 2] = "Vp8", t[t.Vp9 = 3] = "Vp9", t[t.Av1 = 4] = "Av1", t))(u || {}), c = /* @__PURE__ */ ((t) => (t[t.NONE = 0] = "NONE", t[t.CONSTANT_GROUP_BITS = 15] = "CONSTANT_GROUP_BITS", t[t.CONSTANT_GROUP_OFFSET = 16] = "CONSTANT_GROUP_OFFSET", t[t.GROUP_CORE = 65536] = "GROUP_CORE", t[t.CORE_AUTH_RESPONSE = 65537] = "CORE_AUTH_RESPONSE", t[t.CORE_AUTH_TICKET = 65538] = "CORE_AUTH_TICKET", t[t.CORE_GLOBAL_STATE = 65539] = "CORE_GLOBAL_STATE", t[t.CORE_ON_SERVER_STATUS_PING = 65540] = "CORE_ON_SERVER_STATUS_PING", t[t.CORE_ON_USER_JOINED = 65541] = "CORE_ON_USER_JOINED", t[t.CORE_ON_USER_LEFT = 65542] = "CORE_ON_USER_LEFT", t[t.CORE_ON_CLIENT_JOINED = 65543] = "CORE_ON_CLIENT_JOINED", t[t.CORE_ON_CLIENT_LEFT = 65544] = "CORE_ON_CLIENT_LEFT", t[t.CORE_ON_SERVER_STARTED = 65545] = "CORE_ON_SERVER_STARTED", t[t.CORE_ON_SERVER_STOPPED = 65546] = "CORE_ON_SERVER_STOPPED", t[t.CORE_ON_SERVER_STOPPING = 65547] = "CORE_ON_SERVER_STOPPING", t[t.CORE_ON_CLIENT_READY = 65548] = "CORE_ON_CLIENT_READY", t[t.CORE_CLIENT_READY = 65549] = "CORE_CLIENT_READY", t[t.CORE_SERVER_INIT = 65550] = "CORE_SERVER_INIT", t[t.CORE_ON_PLUGIN_RELOADED = 65551] = "CORE_ON_PLUGIN_RELOADED", t[t.CORE_SERVER_START = 65552] = "CORE_SERVER_START", t[t.CORE_SERVER_STOP = 65553] = "CORE_SERVER_STOP", t[t.CORE_ON_HOSTED_SERVER_EXIT = 65554] = "CORE_ON_HOSTED_SERVER_EXIT", t[t.CORE_DYNAMIC_CONFIG = 65555] = "CORE_DYNAMIC_CONFIG", t[t.CORE_PROXY_RPC_AUTH_TICKET = 65556] = "CORE_PROXY_RPC_AUTH_TICKET", t[t.CORE_SERVER_INIT2 = 65557] = "CORE_SERVER_INIT2", t[t.GROUP_KEEPALIVE = 131072] = "GROUP_KEEPALIVE", t[t.KEEPALIVE_REQUEST = 131073] = "KEEPALIVE_REQUEST", t[t.KEEPALIVE_RESPONSE = 131074] = "KEEPALIVE_RESPONSE", t[t.GROUP_EVENTS = 262144] = "GROUP_EVENTS", t[t.EVENTS_PROFILE_UPDATE = 262145] = "EVENTS_PROFILE_UPDATE", t[t.EVENTS_CHANNEL_COMPLETE = 262146] = "EVENTS_CHANNEL_COMPLETE", t[t.EVENTS_SPEECH_PLAYBACK_COMPLETE = 262147] = "EVENTS_SPEECH_PLAYBACK_COMPLETE", t[t.GROUP_ANALYTICS = 524288] = "GROUP_ANALYTICS", t[t.ANALYTICS_LOGS = 524289] = "ANALYTICS_LOGS", t[t.ANALYTICS_EVENTS = 524290] = "ANALYTICS_EVENTS", t[t.ANALYTICS_USAGES = 524291] = "ANALYTICS_USAGES", t[t.ANALYTICS_USAGE = 524292] = "ANALYTICS_USAGE", t[t.ANALYTICS_SPECIAL_LOG = 524293] = "ANALYTICS_SPECIAL_LOG", t[t.ANALYTICS_PROCESSING_UPDATE = 524294] = "ANALYTICS_PROCESSING_UPDATE", t[t.ANALYTICS_REACTIVE_PROCESSING_UPDATE = 524295] = "ANALYTICS_REACTIVE_PROCESSING_UPDATE", t[t.ANALYTICS_IKON_PROXY_SERVER_STATS = 524296] = "ANALYTICS_IKON_PROXY_SERVER_STATS", t[t.GROUP_ACTIONS = 1048576] = "GROUP_ACTIONS", t[t.ACTION_CALL = 1048577] = "ACTION_CALL", t[t.ACTION_ACTIVE = 1048578] = "ACTION_ACTIVE", t[t.ACTION_TEXT_OUTPUT = 1048579] = "ACTION_TEXT_OUTPUT", t[t.ACTION_TEXT_OUTPUT_DELTA = 1048580] = "ACTION_TEXT_OUTPUT_DELTA", t[t.ACTION_TEXT_OUTPUT_DELTA_FULL = 1048581] = "ACTION_TEXT_OUTPUT_DELTA_FULL", t[t.ACTION_SET_STATE = 1048582] = "ACTION_SET_STATE", t[t.ACTION_TAP = 1048583] = "ACTION_TAP", t[t.ACTION_PAN = 1048584] = "ACTION_PAN", t[t.ACTION_ZOOM = 1048585] = "ACTION_ZOOM", t[t.ACTION_FILE_UPLOAD_BEGIN = 1048586] = "ACTION_FILE_UPLOAD_BEGIN", t[t.ACTION_FILE_UPLOAD_DATA = 1048587] = "ACTION_FILE_UPLOAD_DATA", t[t.ACTION_FILE_UPLOAD_ACK = 1048588] = "ACTION_FILE_UPLOAD_ACK", t[t.ACTION_FILE_UPLOAD_END = 1048589] = "ACTION_FILE_UPLOAD_END", t[t.ACTION_FILE_UPLOAD_RESULT = 1048590] = "ACTION_FILE_UPLOAD_RESULT", t[t.ACTION_OPEN_CHANNEL = 1048591] = "ACTION_OPEN_CHANNEL", t[t.ACTION_OPEN_EXTERNAL_URL = 1048592] = "ACTION_OPEN_EXTERNAL_URL", t[t.ACTION_UI_OPEN_VIEW = 1048593] = "ACTION_UI_OPEN_VIEW", t[t.ACTION_UI_CLOSE_VIEW = 1048594] = "ACTION_UI_CLOSE_VIEW", t[t.ACTION_UI_BLOCKING_BEGIN = 1048595] = "ACTION_UI_BLOCKING_BEGIN", t[t.ACTION_UI_BLOCKING_END = 1048596] = "ACTION_UI_BLOCKING_END", t[t.ACTION_UI_UPDATE_TEXT_DELTA = 1048597] = "ACTION_UI_UPDATE_TEXT_DELTA", t[t.ACTION_UI_DELETE_CONTAINER = 1048598] = "ACTION_UI_DELETE_CONTAINER", t[t.ACTION_UPDATE_GFX_SHADER = 1048599] = "ACTION_UPDATE_GFX_SHADER", t[t.ACTION_FUNCTION_REGISTER = 1048600] = "ACTION_FUNCTION_REGISTER", t[t.ACTION_FUNCTION_CALL = 1048601] = "ACTION_FUNCTION_CALL", t[t.ACTION_FUNCTION_RESULT = 1048602] = "ACTION_FUNCTION_RESULT", t[t.ACTION_GENERATE_ANSWER = 1048603] = "ACTION_GENERATE_ANSWER", t[t.ACTION_REGENERATE_ANSWER = 1048604] = "ACTION_REGENERATE_ANSWER", t[t.ACTION_CLEAR_CHAT_MESSAGE_HISTORY = 1048605] = "ACTION_CLEAR_CHAT_MESSAGE_HISTORY", t[t.ACTION_CLEAR_STATE = 1048606] = "ACTION_CLEAR_STATE", t[t.ACTION_RELOAD_CHANNELS = 1048607] = "ACTION_RELOAD_CHANNELS", t[t.ACTION_RELOAD_PROFILE = 1048608] = "ACTION_RELOAD_PROFILE", t[t.ACTION_CLASSIFICATION_RESULT = 1048609] = "ACTION_CLASSIFICATION_RESULT", t[t.ACTION_AUDIO_STOP = 1048610] = "ACTION_AUDIO_STOP", t[t.ACTION_CALL_TEXT = 1048611] = "ACTION_CALL_TEXT", t[t.ACTION_RELOAD_APPLICATION = 1048612] = "ACTION_RELOAD_APPLICATION", t[t.ACTION_CANCEL_GENERATION = 1048613] = "ACTION_CANCEL_GENERATION", t[t.ACTION_UI_SET_CONTAINER_STABLE = 1048614] = "ACTION_UI_SET_CONTAINER_STABLE", t[t.ACTION_SPEECH_RECOGNIZED = 1048615] = "ACTION_SPEECH_RECOGNIZED", t[t.ACTION_CALL_RESULT = 1048616] = "ACTION_CALL_RESULT", t[t.ACTION_RELOAD_PROVIDER = 1048617] = "ACTION_RELOAD_PROVIDER", t[t.ACTION_DOWNLOAD = 1048618] = "ACTION_DOWNLOAD", t[t.ACTION_SCROLL_TO_CONTAINER = 1048619] = "ACTION_SCROLL_TO_CONTAINER", t[t.ACTION_UI_CLEAR_STREAM = 1048620] = "ACTION_UI_CLEAR_STREAM", t[t.ACTION_PLAY_SOUND = 1048621] = "ACTION_PLAY_SOUND", t[t.ACTION_ENTER_FULLSCREEN = 1048622] = "ACTION_ENTER_FULLSCREEN", t[t.ACTION_STOP_SOUND = 1048623] = "ACTION_STOP_SOUND", t[t.ACTION_START_RECORDING = 1048624] = "ACTION_START_RECORDING", t[t.ACTION_STOP_RECORDING = 1048625] = "ACTION_STOP_RECORDING", t[t.ACTION_OPTIMISTIC_CLIENT_CALLS = 1048626] = "ACTION_OPTIMISTIC_CLIENT_CALLS", t[t.ACTION_FUNCTION_ENUMERATION_ITEM = 1048627] = "ACTION_FUNCTION_ENUMERATION_ITEM", t[t.ACTION_FUNCTION_ENUMERATION_END = 1048628] = "ACTION_FUNCTION_ENUMERATION_END", t[t.ACTION_FUNCTION_CANCEL = 1048629] = "ACTION_FUNCTION_CANCEL", t[t.ACTION_FUNCTION_DISPOSE = 1048630] = "ACTION_FUNCTION_DISPOSE", t[t.ACTION_FUNCTION_ERROR = 1048631] = "ACTION_FUNCTION_ERROR", t[t.ACTION_FUNCTION_ACK = 1048632] = "ACTION_FUNCTION_ACK", t[t.ACTION_FUNCTION_AWAITING_APPROVAL = 1048633] = "ACTION_FUNCTION_AWAITING_APPROVAL", t[t.ACTION_FUNCTION_APPROVAL_REQUIRED = 1048634] = "ACTION_FUNCTION_APPROVAL_REQUIRED", t[t.ACTION_FUNCTION_APPROVAL_RESPONSE = 1048635] = "ACTION_FUNCTION_APPROVAL_RESPONSE", t[t.UI_UPDATE_ACK = 1048636] = "UI_UPDATE_ACK", t[t.ACTION_CALL2 = 1048637] = "ACTION_CALL2", t[t.ACTION_FUNCTION_REGISTER_BATCH = 1048638] = "ACTION_FUNCTION_REGISTER_BATCH", t[t.ACTION_TRIGGER_GIT_PULL = 1048639] = "ACTION_TRIGGER_GIT_PULL", t[t.GROUP_UI = 2097152] = "GROUP_UI", t[t.UI_STREAM_BEGIN = 2097153] = "UI_STREAM_BEGIN", t[t.UI_STREAM_END = 2097154] = "UI_STREAM_END", t[t.UI_CONTAINER_BEGIN = 2097155] = "UI_CONTAINER_BEGIN", t[t.UI_CONTAINER_END = 2097156] = "UI_CONTAINER_END", t[t.UI_SECTION_BEGIN = 2097157] = "UI_SECTION_BEGIN", t[t.UI_SECTION_END = 2097158] = "UI_SECTION_END", t[t.UI_LIST_BEGIN = 2097159] = "UI_LIST_BEGIN", t[t.UI_LIST_ITEM = 2097160] = "UI_LIST_ITEM", t[t.UI_LIST_END = 2097161] = "UI_LIST_END", t[t.UI_TEXT = 2097162] = "UI_TEXT", t[t.UI_HEADER = 2097163] = "UI_HEADER", t[t.UI_SEPARATOR = 2097164] = "UI_SEPARATOR", t[t.UI_BUTTON = 2097165] = "UI_BUTTON", t[t.UI_ICON_BUTTON = 2097166] = "UI_ICON_BUTTON", t[t.UI_IMAGE = 2097167] = "UI_IMAGE", t[t.UI_FILE = 2097168] = "UI_FILE", t[t.UI_BADGE = 2097169] = "UI_BADGE", t[t.UI_CONTENT_LINK = 2097170] = "UI_CONTENT_LINK", t[t.UI_MAP = 2097171] = "UI_MAP", t[t.UI_VEGA_CHART = 2097172] = "UI_VEGA_CHART", t[t.UI_ICON = 2097173] = "UI_ICON", t[t.UI_FILE_UPLOAD_SECTION_BEGIN = 2097174] = "UI_FILE_UPLOAD_SECTION_BEGIN", t[t.UI_FILE_UPLOAD_SECTION_END = 2097175] = "UI_FILE_UPLOAD_SECTION_END", t[t.UI_MATERIAL_SYMBOL = 2097176] = "UI_MATERIAL_SYMBOL", t[t.UI_BUTTON_BEGIN = 2097177] = "UI_BUTTON_BEGIN", t[t.UI_BUTTON_END = 2097178] = "UI_BUTTON_END", t[t.UI_CONTAINER_DELETE = 2097179] = "UI_CONTAINER_DELETE", t[t.UI_INPUT_TEXT = 2097180] = "UI_INPUT_TEXT", t[t.UI_PROGRESS_BAR = 2097181] = "UI_PROGRESS_BAR", t[t.UI_UPDATE_BEGIN = 2097182] = "UI_UPDATE_BEGIN", t[t.UI_UPDATE_END = 2097183] = "UI_UPDATE_END", t[t.UI_AUTOCOMPLETE = 2097184] = "UI_AUTOCOMPLETE", t[t.UI_CHECKBOX = 2097185] = "UI_CHECKBOX", t[t.UI_QS = 2097186] = "UI_QS", t[t.UI_ELEMENT = 2097187] = "UI_ELEMENT", t[t.UI_STYLES = 2097188] = "UI_STYLES", t[t.UI_SVG = 2097189] = "UI_SVG", t[t.UI_UPDATE = 2097190] = "UI_UPDATE", t[t.UI_INIT = 2097191] = "UI_INIT", t[t.UI_STYLES_BATCH = 2097192] = "UI_STYLES_BATCH", t[t.UI_STYLES_DELETE = 2097193] = "UI_STYLES_DELETE", t[t.GROUP_COMMON = 4128768] = "GROUP_COMMON", t[t.GROUP_AUDIO = 4194304] = "GROUP_AUDIO", t[t.AUDIO_STREAM_BEGIN = 4194305] = "AUDIO_STREAM_BEGIN", t[t.AUDIO_STREAM_END = 4194306] = "AUDIO_STREAM_END", t[t.AUDIO_FRAME = 4194307] = "AUDIO_FRAME", t[t.AUDIO_FRAME_VOLUME = 4194308] = "AUDIO_FRAME_VOLUME", t[t.AUDIO_FRAME2 = 4194309] = "AUDIO_FRAME2", t[t.GROUP_VIDEO = 8388608] = "GROUP_VIDEO", t[t.VIDEO_STREAM_BEGIN = 8388609] = "VIDEO_STREAM_BEGIN", t[t.VIDEO_STREAM_END = 8388610] = "VIDEO_STREAM_END", t[t.VIDEO_FRAME = 8388611] = "VIDEO_FRAME", t[t.VIDEO_REQUEST_IDR_FRAME = 8388612] = "VIDEO_REQUEST_IDR_FRAME", t[t.VIDEO_INVALIDATE_FRAME = 8388613] = "VIDEO_INVALIDATE_FRAME", t[t.GROUP_TRACKING = 16777216] = "GROUP_TRACKING", t[t.TRACKING_STREAM_BEGIN = 16777217] = "TRACKING_STREAM_BEGIN", t[t.TRACKING_STREAM_END = 16777218] = "TRACKING_STREAM_END", t[t.TRACKING_FRAME = 16777219] = "TRACKING_FRAME", t[t.GROUP_SCENE = 33554432] = "GROUP_SCENE", t[t.SCENE_MESH = 33554433] = "SCENE_MESH", t[t.SCENE_ARRAY = 33554434] = "SCENE_ARRAY", t[t.GROUP_ALL = 67043328] = "GROUP_ALL", t[t.CONSTANT_GROUP_MASK = 2147418112] = "CONSTANT_GROUP_MASK", t))(c || {});
517
+ const Et = 1, _t = 8388609, it = 164808083, It = 1368629611, at = 2739413426, Tt = 2768375929, At = 2950031986, Nt = 3284746250, ft = 4065070594;
518
+ function ot(t) {
519
+ const r = {};
520
+ return v(r), r;
521
+ }
522
+ function v(t) {
523
+ return t.Description = "", t.Codec = u.H264, t.Width = 0, t.Height = 0, t.Framerate = 30, t.Bitrate = 0, t.IsHardwareAccelerated = !1, t;
524
+ }
525
+ function Ct(t, r) {
526
+ const e = w.create(t);
527
+ return ut(e, r);
528
+ }
529
+ function ut(t, r) {
530
+ const e = r ?? ot();
531
+ return v(e), ht(t, e), e;
532
+ }
533
+ function ht(t, r) {
534
+ let e;
535
+ for (; (e = t.next()) !== null; )
536
+ switch (e.fieldId) {
537
+ case it: {
538
+ if (e.isNull) throw new Error();
539
+ r.Framerate = e.asInt32();
540
+ break;
541
+ }
542
+ case It: {
543
+ if (e.isNull) throw new Error();
544
+ r.Description = e.asString();
545
+ break;
546
+ }
547
+ case at: {
548
+ if (e.isNull) throw new Error();
549
+ r.IsHardwareAccelerated = e.asBool();
550
+ break;
551
+ }
552
+ case Tt: {
553
+ if (e.isNull) throw new Error();
554
+ r.Bitrate = e.asInt32();
555
+ break;
556
+ }
557
+ case At: {
558
+ if (e.isNull) throw new Error();
559
+ r.Height = e.asInt32();
560
+ break;
561
+ }
562
+ case Nt: {
563
+ if (e.isNull) throw new Error();
564
+ r.Codec = e.asInt32();
565
+ break;
566
+ }
567
+ case ft: {
568
+ if (e.isNull) throw new Error();
569
+ r.Width = e.asInt32();
570
+ break;
571
+ }
572
+ }
573
+ }
574
+ function Rt(t, r) {
575
+ const e = K(t, _t, Et);
576
+ return Ct(e, r);
577
+ }
578
+ const Ut = 1, lt = 8388611, St = 271275304, Dt = 2541432218, ct = 2986785889, Lt = 3105403172, yt = 3456383222;
579
+ function wt(t) {
580
+ const r = {};
581
+ return Y(r), r;
582
+ }
583
+ function Y(t) {
584
+ return t.Data = new Uint8Array(0), t.FrameNumber = 0, t.IsKey = !1, t.TimestampInUs = 0n, t.DurationInUs = 0, t;
585
+ }
586
+ function Ot(t, r) {
587
+ const e = w.create(t);
588
+ return Pt(e, r);
589
+ }
590
+ function Pt(t, r) {
591
+ const e = r ?? wt();
592
+ return Y(e), gt(t, e), e;
593
+ }
594
+ function gt(t, r) {
595
+ let e;
596
+ for (; (e = t.next()) !== null; )
597
+ switch (e.fieldId) {
598
+ case St: {
599
+ if (e.isNull) throw new Error();
600
+ r.TimestampInUs = e.asUInt64();
601
+ break;
602
+ }
603
+ case Dt: {
604
+ if (e.isNull) throw new Error();
605
+ r.DurationInUs = e.asUInt32();
606
+ break;
607
+ }
608
+ case ct: {
609
+ if (e.isNull) throw new Error();
610
+ r.Data = e.asBinary();
611
+ break;
612
+ }
613
+ case Lt: {
614
+ if (e.isNull) throw new Error();
615
+ r.IsKey = e.asBool();
616
+ break;
617
+ }
618
+ case yt: {
619
+ if (e.isNull) throw new Error();
620
+ r.FrameNumber = e.asInt32();
621
+ break;
622
+ }
623
+ }
624
+ }
625
+ function mt(t, r) {
626
+ const e = K(t, lt, Ut);
627
+ return Ot(e, r);
628
+ }
629
+ const Ft = "avc1.42E01E", Vt = "vp8", Mt = "vp09.00.10.08", Gt = "av01.0.04M.08", Bt = 3, l = (t, r) => self.postMessage(t, r ?? []);
630
+ let h = null, y = !0;
631
+ const A = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map();
632
+ function o(t) {
633
+ const r = t instanceof Error ? t : new Error(String(t));
634
+ l({ type: "error", error: { name: r.name, message: r.message, stack: r.stack } });
635
+ }
636
+ function P(t, r) {
637
+ return t << 16 | r & 65535;
638
+ }
639
+ function k(t, r) {
640
+ return `${t}_${r}`;
641
+ }
642
+ function X(t, r) {
643
+ const e = A.get(t);
644
+ if (e)
645
+ return e;
646
+ const n = {
647
+ streamId: r,
648
+ numericKey: t,
649
+ watched: !1,
650
+ surface: null,
651
+ ctx2d: null,
652
+ codec: null,
653
+ width: 0,
654
+ height: 0,
655
+ framerate: 0,
656
+ bitrate: 0,
657
+ decoder: null,
658
+ decoderCodec: null,
659
+ isKeyFrameRequired: !0,
660
+ pendingDecodeCount: 0
661
+ };
662
+ return A.set(t, n), S.set(r, t), n;
663
+ }
664
+ function H(t) {
665
+ const r = S.get(t);
666
+ if (r !== void 0) {
667
+ const _ = A.get(r);
668
+ if (_)
669
+ return _;
670
+ }
671
+ const e = t.split("_"), n = Number(e[0]) || 0, s = Number(e[1]) || 0, E = P(n, s);
672
+ return X(E, t);
673
+ }
674
+ function bt(t) {
675
+ if (t === u.H264) return Ft;
676
+ if (t === u.Vp8) return Vt;
677
+ if (t === u.Vp9) return Mt;
678
+ if (t === u.Av1) return Gt;
679
+ throw new Error(`Unknown codec: ${t}`);
680
+ }
681
+ function C(t) {
682
+ l({ type: "requestIdr", streamId: t });
683
+ }
684
+ async function dt(t, r) {
685
+ try {
686
+ if (!y || !t.watched)
687
+ return;
688
+ if (typeof createImageBitmap == "function") {
689
+ const e = await createImageBitmap(r);
690
+ l({ type: "frame", streamId: t.streamId, width: t.width, height: t.height, bitmap: e }, [e]);
691
+ }
692
+ } catch (e) {
693
+ o(e);
694
+ } finally {
695
+ t.pendingDecodeCount--;
696
+ try {
697
+ r.close();
698
+ } catch {
699
+ }
700
+ }
701
+ }
702
+ async function Ht(t, r, e) {
703
+ const n = {
704
+ codec: t,
705
+ codedWidth: r > 0 ? r : void 0,
706
+ codedHeight: e > 0 ? e : void 0,
707
+ optimizeForLatency: !0
708
+ };
709
+ if (typeof VideoDecoder?.isConfigSupported != "function")
710
+ return { config: { ...n, hardwareAcceleration: "prefer-hardware" }, isHardwareAccelerated: !0 };
711
+ const s = { ...n, hardwareAcceleration: "prefer-hardware" };
712
+ try {
713
+ const E = await VideoDecoder.isConfigSupported(s);
714
+ if (E.supported)
715
+ return { config: E.config ?? s, isHardwareAccelerated: !0 };
716
+ } catch {
717
+ }
718
+ try {
719
+ const E = await VideoDecoder.isConfigSupported(n);
720
+ if (E.supported)
721
+ return { config: E.config ?? n, isHardwareAccelerated: !1 };
722
+ } catch {
723
+ }
724
+ return null;
725
+ }
726
+ async function L(t) {
727
+ if (t.codec == null)
728
+ return;
729
+ const r = bt(t.codec);
730
+ if (t.decoder || (t.decoder = new VideoDecoder({
731
+ output: (e) => {
732
+ if (t.pendingDecodeCount++, !y || !t.watched) {
733
+ t.pendingDecodeCount--;
734
+ try {
735
+ e.close();
736
+ } catch {
737
+ }
738
+ return;
739
+ }
740
+ if (t.pendingDecodeCount > Bt) {
741
+ t.pendingDecodeCount--;
742
+ try {
743
+ e.close();
744
+ } catch {
745
+ }
746
+ return;
747
+ }
748
+ const n = t.width, s = t.height;
749
+ if (t.ctx2d && t.surface) {
750
+ try {
751
+ t.ctx2d.drawImage(e, 0, 0, n, s);
752
+ } catch (E) {
753
+ o(E);
754
+ } finally {
755
+ t.pendingDecodeCount--;
756
+ try {
757
+ e.close();
758
+ } catch {
759
+ }
760
+ }
761
+ return;
762
+ }
763
+ dt(t, e);
764
+ },
765
+ error: (e) => {
766
+ o(e), t.isKeyFrameRequired = !0, C(t.streamId);
767
+ }
768
+ })), t.decoderCodec !== r) {
769
+ const e = await Ht(r, t.width, t.height);
770
+ if (!e) {
771
+ o(new Error(`Decoder not supported for codec ${r}`));
772
+ return;
773
+ }
774
+ t.decoderCodec = r;
775
+ try {
776
+ t.decoder.configure(e.config), t.isKeyFrameRequired = !0, C(t.streamId);
777
+ const n = e.isHardwareAccelerated ? "hardware" : "software", s = t.framerate > 0 ? `@${Math.round(t.framerate)}fps` : "";
778
+ l({ type: "log", message: `Decoder configured: codec=${r}, ${t.width}x${t.height}${s}, hw=${n}` });
779
+ } catch (n) {
780
+ o(n);
781
+ }
782
+ t.surface && t.ctx2d && t.width > 0 && t.height > 0 && (t.surface.width !== t.width || t.surface.height !== t.height) && (t.surface.width = t.width, t.surface.height = t.height);
783
+ }
784
+ }
785
+ function Kt(t, r) {
786
+ const e = P(r.senderId, r.trackId), n = k(r.senderId, r.trackId), s = Rt(t), E = X(e, n);
787
+ E.codec = s.Codec, E.width = s.Width, E.height = s.Height, E.framerate = s.Framerate, E.bitrate = s.Bitrate, l({ type: "streamBegin", streamId: n, width: s.Width, height: s.Height, codec: s.Codec }), E.watched && (E.surface && E.ctx2d && s.Width > 0 && s.Height > 0 && (E.surface.width !== s.Width || E.surface.height !== s.Height) && (E.surface.width = s.Width, E.surface.height = s.Height), L(E));
788
+ }
789
+ function xt(t) {
790
+ const r = P(t.senderId, t.trackId), e = k(t.senderId, t.trackId);
791
+ l({ type: "streamEnd", streamId: e });
792
+ const n = A.get(r);
793
+ if (n) {
794
+ if (n.decoder)
795
+ try {
796
+ n.decoder.close();
797
+ } catch {
798
+ }
799
+ A.delete(r), S.delete(e);
800
+ }
801
+ }
802
+ function W(t) {
803
+ const r = S.get(t);
804
+ if (r === void 0)
805
+ return;
806
+ const e = A.get(r);
807
+ e && (e.surface = null, e.ctx2d = null);
808
+ }
809
+ function z(t) {
810
+ const r = S.get(t);
811
+ if (r === void 0)
812
+ return;
813
+ const e = A.get(r);
814
+ if (e && (e.watched = !1, e.isKeyFrameRequired = !0, W(t), e.decoder)) {
815
+ try {
816
+ e.decoder.close();
817
+ } catch {
818
+ }
819
+ e.decoder = null, e.decoderCodec = null;
820
+ }
821
+ }
822
+ function vt(t, r) {
823
+ const e = P(r.senderId, r.trackId), n = A.get(e);
824
+ if (!n || !y || !n.watched || ((!n.decoder || !n.decoderCodec) && L(n), !n.decoder || !n.decoderCodec))
825
+ return;
826
+ const s = mt(t);
827
+ if (n.isKeyFrameRequired) {
828
+ if (!s.IsKey)
829
+ return;
830
+ n.isKeyFrameRequired = !1;
831
+ }
832
+ try {
833
+ n.decoder.decode(
834
+ new EncodedVideoChunk({
835
+ type: s.IsKey ? "key" : "delta",
836
+ timestamp: Number(s.TimestampInUs),
837
+ duration: s.DurationInUs,
838
+ data: s.Data
839
+ })
840
+ );
841
+ } catch (E) {
842
+ n.isKeyFrameRequired = !0, C(n.streamId), o(E);
843
+ }
844
+ }
845
+ function Yt(t) {
846
+ const r = P(t.senderId, t.trackId), e = A.get(r);
847
+ e && (e.isKeyFrameRequired = !0, e.watched && C(e.streamId));
848
+ }
849
+ function kt(t, r) {
850
+ switch (r.opcode) {
851
+ case c.VIDEO_STREAM_BEGIN:
852
+ Kt(t, r);
853
+ return;
854
+ case c.VIDEO_STREAM_END:
855
+ xt(r);
856
+ return;
857
+ case c.VIDEO_FRAME:
858
+ vt(t, r);
859
+ return;
860
+ case c.VIDEO_INVALIDATE_FRAME:
861
+ Yt(r);
862
+ return;
863
+ default:
864
+ return;
865
+ }
866
+ }
867
+ function $() {
868
+ if (h) {
869
+ try {
870
+ h.close();
871
+ } catch {
872
+ }
873
+ h = null;
874
+ }
875
+ }
876
+ function Xt() {
877
+ $();
878
+ for (const t of A.values())
879
+ z(t.streamId);
880
+ A.clear(), S.clear();
881
+ }
882
+ self.addEventListener("message", (t) => {
883
+ const r = t.data;
884
+ if (r.type !== "configure") {
885
+ if (r.type === "attachSurface") {
886
+ const e = r.streamId, n = H(e);
887
+ n.watched = !0, n.surface = r.canvas;
888
+ try {
889
+ n.ctx2d = n.surface.getContext("2d", { alpha: !1, desynchronized: !0 });
890
+ } catch (s) {
891
+ o(s), n.ctx2d = null;
892
+ }
893
+ n.isKeyFrameRequired = !0, L(n), C(e);
894
+ return;
895
+ }
896
+ if (r.type === "detachSurface") {
897
+ W(r.streamId);
898
+ return;
899
+ }
900
+ if (r.type === "attachProtocolPort") {
901
+ $(), h = r.port, h.addEventListener("message", (e) => {
902
+ const n = e.data;
903
+ n?.type === "protocol" && n.message instanceof ArrayBuffer && n.headers && kt(new Uint8Array(n.message), n.headers);
904
+ }), h.start?.();
905
+ return;
906
+ }
907
+ if (r.type === "watchStream") {
908
+ const e = H(r.streamId);
909
+ e.watched = !0, e.isKeyFrameRequired = !0, L(e), C(e.streamId);
910
+ return;
911
+ }
912
+ if (r.type === "unwatchStream") {
913
+ z(r.streamId);
914
+ return;
915
+ }
916
+ if (r.type === "setEnabled") {
917
+ if (y = r.enabled, y)
918
+ for (const e of A.values())
919
+ e.watched && (e.isKeyFrameRequired = !0, L(e), C(e.streamId));
920
+ return;
921
+ }
922
+ r.type === "dispose" && Xt();
923
+ }
924
+ });