@ikonai/sdk 1.0.80 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/app-messaging.d.ts +1 -1
  2. package/assets/audio-capture-worker-CJ5S-nQt.js +1 -0
  3. package/assets/audio-playback-worker-B-dHMbvO.js +1 -0
  4. package/assets/libopus-CnBCihDi.js +1 -0
  5. package/assets/protocol-worker-DwwqSFAV.js +1 -0
  6. package/assets/src-BKYD07QQ.js +1 -0
  7. package/assets/src-DOUWsCWT.js +1 -0
  8. package/assets/video-capture-worker-BQGOFbZt.js +1 -0
  9. package/assets/video-playback-worker-BdfWDo46.js +1 -0
  10. package/assets/viseme-worker-DoO4M4Te.js +1 -0
  11. package/capabilities-Dm_Nog1J.js +105 -0
  12. package/channel/channel-manager.d.ts +1 -1
  13. package/channel/channel.d.ts +1 -1
  14. package/client/endpoint-selector.d.ts +1 -1
  15. package/client/ikon-client-config.d.ts +13 -11
  16. package/client/ikon-client.d.ts +86 -4
  17. package/connection/authenticator.d.ts +3 -3
  18. package/connection/urls.d.ts +7 -18
  19. package/errors/index.d.ts +22 -13
  20. package/functions/browser-functions.d.ts +1 -1
  21. package/functions/function-registry.d.ts +1 -1
  22. package/functions/types.d.ts +2 -2
  23. package/ikon-media-DuCadOIe.js +3154 -0
  24. package/index.d.ts +8 -8
  25. package/index.js +8083 -12536
  26. package/media/ikon-audio-capture.d.ts +7 -3
  27. package/media/ikon-audio-playback.d.ts +37 -0
  28. package/media/ikon-video-playback.d.ts +24 -0
  29. package/media/media-session-helper.d.ts +8 -0
  30. package/media/video-constants.d.ts +11 -1
  31. package/media/viseme-tracker.d.ts +10 -1
  32. package/package.json +1 -1
  33. package/storage.d.ts +13 -0
  34. package/transport/transport.d.ts +1 -1
  35. package/transport/web-socket-transport.d.ts +1 -1
  36. package/transport/web-transport-transport.d.ts +1 -1
  37. package/utils/inspect-mode.d.ts +4 -0
  38. package/utils/log-sender.d.ts +1 -1
  39. package/utils/platform.d.ts +4 -0
  40. package/utils/query-params.d.ts +8 -4
  41. package/vite.config.d.ts +2 -0
  42. package/webrtc/webrtc-signaling.d.ts +11 -2
  43. package/worker/audio-playback-worker.d.ts +14 -1
  44. package/worker/video-capture-worker.d.ts +2 -2
  45. package/worker/video-playback-worker.d.ts +14 -2
  46. package/worker/viseme-worker.d.ts +10 -2
  47. package/assets/audio-capture-worker-Brmt2Z7a.js +0 -1279
  48. package/assets/audio-playback-worker-C9XXiFhK.js +0 -1474
  49. package/assets/index-Ca9sTcGt.js +0 -119
  50. package/assets/index-D_vz6N3U.js +0 -267
  51. package/assets/libopus-ChbDZJKA.js +0 -139
  52. package/assets/protocol-worker-1sGaGw11.js +0 -1674
  53. package/assets/video-capture-worker-zOxyU-q3.js +0 -1126
  54. package/assets/video-playback-worker-DfwfIoRw.js +0 -1005
  55. package/assets/viseme-worker-CFJdP6of.js +0 -831
