@ikonai/sdk 0.0.28 → 0.0.29

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 (32) hide show
  1. package/assets/audio-capture-worker-fxRKlQJF.js +932 -0
  2. package/assets/audio-playback-worker-C4Eyhfrh.js +1323 -0
  3. package/assets/protocol-worker-E7o-6_bZ.js +1422 -0
  4. package/assets/video-capture-worker-CTRX9PKp.js +843 -0
  5. package/assets/video-playback-worker-CIuL9Crw.js +875 -0
  6. package/channel/channel-manager.d.ts +1 -1
  7. package/channel/channel.d.ts +1 -1
  8. package/client/endpoint-selector.d.ts +1 -1
  9. package/client/ikon-client-config.d.ts +4 -9
  10. package/client/ikon-client.d.ts +5 -1
  11. package/connection/authenticator.d.ts +1 -1
  12. package/functions/function-registry.d.ts +1 -1
  13. package/functions/index.d.ts +1 -1
  14. package/functions/types.d.ts +1 -1
  15. package/index.d.ts +8 -8
  16. package/index.js +3878 -15843
  17. package/media/audio-constants.d.ts +20 -0
  18. package/media/ikon-audio-playback.d.ts +1 -1
  19. package/media/ikon-video-playback.d.ts +0 -8
  20. package/package.json +2 -1
  21. package/transport/transport.d.ts +1 -1
  22. package/transport/web-socket-transport.d.ts +6 -1
  23. package/transport/web-transport-transport.d.ts +17 -2
  24. package/{media/audio-worker-messages.d.ts → worker/audio-playback-worker.d.ts} +10 -10
  25. package/worker/video-playback-worker.d.ts +59 -0
  26. package/assets/audio-capture-worker-C5hNMTF7.js +0 -14835
  27. package/assets/audio-worker-Ci3tYX2B.js +0 -15121
  28. package/assets/protocol-worker-DXLojSe-.js +0 -15288
  29. package/assets/video-capture-worker-OBl3bsvx.js +0 -14733
  30. package/assets/video-worker-BoOfB8qz.js +0 -14761
  31. package/worker/audio-worker.d.ts +0 -1
  32. package/worker/video-worker.d.ts +0 -1