@@ -1,1005 +0,0 @@
1
- const J = {
2
- Compressed: 8
3
- };
4
- function p(t) {
5
- const e = w(t), r = new DataView(e.buffer, e.byteOffset, e.byteLength);
6
- if (e.length < 27)
7
- throw new Error("Protocol payload too short");
8
- const n = r.getUint32(0, !0), E = r.getUint32(4, !0), s = r.getUint32(8, !0), _ = r.getUint32(12, !0), i = r.getUint32(16, !0), C = r.getUint32(20, !0), N = r.getUint8(24), d = r.getUint8(25), Z = r.getUint8(26);
9
- if (27 + C * 4 > e.length)
10
- throw new Error("Protocol header exceeds payload length");
11
- const B = [];
12
- let K = 27;
13
- for (let Y = 0; Y < C; Y++)
14
- B.push(r.getUint32(K, !0)), K += 4;
15
- return {
16
- length: n,
17
- opcode: E,
18
- senderId: s,
19
- trackId: _,
20
- sequenceId: i,
21
- targetIds: B,
22
- payloadVersion: N,
23
- payloadType: d,
24
- flags: Z
25
- };
26
- }
27
- async function W(t, e, r) {
28
- const n = w(t), E = p(n);
29
- if (e !== void 0 && E.opcode !== e)
30
- throw new Error(`Unexpected opcode ${E.opcode}`);
31
- if (E.payloadType !== 8)
32
- throw new Error(`Unexpected payload type ${E.payloadType}`);
33
- const s = 27 + E.targetIds.length * 4;
34
- let _ = n.subarray(s, E.length);
35
- return (E.flags & J.Compressed) !== 0 && (_ = await tt(_)), _;
36
- }
37
- async function tt(t) {
38
- if (typeof DecompressionStream > "u")
39
- throw new Error("DecompressionStream not supported");
40
- const e = new DecompressionStream("gzip"), r = e.writable.getWriter(), n = new Uint8Array(t);
41
- r.write(n), r.close();
42
- const E = e.readable.getReader(), s = [];
43
- let _ = 0;
44
- for (; ; ) {
45
- const { done: N, value: d } = await E.read();
46
- if (N) break;
47
- s.push(d), _ += d.length;
48
- }
49
- const i = new Uint8Array(_);
50
- let C = 0;
51
- for (let N = 0; N < s.length; N++)
52
- i.set(s[N], C), C += s[N].length;
53
- return i;
54
- }
55
- var l = /* @__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))(l || {});
56
- const et = 161, rt = 162;
57
- new TextEncoder();
58
- const nt = new TextDecoder("utf-8", { fatal: !0 });
59
- class P {
60
- constructor(e, r, n) {
61
- this.buffer = e, this.version = r, this.offset = n, this.end = e.length - 1;
62
- }
63
- offset;
64
- end;
65
- static create(e) {
66
- const r = w(e);
67
- if (r.length < 2)
68
- throw new Error("Teleport payload too short");
69
- if (r[0] !== et || r[r.length - 1] !== rt)
70
- throw new Error("Teleport object missing markers");
71
- const n = { offset: 1 }, E = I(r, n, "InvalidLength");
72
- return new P(r, E, n.offset);
73
- }
74
- next() {
75
- if (this.offset >= this.end)
76
- return null;
77
- if (this.offset + 5 > this.buffer.length)
78
- throw new Error("Teleport object truncated");
79
- const e = it(this.buffer, this.offset);
80
- this.offset += 4;
81
- const r = this.buffer[this.offset++], n = r >> 4 & 15;
82
- if ((r & 15) !== 0)
83
- throw new Error("Teleport field flags must be zero");
84
- const E = S(n);
85
- let s;
86
- if (E >= 0)
87
- A(this.buffer, this.offset, E), s = this.buffer.subarray(this.offset, this.offset + E), this.offset += E;
88
- else {
89
- const _ = { offset: this.offset }, i = I(this.buffer, _, "InvalidLength");
90
- A(this.buffer, _.offset, i), s = this.buffer.subarray(_.offset, _.offset + i), this.offset = _.offset + i;
91
- }
92
- return new Et(e, n, s);
93
- }
94
- }
95
- class o {
96
- constructor(e, r) {
97
- this.type = e, this.payload = r;
98
- }
99
- asInt32() {
100
- return this.ensureType(
101
- 3
102
- /* Int32 */
103
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getInt32(0, !0);
104
- }
105
- asUInt32() {
106
- return this.ensureType(
107
- 5
108
- /* UInt32 */
109
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getUint32(0, !0);
110
- }
111
- asInt64() {
112
- return this.ensureType(
113
- 4
114
- /* Int64 */
115
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigInt64(0, !0);
116
- }
117
- asUInt64() {
118
- return this.ensureType(
119
- 6
120
- /* UInt64 */
121
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigUint64(0, !0);
122
- }
123
- asFloat32() {
124
- return this.ensureType(
125
- 7
126
- /* Float32 */
127
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getFloat32(0, !0);
128
- }
129
- asFloat64() {
130
- return this.ensureType(
131
- 8
132
- /* Float64 */
133
- ), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getFloat64(0, !0);
134
- }
135
- asBool() {
136
- return this.ensureType(
137
- 2
138
- /* Bool */
139
- ), this.payload.length > 0 && this.payload[0] !== 0;
140
- }
141
- asBinary() {
142
- return this.ensureType(
143
- 13
144
- /* Binary */
145
- ), this.payload;
146
- }
147
- asUtf8() {
148
- return this.ensureType(
149
- 12
150
- /* String */
151
- ), this.payload;
152
- }
153
- asString() {
154
- return this.ensureType(
155
- 12
156
- /* String */
157
- ), nt.decode(this.payload);
158
- }
159
- asGuid() {
160
- return this.ensureType(
161
- 14
162
- /* Guid */
163
- ), a.fromBytes(this.payload);
164
- }
165
- asObject() {
166
- return this.ensureType(
167
- 11
168
- /* Object */
169
- ), P.create(this.payload);
170
- }
171
- asArray() {
172
- return this.ensureType(
173
- 9
174
- /* Array */
175
- ), M.create(this.payload);
176
- }
177
- asDictionary() {
178
- return this.ensureType(
179
- 10
180
- /* Dict */
181
- ), G.create(this.payload);
182
- }
183
- ensureType(e) {
184
- if (this.type !== e)
185
- throw new Error(`Teleport value has type ${l[this.type]}, expected ${l[e]}`);
186
- }
187
- }
188
- class Et extends o {
189
- constructor(e, r, n) {
190
- super(r, n), this.fieldId = e;
191
- }
192
- get isNull() {
193
- return this.type === 1;
194
- }
195
- }
196
- class M {
197
- payload;
198
- elementType;
199
- count;
200
- offset;
201
- index = 0;
202
- constructor(e) {
203
- if (this.payload = e, e.length === 0)
204
- throw new Error("Array payload too short");
205
- const r = e[0];
206
- if (this.elementType = r >> 4 & 15, (r & 15) !== 0)
207
- throw new Error("Array flags must be zero");
208
- const n = { offset: 1 };
209
- this.count = I(e, n, "ArrayMalformed"), this.offset = n.offset;
210
- }
211
- static create(e) {
212
- return new M(w(e));
213
- }
214
- next() {
215
- if (this.index >= this.count) {
216
- if (this.offset !== this.payload.length)
217
- throw new Error("Array payload contains trailing data");
218
- return null;
219
- }
220
- const e = this.readValue();
221
- return this.index++, e;
222
- }
223
- readValue() {
224
- switch (this.elementType) {
225
- case 3:
226
- case 5:
227
- case 7:
228
- case 8:
229
- case 2:
230
- case 4:
231
- case 6:
232
- case 14: {
233
- const e = S(this.elementType);
234
- A(this.payload, this.offset, e);
235
- const r = this.payload.subarray(this.offset, this.offset + e);
236
- return this.offset += e, new L(this.elementType, r);
237
- }
238
- case 12:
239
- case 13: {
240
- const e = { offset: this.offset }, r = I(this.payload, e, "ArrayMalformed");
241
- A(this.payload, e.offset, r);
242
- const n = this.payload.subarray(e.offset, e.offset + r);
243
- return this.offset = e.offset + r, new L(this.elementType, n);
244
- }
245
- case 11: {
246
- const e = { offset: this.offset }, r = I(this.payload, e, "ArrayMalformed");
247
- A(this.payload, e.offset, r);
248
- const n = this.payload.subarray(e.offset, e.offset + r);
249
- return this.offset = e.offset + r, new L(11, n);
250
- }
251
- case 9: {
252
- const e = b(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
253
- return this.offset += e, new L(9, r);
254
- }
255
- case 10: {
256
- const e = H(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
257
- return this.offset += e, new L(10, r);
258
- }
259
- default:
260
- throw new Error(`Unsupported array element type ${l[this.elementType]}`);
261
- }
262
- }
263
- }
264
- class L extends o {
265
- constructor(e, r) {
266
- super(e, r);
267
- }
268
- }
269
- class G {
270
- payload;
271
- keyType;
272
- valueType;
273
- count;
274
- offset;
275
- index = 0;
276
- constructor(e) {
277
- if (this.payload = e, e.length < 2)
278
- throw new Error("Dictionary payload too short");
279
- if (this.keyType = e[0] >> 4 & 15, this.valueType = e[1] >> 4 & 15, (e[0] & 15) !== 0 || (e[1] & 15) !== 0)
280
- throw new Error("Dictionary key/value flags must be zero");
281
- k(this.keyType);
282
- const r = { offset: 2 };
283
- this.count = I(e, r, "DictMalformed"), this.offset = r.offset;
284
- }
285
- static create(e) {
286
- return new G(w(e));
287
- }
288
- next() {
289
- if (this.index >= this.count) {
290
- if (this.offset !== this.payload.length)
291
- throw new Error("Dictionary payload contains trailing data");
292
- return null;
293
- }
294
- const e = this.readKey(), r = this.readValue();
295
- return this.index++, new st(e, r);
296
- }
297
- readKey() {
298
- const e = S(this.keyType);
299
- if (e >= 0) {
300
- A(this.payload, this.offset, e);
301
- const r = this.payload.subarray(this.offset, this.offset + e);
302
- return this.offset += e, new o(this.keyType, r);
303
- }
304
- if (this.keyType === 12 || this.keyType === 13) {
305
- const r = { offset: this.offset }, n = I(this.payload, r, "DictMalformed");
306
- A(this.payload, r.offset, n);
307
- const E = this.payload.subarray(r.offset, r.offset + n);
308
- return this.offset = r.offset + n, new o(this.keyType, E);
309
- }
310
- throw new Error("Unsupported dictionary key type");
311
- }
312
- readValue() {
313
- switch (this.valueType) {
314
- case 12:
315
- case 13: {
316
- const e = { offset: this.offset }, r = I(this.payload, e, "DictMalformed");
317
- A(this.payload, e.offset, r);
318
- const n = this.payload.subarray(e.offset, e.offset + r);
319
- return this.offset = e.offset + r, new o(this.valueType, n);
320
- }
321
- case 11: {
322
- const e = { offset: this.offset }, r = I(this.payload, e, "DictMalformed");
323
- A(this.payload, e.offset, r);
324
- const n = this.payload.subarray(e.offset, e.offset + r);
325
- return this.offset = e.offset + r, new o(11, n);
326
- }
327
- case 9: {
328
- const e = b(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
329
- return this.offset += e, new o(9, r);
330
- }
331
- case 10: {
332
- const e = H(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
333
- return this.offset += e, new o(10, r);
334
- }
335
- case 3:
336
- case 5:
337
- case 7:
338
- case 8:
339
- case 2:
340
- case 4:
341
- case 6:
342
- case 14:
343
- case 1: {
344
- const e = S(this.valueType);
345
- A(this.payload, this.offset, e);
346
- const r = this.payload.subarray(this.offset, this.offset + e);
347
- return this.offset += e, new o(this.valueType, r);
348
- }
349
- default:
350
- throw new Error(`Unsupported dictionary value type ${l[this.valueType]}`);
351
- }
352
- }
353
- }
354
- class st {
355
- constructor(e, r) {
356
- this.key = e, this.value = r;
357
- }
358
- }
359
- class a {
360
- constructor(e) {
361
- this.bytes = e;
362
- }
363
- static fromString(e) {
364
- if (!e)
365
- throw new Error("Guid string is empty");
366
- const r = e.replace(/-/g, "");
367
- if (r.length !== 32)
368
- throw new Error("Guid string must be 32 hex characters");
369
- const n = new Uint8Array(16), E = a.parseHexSlice(r, 0, 8), s = a.parseHexSlice(r, 8, 4), _ = a.parseHexSlice(r, 12, 4);
370
- a.writeUInt32LE(n, 0, E), a.writeUInt16LE(n, 4, s), a.writeUInt16LE(n, 6, _);
371
- for (let i = 0; i < 8; i++)
372
- n[8 + i] = a.parseHexSlice(r, 16 + i * 2, 2);
373
- return new a(n);
374
- }
375
- static fromBytes(e) {
376
- if (e.length !== 16)
377
- throw new Error("Guid byte array must be 16 bytes");
378
- return new a(Uint8Array.from(e));
379
- }
380
- static createZero() {
381
- return new a(new Uint8Array(16));
382
- }
383
- static createRandom() {
384
- const e = new Uint8Array(16), r = globalThis.crypto;
385
- if (r?.getRandomValues)
386
- r.getRandomValues(e);
387
- else
388
- for (let n = 0; n < e.length; n++)
389
- e[n] = Math.floor(Math.random() * 256);
390
- return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new a(e);
391
- }
392
- toString() {
393
- const e = this.bytes;
394
- return [
395
- a.toHex(a.readUInt32LE(e, 0), 8),
396
- a.toHex(a.readUInt16LE(e, 4), 4),
397
- a.toHex(a.readUInt16LE(e, 6), 4),
398
- x(e.subarray(8, 10)),
399
- x(e.subarray(10, 16))
400
- ].join("-");
401
- }
402
- asBytes() {
403
- return this.bytes.slice();
404
- }
405
- static parseHexSlice(e, r, n) {
406
- const E = e.substr(r, n), s = Number.parseInt(E, 16);
407
- if (Number.isNaN(s))
408
- throw new Error("Guid string contains invalid characters");
409
- return s >>> 0;
410
- }
411
- static writeUInt32LE(e, r, n) {
412
- const E = n >>> 0;
413
- e[r] = E & 255, e[r + 1] = E >>> 8 & 255, e[r + 2] = E >>> 16 & 255, e[r + 3] = E >>> 24 & 255;
414
- }
415
- static writeUInt16LE(e, r, n) {
416
- const E = n & 65535;
417
- e[r] = E & 255, e[r + 1] = E >>> 8 & 255;
418
- }
419
- static readUInt32LE(e, r) {
420
- return (e[r] | e[r + 1] << 8 | e[r + 2] << 16 | e[r + 3] << 24) >>> 0;
421
- }
422
- static readUInt16LE(e, r) {
423
- return (e[r] | e[r + 1] << 8) & 65535;
424
- }
425
- static toHex(e, r) {
426
- return (e >>> 0).toString(16).padStart(r, "0");
427
- }
428
- }
429
- function I(t, e, r) {
430
- if (e.offset >= t.length)
431
- throw new Error(r);
432
- let n = 0, E = 0, s = 0;
433
- for (; e.offset < t.length; ) {
434
- const _ = t[e.offset++];
435
- if (s++, n |= (_ & 127) << E, (_ & 128) === 0) {
436
- if (s !== _t(n))
437
- throw new Error("Teleport VarUInt is not canonical");
438
- return n >>> 0;
439
- }
440
- if (E += 7, E >= 35)
441
- throw new Error("Teleport VarUInt exceeds 32-bit range");
442
- }
443
- throw new Error(r);
444
- }
445
- function _t(t) {
446
- return t < 128 ? 1 : t < 16384 ? 2 : t < 2097152 ? 3 : t < 268435456 ? 4 : 5;
447
- }
448
- function S(t) {
449
- switch (t) {
450
- case 3:
451
- case 5:
452
- case 7:
453
- return 4;
454
- case 4:
455
- case 6:
456
- case 8:
457
- return 8;
458
- case 14:
459
- return 16;
460
- case 2:
461
- return 1;
462
- case 1:
463
- return 0;
464
- default:
465
- return -1;
466
- }
467
- }
468
- function k(t) {
469
- if (t === 9 || t === 11 || t === 10 || t === 1)
470
- throw new Error("Dictionary keys must be primitive Teleport types");
471
- }
472
- function A(t, e, r) {
473
- if (e < 0 || r < 0 || e + r > t.length)
474
- throw new Error("Teleport payload exceeds bounds");
475
- }
476
- function it(t, e) {
477
- return (t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24) >>> 0;
478
- }
479
- function b(t, e) {
480
- if (e >= t.length)
481
- throw new Error("Array payload exceeds bounds");
482
- const r = t[e], n = r >> 4 & 15;
483
- if ((r & 15) !== 0)
484
- throw new Error("Array flags must be zero");
485
- const E = { offset: e + 1 }, s = I(t, E, "ArrayMalformed"), _ = S(n);
486
- if (_ >= 0) {
487
- const C = _ * s;
488
- return A(t, E.offset, C), E.offset + C - e;
489
- }
490
- let i = E.offset;
491
- for (let C = 0; C < s; C++)
492
- i = F(n, t, i, "ArrayMalformed");
493
- return i - e;
494
- }
495
- function H(t, e) {
496
- if (e + 2 > t.length)
497
- throw new Error("Dictionary payload too short");
498
- const r = t[e] >> 4 & 15, n = t[e + 1] >> 4 & 15;
499
- if ((t[e] & 15) !== 0 || (t[e + 1] & 15) !== 0)
500
- throw new Error("Dictionary key/value flags must be zero");
501
- k(r);
502
- const E = { offset: e + 2 }, s = I(t, E, "DictMalformed");
503
- let _ = E.offset;
504
- for (let i = 0; i < s; i++)
505
- _ = F(r, t, _, "DictMalformed"), _ = F(n, t, _, "DictMalformed");
506
- return _ - e;
507
- }
508
- function F(t, e, r, n) {
509
- const E = S(t);
510
- if (E >= 0)
511
- return A(e, r, E), r + E;
512
- switch (t) {
513
- case 12:
514
- case 13: {
515
- const s = { offset: r }, _ = I(e, s, n);
516
- return A(e, s.offset, _), s.offset + _;
517
- }
518
- case 11: {
519
- const s = { offset: r }, _ = I(e, s, n);
520
- return A(e, s.offset, _), s.offset + _;
521
- }
522
- case 9:
523
- return r + b(e, r);
524
- case 10:
525
- return r + H(e, r);
526
- default:
527
- throw new Error(`Unsupported Teleport type ${l[t]}`);
528
- }
529
- }
530
- function x(t) {
531
- return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
532
- }
533
- function w(t) {
534
- return t instanceof Uint8Array ? t : new Uint8Array(t);
535
- }
536
- var h = /* @__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))(h || {}), U = /* @__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.CORE_UPDATE_CLIENT_CONTEXT = 65558] = "CORE_UPDATE_CLIENT_CONTEXT", t[t.CORE_BACKGROUND_WORK_ACTIVE = 65559] = "CORE_BACKGROUND_WORK_ACTIVE", t[t.CORE_RESET_IDLE = 65560] = "CORE_RESET_IDLE", t[t.CORE_CLIENT_DISCONNECTING = 65561] = "CORE_CLIENT_DISCONNECTING", t[t.CORE_ON_APP_READY = 65562] = "CORE_ON_APP_READY", t[t.CORE_ON_FRONTEND_RELOADED = 65563] = "CORE_ON_FRONTEND_RELOADED", t[t.CORE_WEBRTC_OFFER = 65566] = "CORE_WEBRTC_OFFER", t[t.CORE_WEBRTC_ANSWER = 65567] = "CORE_WEBRTC_ANSWER", t[t.CORE_WEBRTC_ICE_CANDIDATE = 65568] = "CORE_WEBRTC_ICE_CANDIDATE", t[t.CORE_WEBRTC_READY = 65569] = "CORE_WEBRTC_READY", t[t.CORE_WEBRTC_AUDIO_SEGMENT = 65570] = "CORE_WEBRTC_AUDIO_SEGMENT", t[t.CORE_WEBRTC_TRACK_MAP = 65571] = "CORE_WEBRTC_TRACK_MAP", t[t.CORE_WEBRTC_VIDEO_CAPTURE = 65572] = "CORE_WEBRTC_VIDEO_CAPTURE", t[t.CORE_WEBRTC_ICE_SERVERS_REQUEST = 65573] = "CORE_WEBRTC_ICE_SERVERS_REQUEST", t[t.CORE_WEBRTC_ICE_SERVERS_RESPONSE = 65574] = "CORE_WEBRTC_ICE_SERVERS_RESPONSE", t[t.CORE_WEBRTC_CLOSE = 65575] = "CORE_WEBRTC_CLOSE", t[t.CORE_RELAY_AGENT_AUTH = 65576] = "CORE_RELAY_AGENT_AUTH", t[t.CORE_RELAY_AGENT_AUTH_RESULT = 65577] = "CORE_RELAY_AGENT_AUTH_RESULT", t[t.CORE_RELAY_HEARTBEAT = 65578] = "CORE_RELAY_HEARTBEAT", t[t.CORE_RELAY_TCP_CONNECTION_OPENED = 65579] = "CORE_RELAY_TCP_CONNECTION_OPENED", t[t.CORE_RELAY_TCP_CONNECTION_CLOSED = 65580] = "CORE_RELAY_TCP_CONNECTION_CLOSED", t[t.CORE_RELAY_TCP_DATA = 65581] = "CORE_RELAY_TCP_DATA", t[t.CORE_RELAY_UDP_DATA = 65582] = "CORE_RELAY_UDP_DATA", t[t.CORE_RELAY_ADD_TUNNEL = 65583] = "CORE_RELAY_ADD_TUNNEL", t[t.CORE_RELAY_TUNNEL_ADDED = 65584] = "CORE_RELAY_TUNNEL_ADDED", t[t.CORE_RELAY_REMOVE_TUNNEL = 65585] = "CORE_RELAY_REMOVE_TUNNEL", t[t.CORE_IKON_SERVER_ENDPOINT_HOST_INFO = 65586] = "CORE_IKON_SERVER_ENDPOINT_HOST_INFO", t[t.CORE_CLIENT_INITIALIZATION = 65587] = "CORE_CLIENT_INITIALIZATION", t[t.CORE_CLIENT_LIFECYCLE_BATCH = 65588] = "CORE_CLIENT_LIFECYCLE_BATCH", t[t.CORE_APP_CONFIG = 65589] = "CORE_APP_CONFIG", 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.ANALYTICS_IKON_RELAY_SERVER_STATS = 524297] = "ANALYTICS_IKON_RELAY_SERVER_STATS", t[t.ANALYTICS_IKON_TURN_SERVER_STATS = 524298] = "ANALYTICS_IKON_TURN_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_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_SPEECH_RECOGNIZED = 1048615] = "ACTION_SPEECH_RECOGNIZED", t[t.ACTION_CALL_RESULT = 1048616] = "ACTION_CALL_RESULT", t[t.ACTION_DOWNLOAD = 1048618] = "ACTION_DOWNLOAD", t[t.ACTION_PLAY_SOUND = 1048621] = "ACTION_PLAY_SOUND", 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_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.ACTION_FILE_UPLOAD_CALLBACK = 1048640] = "ACTION_FILE_UPLOAD_CALLBACK", t[t.ACTION_CUSTOM_USER_MESSAGE = 1048641] = "ACTION_CUSTOM_USER_MESSAGE", t[t.ACTION_URL_CHANGED = 1048642] = "ACTION_URL_CHANGED", t[t.ACTION_FILE_UPLOAD_PRE_START2 = 1048643] = "ACTION_FILE_UPLOAD_PRE_START2", t[t.ACTION_FILE_UPLOAD_PRE_START_RESPONSE2 = 1048644] = "ACTION_FILE_UPLOAD_PRE_START_RESPONSE2", t[t.ACTION_FILE_UPLOAD_START2 = 1048645] = "ACTION_FILE_UPLOAD_START2", t[t.ACTION_FILE_UPLOAD_START_RESPONSE2 = 1048646] = "ACTION_FILE_UPLOAD_START_RESPONSE2", t[t.ACTION_FILE_UPLOAD_DATA2 = 1048647] = "ACTION_FILE_UPLOAD_DATA2", t[t.ACTION_FILE_UPLOAD_ACK2 = 1048648] = "ACTION_FILE_UPLOAD_ACK2", t[t.ACTION_FILE_UPLOAD_END2 = 1048649] = "ACTION_FILE_UPLOAD_END2", t[t.ACTION_FILE_UPLOAD_COMPLETE2 = 1048650] = "ACTION_FILE_UPLOAD_COMPLETE2", t[t.ACTION_FUNCTION_ENUMERATION_ITEM_BATCH = 1048651] = "ACTION_FUNCTION_ENUMERATION_ITEM_BATCH", t[t.ACTION_CALL_ACK = 1048652] = "ACTION_CALL_ACK", t[t.ACTION_TRIGGER_CRON = 1048653] = "ACTION_TRIGGER_CRON", t[t.ACTION_RESULT = 1048654] = "ACTION_RESULT", t[t.UI_RESYNC_REQUEST = 1048655] = "UI_RESYNC_REQUEST", 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_STYLES = 2097188] = "UI_STYLES", t[t.UI_UPDATE = 2097190] = "UI_UPDATE", 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.AUDIO_SHAPE_FRAME = 4194310] = "AUDIO_SHAPE_FRAME", 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.GROUP_APP_LOCAL = 1073741824] = "GROUP_APP_LOCAL", t[t.CONSTANT_GROUP_MASK = 2147418112] = "CONSTANT_GROUP_MASK", t))(U || {});
537
- const at = 8388611, At = 271275304, It = 2541432218, Tt = 2986785889, Ct = 3105403172, ot = 3456383222;
538
- function Nt(t) {
539
- const e = {};
540
- return z(e), e;
541
- }
542
- function z(t) {
543
- return t.Data = new Uint8Array(0), t.FrameNumber = 0, t.IsKey = !1, t.TimestampInUs = 0n, t.DurationInUs = 0, t;
544
- }
545
- function Rt(t, e) {
546
- const r = P.create(t);
547
- return ft(r, e);
548
- }
549
- function ft(t, e) {
550
- const r = e ?? Nt();
551
- return z(r), ut(t, r), r;
552
- }
553
- function ut(t, e) {
554
- let r;
555
- for (; (r = t.next()) !== null; )
556
- switch (r.fieldId) {
557
- case At: {
558
- if (r.isNull) throw new Error();
559
- e.TimestampInUs = r.asUInt64();
560
- break;
561
- }
562
- case It: {
563
- if (r.isNull) throw new Error();
564
- e.DurationInUs = r.asUInt32();
565
- break;
566
- }
567
- case Tt: {
568
- if (r.isNull) throw new Error();
569
- e.Data = r.asBinary();
570
- break;
571
- }
572
- case Ct: {
573
- if (r.isNull) throw new Error();
574
- e.IsKey = r.asBool();
575
- break;
576
- }
577
- case ot: {
578
- if (r.isNull) throw new Error();
579
- e.FrameNumber = r.asInt32();
580
- break;
581
- }
582
- }
583
- }
584
- async function ht(t, e) {
585
- const r = await W(t, at);
586
- return Rt(r, e);
587
- }
588
- const ct = 8388609, lt = 161083277, St = 164808083, Dt = 1368629611, Lt = 2514959030, Ut = 2745379226, Ot = 2950031986, yt = 3282782683, Pt = 3284746250, wt = 4065070594;
589
- function gt(t) {
590
- const e = {};
591
- return X(e), e;
592
- }
593
- function X(t) {
594
- return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = h.H264, t.CodecDetails = "", t.Width = 0, t.Height = 0, t.Framerate = 30, t.CorrelationId = void 0, t;
595
- }
596
- function dt(t, e) {
597
- const r = P.create(t);
598
- return mt(r, e);
599
- }
600
- function mt(t, e) {
601
- const r = e ?? gt();
602
- return X(r), Ft(t, r), r;
603
- }
604
- function Ft(t, e) {
605
- let r;
606
- for (; (r = t.next()) !== null; )
607
- switch (r.fieldId) {
608
- case lt: {
609
- if (r.isNull) throw new Error();
610
- e.StreamId = r.asString();
611
- break;
612
- }
613
- case St: {
614
- if (r.isNull) throw new Error();
615
- e.Framerate = r.asFloat64();
616
- break;
617
- }
618
- case Dt: {
619
- if (r.isNull) throw new Error();
620
- e.Description = r.asString();
621
- break;
622
- }
623
- case Lt: {
624
- if (r.isNull) {
625
- e.CorrelationId = void 0;
626
- break;
627
- }
628
- e.CorrelationId = r.asString();
629
- break;
630
- }
631
- case Ut: {
632
- if (r.isNull) throw new Error();
633
- e.CodecDetails = r.asString();
634
- break;
635
- }
636
- case Ot: {
637
- if (r.isNull) throw new Error();
638
- e.Height = r.asInt32();
639
- break;
640
- }
641
- case yt: {
642
- if (r.isNull) throw new Error();
643
- e.SourceType = r.asString();
644
- break;
645
- }
646
- case Pt: {
647
- if (r.isNull) throw new Error();
648
- e.Codec = r.asInt32();
649
- break;
650
- }
651
- case wt: {
652
- if (r.isNull) throw new Error();
653
- e.Width = r.asInt32();
654
- break;
655
- }
656
- }
657
- }
658
- async function Vt(t, e) {
659
- const r = await W(t, ct);
660
- return dt(r, e);
661
- }
662
- const Mt = "avc1.42E01E", Gt = "vp8", bt = "vp09.00.10.08", Ht = "av01.0.04M.08", Bt = 8, D = (t, e) => self.postMessage(t, e ?? []);
663
- let c = null, y = !0, $ = !1;
664
- const T = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
665
- function u(t) {
666
- const e = t instanceof Error ? t : new Error(String(t));
667
- D({ type: "error", error: { name: e.name, message: e.message, stack: e.stack } });
668
- }
669
- function g(t, e) {
670
- return t << 16 | e & 65535;
671
- }
672
- function V(t) {
673
- const e = T.get(t);
674
- if (e)
675
- return e;
676
- const r = {
677
- streamId: t,
678
- numericKey: 0,
679
- watched: !1,
680
- surface: null,
681
- ctx2d: null,
682
- codec: null,
683
- width: 0,
684
- height: 0,
685
- framerate: 0,
686
- decoder: null,
687
- decoderCodec: null,
688
- decoderWidth: 0,
689
- decoderHeight: 0,
690
- isKeyFrameRequired: !0,
691
- isReconfiguring: !1,
692
- pendingDecodeCount: 0
693
- };
694
- return T.set(t, r), r;
695
- }
696
- function v(t) {
697
- if (t === h.H264) return Mt;
698
- if (t === h.Vp8) return Gt;
699
- if (t === h.Vp9) return bt;
700
- if (t === h.Av1) return Ht;
701
- throw new Error(`Unknown codec: ${t}`);
702
- }
703
- function f(t) {
704
- const e = T.get(t);
705
- if (!e || e.numericKey === 0)
706
- return;
707
- const r = e.numericKey >> 16 & 65535, n = e.numericKey & 65535;
708
- D({ type: "requestIdr", streamId: t, senderId: r, trackId: n });
709
- }
710
- async function Kt(t, e) {
711
- try {
712
- if (!y || !t.watched)
713
- return;
714
- if (typeof createImageBitmap == "function") {
715
- const r = await createImageBitmap(e);
716
- D({ type: "frame", streamId: t.streamId, width: t.width, height: t.height, bitmap: r }, [r]);
717
- }
718
- } catch (r) {
719
- u(r);
720
- } finally {
721
- t.pendingDecodeCount--;
722
- try {
723
- e.close();
724
- } catch {
725
- }
726
- }
727
- }
728
- async function Yt(t, e, r) {
729
- const n = {
730
- codec: t,
731
- codedWidth: e > 0 ? e : void 0,
732
- codedHeight: r > 0 ? r : void 0,
733
- optimizeForLatency: !0
734
- };
735
- if (typeof VideoDecoder?.isConfigSupported != "function")
736
- return { config: { ...n, hardwareAcceleration: "prefer-hardware" }, isHardwareAccelerated: !0 };
737
- const E = { ...n, hardwareAcceleration: "prefer-hardware" };
738
- try {
739
- const s = await VideoDecoder.isConfigSupported(E);
740
- if (s.supported)
741
- return { config: s.config ?? E, isHardwareAccelerated: !0 };
742
- } catch {
743
- }
744
- try {
745
- const s = await VideoDecoder.isConfigSupported(n);
746
- if (s.supported)
747
- return { config: s.config ?? n, isHardwareAccelerated: !1 };
748
- } catch {
749
- }
750
- return null;
751
- }
752
- function m(t) {
753
- return new VideoDecoder({
754
- output: (e) => {
755
- if (t.pendingDecodeCount++, !y || !t.watched) {
756
- t.pendingDecodeCount--;
757
- try {
758
- e.close();
759
- } catch {
760
- }
761
- return;
762
- }
763
- if (t.pendingDecodeCount > Bt) {
764
- t.pendingDecodeCount--;
765
- try {
766
- e.close();
767
- } catch {
768
- }
769
- return;
770
- }
771
- const r = t.width, n = t.height;
772
- if (t.ctx2d && t.surface) {
773
- try {
774
- t.ctx2d.drawImage(e, 0, 0, r, n);
775
- } catch (E) {
776
- u(E);
777
- } finally {
778
- t.pendingDecodeCount--;
779
- try {
780
- e.close();
781
- } catch {
782
- }
783
- }
784
- return;
785
- }
786
- Kt(t, e);
787
- },
788
- error: (e) => {
789
- if (u(e), t.isKeyFrameRequired = !0, t.isReconfiguring = !0, t.decoder && t.decoder.state !== "closed")
790
- try {
791
- t.decoder.close();
792
- } catch {
793
- }
794
- f(t.streamId);
795
- }
796
- });
797
- }
798
- async function O(t) {
799
- if (t.codec == null || $) {
800
- t.isReconfiguring = !1;
801
- return;
802
- }
803
- const e = v(t.codec);
804
- (!t.decoder || t.decoder.state === "closed") && (t.decoder && (t.decoderCodec = null, t.decoderWidth = 0, t.decoderHeight = 0), t.decoder = m(t));
805
- const r = t.decoderCodec !== null && t.decoderCodec !== e;
806
- if (!(t.decoderCodec !== e || t.decoderWidth !== t.width || t.decoderHeight !== t.height)) {
807
- t.isReconfiguring = !1;
808
- return;
809
- }
810
- if (t.isReconfiguring = !0, t.decoderCodec = null, r && t.decoder) {
811
- try {
812
- t.decoder.close();
813
- } catch {
814
- }
815
- t.decoder = m(t);
816
- }
817
- try {
818
- const E = await Yt(e, t.width, t.height);
819
- if (v(t.codec) !== e) {
820
- if (t.decoder && t.decoder.state !== "closed")
821
- try {
822
- t.decoder.close();
823
- } catch {
824
- }
825
- t.decoder = null, t.decoderCodec = null, t.decoderWidth = 0, t.decoderHeight = 0;
826
- return;
827
- }
828
- if (!E) {
829
- u(new Error(`Decoder not supported for codec ${e}`));
830
- return;
831
- }
832
- (!t.decoder || t.decoder.state === "closed") && (t.decoder = m(t)), t.decoderCodec = e, t.decoderWidth = t.width, t.decoderHeight = t.height;
833
- try {
834
- t.decoder.configure(E.config), t.isKeyFrameRequired = !0, f(t.streamId);
835
- const _ = E.isHardwareAccelerated ? "hardware" : "software", i = t.framerate > 0 ? `@${Math.round(t.framerate)}fps` : "";
836
- D({ type: "debug", message: `Decoder configured: codec=${e}, ${t.width}x${t.height}${i}, hw=${_}` });
837
- } catch (_) {
838
- u(_);
839
- }
840
- 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);
841
- } finally {
842
- t.isReconfiguring = !1;
843
- }
844
- }
845
- async function xt(t, e) {
846
- const r = await Vt(t), n = r.StreamId, E = g(e.senderId, e.trackId), s = V(n);
847
- s.numericKey = E, s.codec = r.Codec, s.width = r.Width, s.height = r.Height, s.framerate = r.Framerate, R.set(E, n), D({ type: "streamBegin", streamId: n, width: r.Width, height: r.Height, codec: r.Codec }), s.watched ? (s.surface && s.ctx2d && r.Width > 0 && r.Height > 0 && (s.surface.width !== r.Width || s.surface.height !== r.Height) && (s.surface.width = r.Width, s.surface.height = r.Height), O(s)) : s.isReconfiguring = !1;
848
- }
849
- function vt(t) {
850
- const e = g(t.senderId, t.trackId), r = R.get(e);
851
- if (!r)
852
- return;
853
- D({ type: "streamEnd", streamId: r });
854
- const n = T.get(r);
855
- if (!n) {
856
- R.delete(e);
857
- return;
858
- }
859
- if (n.decoder)
860
- try {
861
- n.decoder.close();
862
- } catch {
863
- }
864
- T.delete(r), R.delete(e);
865
- }
866
- function q(t) {
867
- const e = T.get(t);
868
- e && (e.surface = null, e.ctx2d = null);
869
- }
870
- function Q(t) {
871
- const e = T.get(t);
872
- if (e) {
873
- if (e.watched = !1, e.isKeyFrameRequired = !0, q(t), e.decoder) {
874
- try {
875
- e.decoder.close();
876
- } catch {
877
- }
878
- e.decoder = null, e.decoderCodec = null, e.decoderWidth = 0, e.decoderHeight = 0;
879
- }
880
- e.isReconfiguring = !1;
881
- }
882
- }
883
- async function Wt(t, e) {
884
- const r = g(e.senderId, e.trackId), n = R.get(r);
885
- if (!n)
886
- return;
887
- const E = T.get(n);
888
- if (!E || !y || !E.watched || E.isReconfiguring || ((!E.decoder || !E.decoderCodec) && O(E), !E.decoder || !E.decoderCodec))
889
- return;
890
- const s = await ht(t);
891
- if (!(E.isReconfiguring || !E.decoder || !E.decoderCodec) && E.decoder.state !== "closed") {
892
- if (E.isKeyFrameRequired) {
893
- if (!s.IsKey)
894
- return;
895
- E.isKeyFrameRequired = !1;
896
- }
897
- try {
898
- if (E.decoder.state === "closed")
899
- return;
900
- E.decoder.decode(
901
- new EncodedVideoChunk({
902
- type: s.IsKey ? "key" : "delta",
903
- timestamp: Number(s.TimestampInUs),
904
- duration: s.DurationInUs,
905
- data: s.Data
906
- })
907
- );
908
- } catch (_) {
909
- if (_ instanceof DOMException && _.message.includes("closed"))
910
- return;
911
- E.isKeyFrameRequired = !0, f(E.streamId), u(_);
912
- }
913
- }
914
- }
915
- function kt(t) {
916
- const e = g(t.senderId, t.trackId), r = R.get(e);
917
- if (!r)
918
- return;
919
- const n = T.get(r);
920
- n && (n.isKeyFrameRequired = !0, n.watched && f(n.streamId));
921
- }
922
- function zt(t, e) {
923
- switch (e.opcode) {
924
- case U.VIDEO_STREAM_BEGIN: {
925
- const r = g(e.senderId, e.trackId), n = R.get(r);
926
- if (n) {
927
- const E = T.get(n);
928
- E && (E.isReconfiguring = !0);
929
- }
930
- xt(t, e);
931
- return;
932
- }
933
- case U.VIDEO_STREAM_END:
934
- vt(e);
935
- return;
936
- case U.VIDEO_FRAME:
937
- Wt(t, e);
938
- return;
939
- case U.VIDEO_INVALIDATE_FRAME:
940
- kt(e);
941
- return;
942
- default:
943
- return;
944
- }
945
- }
946
- function j() {
947
- if (c) {
948
- try {
949
- c.close();
950
- } catch {
951
- }
952
- c = null;
953
- }
954
- }
955
- function Xt() {
956
- j();
957
- for (const t of T.values())
958
- Q(t.streamId);
959
- T.clear(), R.clear();
960
- }
961
- self.addEventListener("message", (t) => {
962
- const e = t.data;
963
- if (e.type === "configure") {
964
- $ = e.webRtcEnabled ?? !1;
965
- return;
966
- }
967
- if (e.type === "attachSurface") {
968
- const r = e.streamId, n = V(r);
969
- n.watched = !0, n.surface = e.canvas;
970
- try {
971
- n.ctx2d = n.surface.getContext("2d", { alpha: !1, desynchronized: !0 });
972
- } catch (E) {
973
- u(E), n.ctx2d = null;
974
- }
975
- n.isKeyFrameRequired = !0, O(n), f(r);
976
- return;
977
- }
978
- if (e.type === "detachSurface") {
979
- q(e.streamId);
980
- return;
981
- }
982
- if (e.type === "attachProtocolPort") {
983
- j(), c = e.port, c.addEventListener("message", (r) => {
984
- const n = r.data;
985
- n?.type === "protocol" && n.message instanceof ArrayBuffer && n.headers && zt(new Uint8Array(n.message), n.headers);
986
- }), c.start?.();
987
- return;
988
- }
989
- if (e.type === "watchStream") {
990
- const r = V(e.streamId);
991
- r.watched = !0, r.isKeyFrameRequired = !0, O(r), f(r.streamId);
992
- return;
993
- }
994
- if (e.type === "unwatchStream") {
995
- Q(e.streamId);
996
- return;
997
- }
998
- if (e.type === "setEnabled") {
999
- if (y = e.enabled, y)
1000
- for (const r of T.values())
1001
- r.watched && (r.isKeyFrameRequired = !0, O(r), f(r.streamId));
1002
- return;
1003
- }
1004
- e.type === "dispose" && Xt();
1005
- });