@@ -0,0 +1,932 @@
1
+ function U(e, t, r, i, n) {
2
+ const s = n?.trackId ?? 0, o = n?.sequenceId ?? 0, d = n?.flags ?? 0, c = n?.targetIds ?? [], g = n?.payloadType ?? 8, V = 27 + c.length * 4, O = V + t.length, D = new Uint8Array(O), u = new DataView(D.buffer);
3
+ u.setUint32(0, O, !0), u.setUint32(4, e >>> 0, !0), u.setUint32(8, i >>> 0, !0), u.setUint32(12, s >>> 0, !0), u.setUint32(16, o >>> 0, !0), u.setUint32(20, c.length >>> 0, !0), u.setUint8(24, r & 255), u.setUint8(25, g & 255), u.setUint8(26, d & 255);
4
+ let L = 27;
5
+ for (let B = 0; B < c.length; B++)
6
+ u.setUint32(L, c[B] >>> 0, !0), L += 4;
7
+ return D.set(t, V), D;
8
+ }
9
+ var w = /* @__PURE__ */ ((e) => (e[e.Null = 1] = "Null", e[e.Bool = 2] = "Bool", e[e.Int32 = 3] = "Int32", e[e.Int64 = 4] = "Int64", e[e.UInt32 = 5] = "UInt32", e[e.UInt64 = 6] = "UInt64", e[e.Float32 = 7] = "Float32", e[e.Float64 = 8] = "Float64", e[e.Array = 9] = "Array", e[e.Dict = 10] = "Dict", e[e.Object = 11] = "Object", e[e.String = 12] = "String", e[e.Binary = 13] = "Binary", e[e.Guid = 14] = "Guid", e))(w || {});
10
+ const C = 161, K = 162, E = new TextEncoder();
11
+ new TextDecoder("utf-8", { fatal: !0 });
12
+ class y {
13
+ constructor(t = 1) {
14
+ this.version = t, this.buffer.writeByte(C), this.buffer.writeVarUInt(t >>> 0);
15
+ }
16
+ buffer = new p();
17
+ closed = !1;
18
+ cached;
19
+ writeInt32Field(t, r) {
20
+ this.writeFixedField(t, 3, () => this.buffer.writeInt32(r | 0));
21
+ }
22
+ writeUInt32Field(t, r) {
23
+ this.writeFixedField(t, 5, () => this.buffer.writeUInt32(r >>> 0));
24
+ }
25
+ writeInt64Field(t, r) {
26
+ this.writeFixedField(t, 4, () => this.buffer.writeBigInt64(r));
27
+ }
28
+ writeUInt64Field(t, r) {
29
+ this.writeFixedField(t, 6, () => this.buffer.writeBigUInt64(r));
30
+ }
31
+ writeFloat32Field(t, r) {
32
+ this.writeFixedField(t, 7, () => this.buffer.writeFloat32(r));
33
+ }
34
+ writeFloat64Field(t, r) {
35
+ this.writeFixedField(t, 8, () => this.buffer.writeFloat64(r));
36
+ }
37
+ writeBoolField(t, r) {
38
+ this.writeFixedField(t, 2, () => this.buffer.writeByte(r ? 1 : 0));
39
+ }
40
+ writeGuidField(t, r) {
41
+ const i = r instanceof a ? r.asBytes() : r;
42
+ if (i.length !== 16)
43
+ throw new Error("Guid payload must be 16 bytes");
44
+ this.writeFixedField(t, 14, () => this.buffer.writeBytes(i));
45
+ }
46
+ writeStringField(t, r) {
47
+ const i = E.encode(r ?? "");
48
+ this.writeVariableField(t, 12, i);
49
+ }
50
+ writeBinaryField(t, r) {
51
+ this.writeVariableField(t, 13, r);
52
+ }
53
+ writeObjectField(t, r, i) {
54
+ const n = new y(r);
55
+ i(n);
56
+ const s = n.finish();
57
+ this.writeVariableField(t, 11, s);
58
+ }
59
+ writeArrayField(t, r, i) {
60
+ const n = new b(r);
61
+ i(n);
62
+ const s = n.finish();
63
+ this.writeVariableField(t, 9, s);
64
+ }
65
+ writeDictionaryField(t, r, i, n) {
66
+ const s = new _(r, i);
67
+ n(s);
68
+ const o = s.finish();
69
+ this.writeVariableField(t, 10, o);
70
+ }
71
+ finish() {
72
+ return this.closed || (this.buffer.writeByte(K), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
73
+ }
74
+ writeFixedField(t, r, i) {
75
+ this.writeFieldHeader(t, r, 0), i();
76
+ }
77
+ writeVariableField(t, r, i) {
78
+ this.writeFieldHeader(t, r, i.length), this.buffer.writeBytes(i);
79
+ }
80
+ writeFieldHeader(t, r, i) {
81
+ this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(F(r)), z(r) && this.buffer.writeVarUInt(i >>> 0);
82
+ }
83
+ }
84
+ class b {
85
+ constructor(t) {
86
+ this.elementType = t;
87
+ }
88
+ payload = new p();
89
+ count = 0;
90
+ writeInt32(t) {
91
+ this.ensureElementType(
92
+ 3
93
+ /* Int32 */
94
+ ), this.count++, this.payload.writeInt32(t | 0);
95
+ }
96
+ writeUInt32(t) {
97
+ this.ensureElementType(
98
+ 5
99
+ /* UInt32 */
100
+ ), this.count++, this.payload.writeUInt32(t >>> 0);
101
+ }
102
+ writeInt64(t) {
103
+ this.ensureElementType(
104
+ 4
105
+ /* Int64 */
106
+ ), this.count++, this.payload.writeBigInt64(t);
107
+ }
108
+ writeUInt64(t) {
109
+ this.ensureElementType(
110
+ 6
111
+ /* UInt64 */
112
+ ), this.count++, this.payload.writeBigUInt64(t);
113
+ }
114
+ writeFloat32(t) {
115
+ this.ensureElementType(
116
+ 7
117
+ /* Float32 */
118
+ ), this.count++, this.payload.writeFloat32(t);
119
+ }
120
+ writeFloat64(t) {
121
+ this.ensureElementType(
122
+ 8
123
+ /* Float64 */
124
+ ), this.count++, this.payload.writeFloat64(t);
125
+ }
126
+ writeBool(t) {
127
+ this.ensureElementType(
128
+ 2
129
+ /* Bool */
130
+ ), this.count++, this.payload.writeByte(t ? 1 : 0);
131
+ }
132
+ writeGuid(t) {
133
+ this.ensureElementType(
134
+ 14
135
+ /* Guid */
136
+ ), this.count++;
137
+ const r = t instanceof a ? t.asBytes() : t;
138
+ if (r.length !== 16)
139
+ throw new Error("Guid payload must be 16 bytes");
140
+ this.payload.writeBytes(r);
141
+ }
142
+ writeString(t) {
143
+ this.ensureElementType(
144
+ 12
145
+ /* String */
146
+ ), this.count++;
147
+ const r = E.encode(t ?? "");
148
+ this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
149
+ }
150
+ writeBinary(t) {
151
+ this.ensureElementType(
152
+ 13
153
+ /* Binary */
154
+ ), this.count++, this.payload.writeVarUInt(t.length), this.payload.writeBytes(t);
155
+ }
156
+ writeObject(t, r) {
157
+ this.ensureElementType(
158
+ 11
159
+ /* Object */
160
+ ), this.count++;
161
+ const i = new y(t);
162
+ r(i);
163
+ const n = i.finish();
164
+ this.payload.writeVarUInt(n.length), this.payload.writeBytes(n);
165
+ }
166
+ writeArray(t, r) {
167
+ this.ensureElementType(
168
+ 9
169
+ /* Array */
170
+ ), this.count++;
171
+ const i = new b(t);
172
+ r(i);
173
+ const n = i.finish();
174
+ this.payload.writeBytes(n);
175
+ }
176
+ writeDictionary(t, r, i) {
177
+ this.ensureElementType(
178
+ 10
179
+ /* Dict */
180
+ ), this.count++;
181
+ const n = new _(t, r);
182
+ i(n);
183
+ const s = n.finish();
184
+ this.payload.writeBytes(s);
185
+ }
186
+ finish() {
187
+ const t = new p();
188
+ return t.writeByte(F(this.elementType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
189
+ }
190
+ ensureElementType(t) {
191
+ if (this.elementType !== t)
192
+ throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[t]}`);
193
+ }
194
+ }
195
+ class _ {
196
+ constructor(t, r) {
197
+ this.keyType = t, this.valueType = r, j(t);
198
+ }
199
+ payload = new p();
200
+ count = 0;
201
+ entryOpen = !1;
202
+ beginEntry() {
203
+ if (this.entryOpen)
204
+ throw new Error("Previous dictionary entry not completed");
205
+ return this.count++, this.entryOpen = !0, new H(this.keyType, this.valueType, this.payload, () => {
206
+ this.entryOpen = !1;
207
+ });
208
+ }
209
+ finish() {
210
+ if (this.entryOpen)
211
+ throw new Error("Dictionary entry not completed");
212
+ const t = new p();
213
+ return t.writeByte(F(this.keyType)), t.writeByte(F(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
214
+ }
215
+ }
216
+ class H {
217
+ constructor(t, r, i, n) {
218
+ this.keyType = t, this.valueType = r, this.payload = i, this.onComplete = n;
219
+ }
220
+ keyWritten = !1;
221
+ valueWritten = !1;
222
+ completed = !1;
223
+ writeKeyInt32(t) {
224
+ this.ensureKeyType(
225
+ 3
226
+ /* Int32 */
227
+ ), this.payload.writeInt32(t | 0), this.keyWritten = !0;
228
+ }
229
+ writeKeyUInt32(t) {
230
+ this.ensureKeyType(
231
+ 5
232
+ /* UInt32 */
233
+ ), this.payload.writeUInt32(t >>> 0), this.keyWritten = !0;
234
+ }
235
+ writeKeyInt64(t) {
236
+ this.ensureKeyType(
237
+ 4
238
+ /* Int64 */
239
+ ), this.payload.writeBigInt64(t), this.keyWritten = !0;
240
+ }
241
+ writeKeyUInt64(t) {
242
+ this.ensureKeyType(
243
+ 6
244
+ /* UInt64 */
245
+ ), this.payload.writeBigUInt64(t), this.keyWritten = !0;
246
+ }
247
+ writeKeyFloat32(t) {
248
+ this.ensureKeyType(
249
+ 7
250
+ /* Float32 */
251
+ ), this.payload.writeFloat32(t), this.keyWritten = !0;
252
+ }
253
+ writeKeyFloat64(t) {
254
+ this.ensureKeyType(
255
+ 8
256
+ /* Float64 */
257
+ ), this.payload.writeFloat64(t), this.keyWritten = !0;
258
+ }
259
+ writeKeyBool(t) {
260
+ this.ensureKeyType(
261
+ 2
262
+ /* Bool */
263
+ ), this.payload.writeByte(t ? 1 : 0), this.keyWritten = !0;
264
+ }
265
+ writeKeyGuid(t) {
266
+ this.ensureKeyType(
267
+ 14
268
+ /* Guid */
269
+ );
270
+ const r = t instanceof a ? t.asBytes() : t;
271
+ if (r.length !== 16)
272
+ throw new Error("Guid payload must be 16 bytes");
273
+ this.payload.writeBytes(r), this.keyWritten = !0;
274
+ }
275
+ writeKeyString(t) {
276
+ this.ensureKeyType(
277
+ 12
278
+ /* String */
279
+ );
280
+ const r = E.encode(t ?? "");
281
+ this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
282
+ }
283
+ writeKeyBinary(t) {
284
+ this.ensureKeyType(
285
+ 13
286
+ /* Binary */
287
+ ), this.payload.writeVarUInt(t.length), this.payload.writeBytes(t), this.keyWritten = !0;
288
+ }
289
+ writeValueInt32(t) {
290
+ this.ensureValueType(
291
+ 3
292
+ /* Int32 */
293
+ ), this.payload.writeInt32(t | 0), this.valueWritten = !0;
294
+ }
295
+ writeValueUInt32(t) {
296
+ this.ensureValueType(
297
+ 5
298
+ /* UInt32 */
299
+ ), this.payload.writeUInt32(t >>> 0), this.valueWritten = !0;
300
+ }
301
+ writeValueInt64(t) {
302
+ this.ensureValueType(
303
+ 4
304
+ /* Int64 */
305
+ ), this.payload.writeBigInt64(t), this.valueWritten = !0;
306
+ }
307
+ writeValueUInt64(t) {
308
+ this.ensureValueType(
309
+ 6
310
+ /* UInt64 */
311
+ ), this.payload.writeBigUInt64(t), this.valueWritten = !0;
312
+ }
313
+ writeValueFloat32(t) {
314
+ this.ensureValueType(
315
+ 7
316
+ /* Float32 */
317
+ ), this.payload.writeFloat32(t), this.valueWritten = !0;
318
+ }
319
+ writeValueFloat64(t) {
320
+ this.ensureValueType(
321
+ 8
322
+ /* Float64 */
323
+ ), this.payload.writeFloat64(t), this.valueWritten = !0;
324
+ }
325
+ writeValueBool(t) {
326
+ this.ensureValueType(
327
+ 2
328
+ /* Bool */
329
+ ), this.payload.writeByte(t ? 1 : 0), this.valueWritten = !0;
330
+ }
331
+ writeValueGuid(t) {
332
+ this.ensureValueType(
333
+ 14
334
+ /* Guid */
335
+ );
336
+ const r = t instanceof a ? t.asBytes() : t;
337
+ if (r.length !== 16)
338
+ throw new Error("Guid payload must be 16 bytes");
339
+ this.payload.writeBytes(r), this.valueWritten = !0;
340
+ }
341
+ writeNullValue() {
342
+ this.ensureValueType(
343
+ 1
344
+ /* Null */
345
+ ), this.valueWritten = !0;
346
+ }
347
+ writeValueBinary(t) {
348
+ this.ensureValueType(
349
+ 13
350
+ /* Binary */
351
+ ), this.payload.writeVarUInt(t.length), this.payload.writeBytes(t), this.valueWritten = !0;
352
+ }
353
+ writeValueString(t) {
354
+ this.ensureValueType(
355
+ 12
356
+ /* String */
357
+ );
358
+ const r = E.encode(t ?? "");
359
+ this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
360
+ }
361
+ writeValueObject(t, r) {
362
+ this.ensureValueType(
363
+ 11
364
+ /* Object */
365
+ );
366
+ const i = new y(t);
367
+ r(i);
368
+ const n = i.finish();
369
+ this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.valueWritten = !0;
370
+ }
371
+ writeValueArray(t, r) {
372
+ this.ensureValueType(
373
+ 9
374
+ /* Array */
375
+ );
376
+ const i = new b(t);
377
+ r(i);
378
+ const n = i.finish();
379
+ this.payload.writeBytes(n), this.valueWritten = !0;
380
+ }
381
+ writeValueDictionary(t, r, i) {
382
+ this.ensureValueType(
383
+ 10
384
+ /* Dict */
385
+ );
386
+ const n = new _(t, r);
387
+ i(n);
388
+ const s = n.finish();
389
+ this.payload.writeBytes(s), this.valueWritten = !0;
390
+ }
391
+ complete() {
392
+ if (!this.completed) {
393
+ if (!this.keyWritten || !this.valueWritten)
394
+ throw new Error("Dictionary entry must write both key and value");
395
+ this.completed = !0, this.onComplete();
396
+ }
397
+ }
398
+ ensureKeyType(t) {
399
+ if (this.keyType !== t)
400
+ throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[t]}`);
401
+ }
402
+ ensureValueType(t) {
403
+ if (this.valueType !== t)
404
+ throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[t]}`);
405
+ }
406
+ }
407
+ class a {
408
+ constructor(t) {
409
+ this.bytes = t;
410
+ }
411
+ static fromString(t) {
412
+ if (!t)
413
+ throw new Error("Guid string is empty");
414
+ const r = t.replace(/-/g, "");
415
+ if (r.length !== 32)
416
+ throw new Error("Guid string must be 32 hex characters");
417
+ const i = new Uint8Array(16), n = a.parseHexSlice(r, 0, 8), s = a.parseHexSlice(r, 8, 4), o = a.parseHexSlice(r, 12, 4);
418
+ a.writeUInt32LE(i, 0, n), a.writeUInt16LE(i, 4, s), a.writeUInt16LE(i, 6, o);
419
+ for (let d = 0; d < 8; d++)
420
+ i[8 + d] = a.parseHexSlice(r, 16 + d * 2, 2);
421
+ return new a(i);
422
+ }
423
+ static fromBytes(t) {
424
+ if (t.length !== 16)
425
+ throw new Error("Guid byte array must be 16 bytes");
426
+ return new a(Uint8Array.from(t));
427
+ }
428
+ static createZero() {
429
+ return new a(new Uint8Array(16));
430
+ }
431
+ static createRandom() {
432
+ const t = new Uint8Array(16), r = globalThis.crypto;
433
+ if (r?.getRandomValues)
434
+ r.getRandomValues(t);
435
+ else
436
+ for (let i = 0; i < t.length; i++)
437
+ t[i] = Math.floor(Math.random() * 256);
438
+ return t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, new a(t);
439
+ }
440
+ toString() {
441
+ const t = this.bytes;
442
+ return [
443
+ a.toHex(a.readUInt32LE(t, 0), 8),
444
+ a.toHex(a.readUInt16LE(t, 4), 4),
445
+ a.toHex(a.readUInt16LE(t, 6), 4),
446
+ R(t.subarray(8, 10)),
447
+ R(t.subarray(10, 16))
448
+ ].join("-");
449
+ }
450
+ asBytes() {
451
+ return this.bytes.slice();
452
+ }
453
+ static parseHexSlice(t, r, i) {
454
+ const n = t.substr(r, i), s = Number.parseInt(n, 16);
455
+ if (Number.isNaN(s))
456
+ throw new Error("Guid string contains invalid characters");
457
+ return s >>> 0;
458
+ }
459
+ static writeUInt32LE(t, r, i) {
460
+ const n = i >>> 0;
461
+ t[r] = n & 255, t[r + 1] = n >>> 8 & 255, t[r + 2] = n >>> 16 & 255, t[r + 3] = n >>> 24 & 255;
462
+ }
463
+ static writeUInt16LE(t, r, i) {
464
+ const n = i & 65535;
465
+ t[r] = n & 255, t[r + 1] = n >>> 8 & 255;
466
+ }
467
+ static readUInt32LE(t, r) {
468
+ return (t[r] | t[r + 1] << 8 | t[r + 2] << 16 | t[r + 3] << 24) >>> 0;
469
+ }
470
+ static readUInt16LE(t, r) {
471
+ return (t[r] | t[r + 1] << 8) & 65535;
472
+ }
473
+ static toHex(t, r) {
474
+ return (t >>> 0).toString(16).padStart(r, "0");
475
+ }
476
+ }
477
+ class p {
478
+ bytes = [];
479
+ writeByte(t) {
480
+ this.bytes.push(t & 255);
481
+ }
482
+ writeBytes(t) {
483
+ for (let r = 0; r < t.length; r++)
484
+ this.bytes.push(t[r]);
485
+ }
486
+ writeUInt32(t) {
487
+ this.bytes.push(t & 255), this.bytes.push(t >>> 8 & 255), this.bytes.push(t >>> 16 & 255), this.bytes.push(t >>> 24 & 255);
488
+ }
489
+ writeInt32(t) {
490
+ this.writeUInt32(t | 0);
491
+ }
492
+ writeFloat32(t) {
493
+ const r = new DataView(new ArrayBuffer(4));
494
+ r.setFloat32(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
495
+ }
496
+ writeFloat64(t) {
497
+ const r = new DataView(new ArrayBuffer(8));
498
+ r.setFloat64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
499
+ }
500
+ writeBigInt64(t) {
501
+ const r = new DataView(new ArrayBuffer(8));
502
+ r.setBigInt64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
503
+ }
504
+ writeBigUInt64(t) {
505
+ const r = new DataView(new ArrayBuffer(8));
506
+ r.setBigUint64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
507
+ }
508
+ writeVarUInt(t) {
509
+ let r = t >>> 0;
510
+ for (; r >= 128; )
511
+ this.bytes.push(r & 127 | 128), r >>>= 7;
512
+ this.bytes.push(r & 127);
513
+ }
514
+ toUint8Array() {
515
+ return Uint8Array.from(this.bytes);
516
+ }
517
+ }
518
+ function F(e, t = 0) {
519
+ if ((t & 240) !== 0)
520
+ throw new Error("Teleport flags must fit into 4 bits");
521
+ return (e & 15) << 4 | t & 15;
522
+ }
523
+ function z(e) {
524
+ return e === 12 || e === 13 || e === 9 || e === 11 || e === 10;
525
+ }
526
+ function j(e) {
527
+ if (e === 9 || e === 11 || e === 10 || e === 1)
528
+ throw new Error("Dictionary keys must be primitive Teleport types");
529
+ }
530
+ function R(e) {
531
+ return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
532
+ }
533
+ var S = /* @__PURE__ */ ((e) => (e[e.Unknown = 0] = "Unknown", e[e.Opus = 1] = "Opus", e[e.Mp3 = 2] = "Mp3", e[e.RawPcm16 = 3] = "RawPcm16", e))(S || {});
534
+ const T = 1, $ = 4194307, G = 271275304, Y = 668699606, q = 945580544, J = 1594075008, Z = 2079085407, Q = 2541432218, X = 2986785889, tt = 3105403172, et = 4017217601;
535
+ function rt(e) {
536
+ const t = {};
537
+ return it(t), e && Object.assign(t, e), t;
538
+ }
539
+ function it(e) {
540
+ return e.Data = new Uint8Array(0), e.IsKey = !1, e.IsLast = !1, e.TimestampInUs = 0n, e.DurationInUs = 0, e.IsFirst = !1, e.TotalDurationInUs = 0, e.Volume = 0, e.VolumeSampleCount = 0, e;
541
+ }
542
+ function nt(e) {
543
+ const t = new y(T);
544
+ return st(e, t), t.finish();
545
+ }
546
+ function st(e, t) {
547
+ t.writeUInt64Field(G, e.TimestampInUs), t.writeUInt32Field(Y, e.TotalDurationInUs >>> 0), t.writeInt32Field(q, e.VolumeSampleCount | 0), t.writeBoolField(J, e.IsFirst), t.writeFloat32Field(Z, e.Volume), t.writeUInt32Field(Q, e.DurationInUs >>> 0), t.writeBinaryField(X, e.Data), t.writeBoolField(tt, e.IsKey), t.writeBoolField(et, e.IsLast);
548
+ }
549
+ function at(e, t, r) {
550
+ const i = nt(e);
551
+ return U($, i, T, t, r);
552
+ }
553
+ const W = 1, ot = 4194308, ut = 2079085407, lt = 3485914759;
554
+ function ct(e) {
555
+ const t = {};
556
+ return ht(t), e && Object.assign(t, e), t;
557
+ }
558
+ function ht(e) {
559
+ return e.Volume = 0, e.Count = 0, e;
560
+ }
561
+ function dt(e) {
562
+ const t = new y(W);
563
+ return yt(e, t), t.finish();
564
+ }
565
+ function yt(e, t) {
566
+ t.writeFloat32Field(ut, e.Volume), t.writeInt32Field(lt, e.Count | 0);
567
+ }
568
+ function wt(e, t, r) {
569
+ const i = dt(e);
570
+ return U(ot, i, W, t, r);
571
+ }
572
+ const k = 1, ft = 4194305, pt = 1368629611, It = 2431514951, mt = 2914494629, Et = 3284746250, Ft = 4101844078;
573
+ function Ut(e) {
574
+ const t = {};
575
+ return bt(t), e && Object.assign(t, e), t;
576
+ }
577
+ function bt(e) {
578
+ return e.Description = "", e.Codec = S.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
579
+ }
580
+ function At(e) {
581
+ const t = new y(k);
582
+ return gt(e, t), t.finish();
583
+ }
584
+ function gt(e, t) {
585
+ t.writeStringField(pt, e.Description), t.writeInt32Field(It, e.Channels | 0), t.writeInt32Field(mt, e.BitDepth | 0), t.writeInt32Field(Et, e.Codec), t.writeInt32Field(Ft, e.SampleRate | 0);
586
+ }
587
+ function Dt(e, t, r) {
588
+ const i = At(e);
589
+ return U(ft, i, k, t, r);
590
+ }
591
+ const v = 1, Bt = 4194306;
592
+ function _t(e) {
593
+ const t = {};
594
+ return e && Object.assign(t, e), t;
595
+ }
596
+ function St(e) {
597
+ return new y(v).finish();
598
+ }
599
+ function Mt(e, t, r) {
600
+ const i = St();
601
+ return U(Bt, i, v, t, r);
602
+ }
603
+ class Vt {
604
+ static getStorageForCapacity(t, r) {
605
+ const i = Int32Array.BYTES_PER_ELEMENT * 2, n = r.BYTES_PER_ELEMENT * t;
606
+ return new SharedArrayBuffer(i + n);
607
+ }
608
+ readWrite;
609
+ storage;
610
+ buf;
611
+ constructor(t, r) {
612
+ this.buf = t, this.readWrite = new Int32Array(t, 0, 2);
613
+ const i = Int32Array.BYTES_PER_ELEMENT * 2, n = (t.byteLength - i) / Float32Array.BYTES_PER_ELEMENT;
614
+ this.storage = new r(t, i, n);
615
+ }
616
+ get capacity() {
617
+ return this.storage.length;
618
+ }
619
+ flush() {
620
+ Atomics.store(this.readWrite, 0, 0), Atomics.store(this.readWrite, 1, 0);
621
+ }
622
+ availableRead() {
623
+ const t = Atomics.load(this.readWrite, 0), r = Atomics.load(this.readWrite, 1);
624
+ return r >= t ? r - t : this.capacity - (t - r);
625
+ }
626
+ availableWrite() {
627
+ return this.capacity - this.availableRead() - 1;
628
+ }
629
+ push(t) {
630
+ const r = Math.min(this.availableWrite(), t.length);
631
+ if (r <= 0)
632
+ return 0;
633
+ let i = Atomics.load(this.readWrite, 1);
634
+ const n = Math.min(r, this.capacity - i);
635
+ this.storage.set(t.subarray(0, n), i);
636
+ const s = r - n;
637
+ return s > 0 && this.storage.set(t.subarray(n, n + s), 0), i = (i + r) % this.capacity, Atomics.store(this.readWrite, 1, i), Atomics.notify(this.readWrite, 1), r;
638
+ }
639
+ pop(t) {
640
+ const r = Math.min(this.availableRead(), t.length);
641
+ if (r <= 0)
642
+ return 0;
643
+ let i = Atomics.load(this.readWrite, 0);
644
+ const n = Math.min(r, this.capacity - i);
645
+ t.set(this.storage.subarray(i, i + n), 0);
646
+ const s = r - n;
647
+ return s > 0 && t.set(this.storage.subarray(0, s), n), i = (i + r) % this.capacity, Atomics.store(this.readWrite, 0, i), r;
648
+ }
649
+ skip(t) {
650
+ const r = Math.min(this.availableRead(), t);
651
+ if (r <= 0)
652
+ return 0;
653
+ let i = Atomics.load(this.readWrite, 0);
654
+ return i = (i + r) % this.capacity, Atomics.store(this.readWrite, 0, i), r;
655
+ }
656
+ }
657
+ let Ot = 1;
658
+ function Lt(e, t) {
659
+ return `[${e}] ${t}`;
660
+ }
661
+ function m(e, t, r, i) {
662
+ if ((/* @__PURE__ */ new Date()).toISOString(), Ot <= e) {
663
+ const n = Lt(t, r);
664
+ switch (e) {
665
+ case 0:
666
+ console.debug(n, ...i);
667
+ break;
668
+ case 1:
669
+ console.info(n, ...i);
670
+ break;
671
+ case 2:
672
+ console.warn(n, ...i);
673
+ break;
674
+ case 3:
675
+ console.error(n, ...i);
676
+ break;
677
+ }
678
+ }
679
+ }
680
+ function Rt(e) {
681
+ return {
682
+ debug(t, ...r) {
683
+ m(0, e, t, r);
684
+ },
685
+ info(t, ...r) {
686
+ m(1, e, t, r);
687
+ },
688
+ warn(t, ...r) {
689
+ m(2, e, t, r);
690
+ },
691
+ error(t, ...r) {
692
+ m(3, e, t, r);
693
+ }
694
+ };
695
+ }
696
+ const Tt = Rt("AudioCaptureWorker"), M = (e) => self.postMessage(e);
697
+ let l = null;
698
+ function I(e, t) {
699
+ const r = e instanceof Error ? e : new Error(String(e));
700
+ M({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
701
+ }
702
+ function Wt(e) {
703
+ return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
704
+ }
705
+ function A(e) {
706
+ if (!l)
707
+ return;
708
+ const t = Wt(e);
709
+ l.postMessage({ type: "send", message: t }, [t]);
710
+ }
711
+ function kt(e) {
712
+ if (e.length === 0)
713
+ return 0;
714
+ let t = 0;
715
+ for (let r = 0; r < e.length; r++)
716
+ t += Math.abs(e[r] ?? 0);
717
+ return t / e.length;
718
+ }
719
+ const h = /* @__PURE__ */ new Map();
720
+ let f = null;
721
+ function vt() {
722
+ f === null && (f = self.setInterval(() => {
723
+ for (const e of h.values())
724
+ if (!(e.transport !== "sab" || !e.ringBuffer || !e.ringTemp || e.stopped))
725
+ try {
726
+ const t = e.ringBuffer.pop(e.ringTemp);
727
+ if (t <= 0)
728
+ continue;
729
+ const r = e.ringTemp.subarray(0, t);
730
+ x(e, new Float32Array(r));
731
+ } catch (t) {
732
+ I(t, e.captureId);
733
+ }
734
+ }, 10));
735
+ }
736
+ function Nt() {
737
+ if (!(f === null || Array.from(h.values()).some((t) => t.transport === "sab" && !t.stopped))) {
738
+ try {
739
+ self.clearInterval(f);
740
+ } catch {
741
+ }
742
+ f = null;
743
+ }
744
+ }
745
+ function N(e) {
746
+ if (!e.stopped)
747
+ for (; e.pendingSamples >= e.frameSize; ) {
748
+ const t = new Float32Array(e.frameSize);
749
+ let r = 0;
750
+ for (; r < e.frameSize && e.pending.length > 0; ) {
751
+ const n = e.pending[0], s = Math.min(n.length, e.frameSize - r);
752
+ t.set(n.subarray(0, s), r), r += s, s === n.length ? e.pending.shift() : e.pending[0] = n.subarray(s);
753
+ }
754
+ e.pendingSamples -= e.frameSize;
755
+ const i = kt(t);
756
+ A(wt(ct({ Volume: i, Count: e.frameSize }), e.senderId, { trackId: e.trackId }));
757
+ try {
758
+ const n = new AudioData({
759
+ format: "f32",
760
+ sampleRate: e.sampleRate,
761
+ numberOfFrames: e.frameSize,
762
+ numberOfChannels: e.channels,
763
+ timestamp: e.timestampUs,
764
+ data: t
765
+ });
766
+ e.encoder.encode(n), n.close();
767
+ } catch (n) {
768
+ I(n, e.captureId);
769
+ }
770
+ e.timestampUs += e.frameDurationUs;
771
+ }
772
+ }
773
+ function x(e, t) {
774
+ e.stopped || t.length !== 0 && (e.pending.push(t), e.pendingSamples += t.length, N(e));
775
+ }
776
+ function xt(e) {
777
+ const t = Math.max(8e3, Math.floor(e.options?.bitrate ?? 16e3)), r = new AudioEncoder({
778
+ output: (i) => {
779
+ const n = h.get(e.captureId);
780
+ if (!n || n.stopped)
781
+ return;
782
+ const s = new Uint8Array(i.byteLength);
783
+ i.copyTo(s);
784
+ const o = !n.sentFirst;
785
+ o && (n.sentFirst = !0), A(
786
+ at(
787
+ rt({
788
+ Data: s,
789
+ IsKey: i.type === "key",
790
+ IsFirst: o,
791
+ IsLast: !1,
792
+ TimestampInUs: BigInt(Math.max(0, Math.round(i.timestamp ?? n.timestampUs))),
793
+ DurationInUs: Math.max(0, Math.round(i.duration ?? n.frameDurationUs)),
794
+ TotalDurationInUs: 0
795
+ }),
796
+ n.senderId,
797
+ { trackId: n.trackId }
798
+ )
799
+ );
800
+ },
801
+ error: (i) => {
802
+ I(i, e.captureId);
803
+ }
804
+ });
805
+ return r.configure({
806
+ codec: "opus",
807
+ numberOfChannels: e.channels,
808
+ sampleRate: e.sampleRate,
809
+ bitrate: t,
810
+ bitrateMode: "constant",
811
+ opus: {
812
+ application: "lowdelay",
813
+ signal: "voice"
814
+ }
815
+ }), r;
816
+ }
817
+ function Pt(e) {
818
+ if (!l)
819
+ throw new Error("Audio capture worker missing send port");
820
+ if (h.has(e.captureId))
821
+ return;
822
+ if (typeof AudioEncoder > "u")
823
+ throw new Error("AudioEncoder is not available in this browser");
824
+ const t = Math.max(8e3, Math.floor(e.sampleRate)), r = Math.max(1, Math.floor(e.channels)), i = Math.max(10, Math.min(60, Math.floor(e.options?.frameDurationMs ?? 20))), n = Math.max(1, Math.floor(t * i / 1e3)), s = Math.max(1, Math.floor(n * 1e6 / t)), o = {
825
+ captureId: e.captureId,
826
+ senderId: e.senderId,
827
+ trackId: e.trackId,
828
+ sampleRate: t,
829
+ channels: r,
830
+ frameSize: n,
831
+ frameDurationUs: s,
832
+ timestampUs: 0,
833
+ sentFirst: !1,
834
+ stopped: !1,
835
+ transport: e.transport,
836
+ ringBuffer: null,
837
+ ringTemp: null,
838
+ pending: [],
839
+ pendingSamples: 0,
840
+ options: e.options
841
+ }, d = xt(o), c = {
842
+ ...o,
843
+ encoder: d
844
+ };
845
+ if (e.transport === "sab") {
846
+ if (!e.sharedArrayBuffer)
847
+ throw new Error("Missing SharedArrayBuffer for sab transport");
848
+ const g = new Vt(e.sharedArrayBuffer, Float32Array);
849
+ c.ringBuffer = g, c.ringTemp = new Float32Array(Math.max(c.frameSize * 4, 4096)), vt();
850
+ }
851
+ h.set(e.captureId, c), A(
852
+ Dt(
853
+ Ut({
854
+ Description: `mic:${e.captureId}`,
855
+ Codec: S.Opus,
856
+ SampleRate: t,
857
+ Channels: r,
858
+ BitDepth: 32
859
+ }),
860
+ e.senderId,
861
+ { trackId: e.trackId }
862
+ )
863
+ ), M({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
864
+ }
865
+ async function P(e) {
866
+ const t = h.get(e);
867
+ if (t) {
868
+ t.stopped = !0, h.delete(e);
869
+ try {
870
+ N(t);
871
+ } catch {
872
+ }
873
+ try {
874
+ await t.encoder.flush();
875
+ } catch {
876
+ }
877
+ try {
878
+ t.encoder.close();
879
+ } catch {
880
+ }
881
+ A(Mt(_t({}), t.senderId, { trackId: t.trackId })), M({ type: "stopped", captureId: e }), Nt();
882
+ }
883
+ }
884
+ function Ct() {
885
+ for (const e of Array.from(h.keys()))
886
+ P(e);
887
+ if (l) {
888
+ try {
889
+ l.close();
890
+ } catch {
891
+ }
892
+ l = null;
893
+ }
894
+ }
895
+ self.addEventListener("message", (e) => {
896
+ const t = e.data;
897
+ if (t.type === "attachSendPort") {
898
+ if (l)
899
+ try {
900
+ l.close();
901
+ } catch {
902
+ }
903
+ l = t.port;
904
+ try {
905
+ l.start?.();
906
+ } catch {
907
+ }
908
+ return;
909
+ }
910
+ if (t.type === "start") {
911
+ try {
912
+ Pt(t);
913
+ } catch (r) {
914
+ I(r, t.captureId);
915
+ }
916
+ return;
917
+ }
918
+ if (t.type === "pcm") {
919
+ const r = h.get(t.captureId);
920
+ if (!r || r.stopped)
921
+ return;
922
+ x(r, t.pcm);
923
+ return;
924
+ }
925
+ if (t.type === "stop") {
926
+ P(t.captureId).catch((r) => {
927
+ Tt.warn(`Failed to stop audio capture: ${r}`), I(r, t.captureId);
928
+ });
929
+ return;
930
+ }
931
+ t.type === "dispose" && Ct();
932
+ });