@ikonai/sdk 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- function O(t, e, r, n, i) {
2
- const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, u = i?.flags ?? 0, c = i?.targetIds ?? [], d = i?.payloadType ?? 8, w = 27 + c.length * 4, I = w + e.length, y = new Uint8Array(I), l = new DataView(y.buffer);
3
- l.setUint32(0, I, !0), l.setUint32(4, t >>> 0, !0), l.setUint32(8, n >>> 0, !0), l.setUint32(12, s >>> 0, !0), l.setUint32(16, a >>> 0, !0), l.setUint32(20, c.length >>> 0, !0), l.setUint8(24, r & 255), l.setUint8(25, d & 255), l.setUint8(26, u & 255);
4
- let C = 27;
5
- for (let D = 0; D < c.length; D++)
6
- l.setUint32(C, c[D] >>> 0, !0), C += 4;
7
- return y.set(e, w), y;
1
+ function L(t, e, r, n, i) {
2
+ const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, c = i?.flags ?? 0, l = i?.targetIds ?? [], o = i?.payloadType ?? 8, d = 27 + l.length * 4, y = d + e.length, p = new Uint8Array(y), h = new DataView(p.buffer);
3
+ h.setUint32(0, y, !0), h.setUint32(4, t >>> 0, !0), h.setUint32(8, n >>> 0, !0), h.setUint32(12, s >>> 0, !0), h.setUint32(16, a >>> 0, !0), h.setUint32(20, l.length >>> 0, !0), h.setUint8(24, r & 255), h.setUint8(25, o & 255), h.setUint8(26, c & 255);
4
+ let N = 27;
5
+ for (let V = 0; V < l.length; V++)
6
+ h.setUint32(N, l[V] >>> 0, !0), N += 4;
7
+ return p.set(e, d), p;
8
8
  }
9
- var f = /* @__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))(f || {});
10
- const K = 161, $ = 162, b = new TextEncoder();
9
+ var w = /* @__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))(w || {});
10
+ const q = 161, G = 162, U = new TextEncoder();
11
11
  new TextDecoder("utf-8", { fatal: !0 });
12
- class E {
12
+ class S {
13
13
  constructor(e = 1) {
14
- this.version = e, this.buffer.writeByte(K), this.buffer.writeVarUInt(e >>> 0);
14
+ this.version = e, this.buffer.writeByte(q), this.buffer.writeVarUInt(e >>> 0);
15
15
  }
16
- buffer = new m();
16
+ buffer = new g();
17
17
  closed = !1;
18
18
  cached;
19
19
  writeInt32Field(e, r) {
@@ -38,38 +38,38 @@ class E {
38
38
  this.writeFixedField(e, 2, () => this.buffer.writeByte(r ? 1 : 0));
39
39
  }
40
40
  writeGuidField(e, r) {
41
- const n = r instanceof o ? r.asBytes() : r;
41
+ const n = r instanceof u ? r.asBytes() : r;
42
42
  if (n.length !== 16)
43
43
  throw new Error("Guid payload must be 16 bytes");
44
44
  this.writeFixedField(e, 14, () => this.buffer.writeBytes(n));
45
45
  }
46
46
  writeStringField(e, r) {
47
- const n = b.encode(r ?? "");
47
+ const n = U.encode(r ?? "");
48
48
  this.writeVariableField(e, 12, n);
49
49
  }
50
50
  writeBinaryField(e, r) {
51
51
  this.writeVariableField(e, 13, r);
52
52
  }
53
53
  writeObjectField(e, r, n) {
54
- const i = new E(r);
54
+ const i = new S(r);
55
55
  n(i);
56
56
  const s = i.finish();
57
57
  this.writeVariableField(e, 11, s);
58
58
  }
59
59
  writeArrayField(e, r, n) {
60
- const i = new U(r);
60
+ const i = new R(r);
61
61
  n(i);
62
62
  const s = i.finish();
63
63
  this.writeVariableField(e, 9, s);
64
64
  }
65
65
  writeDictionaryField(e, r, n, i) {
66
- const s = new B(r, n);
66
+ const s = new P(r, n);
67
67
  i(s);
68
68
  const a = s.finish();
69
69
  this.writeVariableField(e, 10, a);
70
70
  }
71
71
  finish() {
72
- return this.closed || (this.buffer.writeByte($), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
72
+ return this.closed || (this.buffer.writeByte(G), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
73
73
  }
74
74
  writeFixedField(e, r, n) {
75
75
  this.writeFieldHeader(e, r, 0), n();
@@ -78,14 +78,14 @@ class E {
78
78
  this.writeFieldHeader(e, r, n.length), this.buffer.writeBytes(n);
79
79
  }
80
80
  writeFieldHeader(e, r, n) {
81
- this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(_(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
81
+ this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(D(r)), J(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
- class U {
84
+ class R {
85
85
  constructor(e) {
86
86
  this.elementType = e;
87
87
  }
88
- payload = new m();
88
+ payload = new g();
89
89
  count = 0;
90
90
  writeInt32(e) {
91
91
  this.ensureElementType(
@@ -134,7 +134,7 @@ class U {
134
134
  14
135
135
  /* Guid */
136
136
  ), this.count++;
137
- const r = e instanceof o ? e.asBytes() : e;
137
+ const r = e instanceof u ? e.asBytes() : e;
138
138
  if (r.length !== 16)
139
139
  throw new Error("Guid payload must be 16 bytes");
140
140
  this.payload.writeBytes(r);
@@ -144,7 +144,7 @@ class U {
144
144
  12
145
145
  /* String */
146
146
  ), this.count++;
147
- const r = b.encode(e ?? "");
147
+ const r = U.encode(e ?? "");
148
148
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
149
149
  }
150
150
  writeBinary(e) {
@@ -158,7 +158,7 @@ class U {
158
158
  11
159
159
  /* Object */
160
160
  ), this.count++;
161
- const n = new E(e);
161
+ const n = new S(e);
162
162
  r(n);
163
163
  const i = n.finish();
164
164
  this.payload.writeVarUInt(i.length), this.payload.writeBytes(i);
@@ -168,7 +168,7 @@ class U {
168
168
  9
169
169
  /* Array */
170
170
  ), this.count++;
171
- const n = new U(e);
171
+ const n = new R(e);
172
172
  r(n);
173
173
  const i = n.finish();
174
174
  this.payload.writeBytes(i);
@@ -178,42 +178,42 @@ class U {
178
178
  10
179
179
  /* Dict */
180
180
  ), this.count++;
181
- const i = new B(e, r);
181
+ const i = new P(e, r);
182
182
  n(i);
183
183
  const s = i.finish();
184
184
  this.payload.writeBytes(s);
185
185
  }
186
186
  finish() {
187
- const e = new m();
188
- return e.writeByte(_(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
187
+ const e = new g();
188
+ return e.writeByte(D(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
189
189
  }
190
190
  ensureElementType(e) {
191
191
  if (this.elementType !== e)
192
- throw new Error(`Array element type is ${f[this.elementType]}, expected ${f[e]}`);
192
+ throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[e]}`);
193
193
  }
194
194
  }
195
- class B {
195
+ class P {
196
196
  constructor(e, r) {
197
- this.keyType = e, this.valueType = r, G(e);
197
+ this.keyType = e, this.valueType = r, X(e);
198
198
  }
199
- payload = new m();
199
+ payload = new g();
200
200
  count = 0;
201
201
  entryOpen = !1;
202
202
  beginEntry() {
203
203
  if (this.entryOpen)
204
204
  throw new Error("Previous dictionary entry not completed");
205
- return this.count++, this.entryOpen = !0, new j(this.keyType, this.valueType, this.payload, () => {
205
+ return this.count++, this.entryOpen = !0, new Y(this.keyType, this.valueType, this.payload, () => {
206
206
  this.entryOpen = !1;
207
207
  });
208
208
  }
209
209
  finish() {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
- const e = new m();
213
- return e.writeByte(_(this.keyType)), e.writeByte(_(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
212
+ const e = new g();
213
+ return e.writeByte(D(this.keyType)), e.writeByte(D(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
214
214
  }
215
215
  }
216
- class j {
216
+ class Y {
217
217
  constructor(e, r, n, i) {
218
218
  this.keyType = e, this.valueType = r, this.payload = n, this.onComplete = i;
219
219
  }
@@ -267,7 +267,7 @@ class j {
267
267
  14
268
268
  /* Guid */
269
269
  );
270
- const r = e instanceof o ? e.asBytes() : e;
270
+ const r = e instanceof u ? e.asBytes() : e;
271
271
  if (r.length !== 16)
272
272
  throw new Error("Guid payload must be 16 bytes");
273
273
  this.payload.writeBytes(r), this.keyWritten = !0;
@@ -277,7 +277,7 @@ class j {
277
277
  12
278
278
  /* String */
279
279
  );
280
- const r = b.encode(e ?? "");
280
+ const r = U.encode(e ?? "");
281
281
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
282
282
  }
283
283
  writeKeyBinary(e) {
@@ -333,7 +333,7 @@ class j {
333
333
  14
334
334
  /* Guid */
335
335
  );
336
- const r = e instanceof o ? e.asBytes() : e;
336
+ const r = e instanceof u ? e.asBytes() : e;
337
337
  if (r.length !== 16)
338
338
  throw new Error("Guid payload must be 16 bytes");
339
339
  this.payload.writeBytes(r), this.valueWritten = !0;
@@ -355,7 +355,7 @@ class j {
355
355
  12
356
356
  /* String */
357
357
  );
358
- const r = b.encode(e ?? "");
358
+ const r = U.encode(e ?? "");
359
359
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
360
360
  }
361
361
  writeValueObject(e, r) {
@@ -363,7 +363,7 @@ class j {
363
363
  11
364
364
  /* Object */
365
365
  );
366
- const n = new E(e);
366
+ const n = new S(e);
367
367
  r(n);
368
368
  const i = n.finish();
369
369
  this.payload.writeVarUInt(i.length), this.payload.writeBytes(i), this.valueWritten = !0;
@@ -373,7 +373,7 @@ class j {
373
373
  9
374
374
  /* Array */
375
375
  );
376
- const n = new U(e);
376
+ const n = new R(e);
377
377
  r(n);
378
378
  const i = n.finish();
379
379
  this.payload.writeBytes(i), this.valueWritten = !0;
@@ -383,7 +383,7 @@ class j {
383
383
  10
384
384
  /* Dict */
385
385
  );
386
- const i = new B(e, r);
386
+ const i = new P(e, r);
387
387
  n(i);
388
388
  const s = i.finish();
389
389
  this.payload.writeBytes(s), this.valueWritten = !0;
@@ -397,14 +397,14 @@ class j {
397
397
  }
398
398
  ensureKeyType(e) {
399
399
  if (this.keyType !== e)
400
- throw new Error(`Dictionary key type is ${f[this.keyType]}, expected ${f[e]}`);
400
+ throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[e]}`);
401
401
  }
402
402
  ensureValueType(e) {
403
403
  if (this.valueType !== e)
404
- throw new Error(`Dictionary value type is ${f[this.valueType]}, expected ${f[e]}`);
404
+ throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[e]}`);
405
405
  }
406
406
  }
407
- class o {
407
+ class u {
408
408
  constructor(e) {
409
409
  this.bytes = e;
410
410
  }
@@ -414,19 +414,19 @@ class o {
414
414
  const r = e.replace(/-/g, "");
415
415
  if (r.length !== 32)
416
416
  throw new Error("Guid string must be 32 hex characters");
417
- const n = new Uint8Array(16), i = o.parseHexSlice(r, 0, 8), s = o.parseHexSlice(r, 8, 4), a = o.parseHexSlice(r, 12, 4);
418
- o.writeUInt32LE(n, 0, i), o.writeUInt16LE(n, 4, s), o.writeUInt16LE(n, 6, a);
419
- for (let u = 0; u < 8; u++)
420
- n[8 + u] = o.parseHexSlice(r, 16 + u * 2, 2);
421
- return new o(n);
417
+ const n = new Uint8Array(16), i = u.parseHexSlice(r, 0, 8), s = u.parseHexSlice(r, 8, 4), a = u.parseHexSlice(r, 12, 4);
418
+ u.writeUInt32LE(n, 0, i), u.writeUInt16LE(n, 4, s), u.writeUInt16LE(n, 6, a);
419
+ for (let c = 0; c < 8; c++)
420
+ n[8 + c] = u.parseHexSlice(r, 16 + c * 2, 2);
421
+ return new u(n);
422
422
  }
423
423
  static fromBytes(e) {
424
424
  if (e.length !== 16)
425
425
  throw new Error("Guid byte array must be 16 bytes");
426
- return new o(Uint8Array.from(e));
426
+ return new u(Uint8Array.from(e));
427
427
  }
428
428
  static createZero() {
429
- return new o(new Uint8Array(16));
429
+ return new u(new Uint8Array(16));
430
430
  }
431
431
  static createRandom() {
432
432
  const e = new Uint8Array(16), r = globalThis.crypto;
@@ -435,16 +435,16 @@ class o {
435
435
  else
436
436
  for (let n = 0; n < e.length; n++)
437
437
  e[n] = Math.floor(Math.random() * 256);
438
- return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new o(e);
438
+ return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new u(e);
439
439
  }
440
440
  toString() {
441
441
  const e = this.bytes;
442
442
  return [
443
- o.toHex(o.readUInt32LE(e, 0), 8),
444
- o.toHex(o.readUInt16LE(e, 4), 4),
445
- o.toHex(o.readUInt16LE(e, 6), 4),
446
- v(e.subarray(8, 10)),
447
- v(e.subarray(10, 16))
443
+ u.toHex(u.readUInt32LE(e, 0), 8),
444
+ u.toHex(u.readUInt16LE(e, 4), 4),
445
+ u.toHex(u.readUInt16LE(e, 6), 4),
446
+ k(e.subarray(8, 10)),
447
+ k(e.subarray(10, 16))
448
448
  ].join("-");
449
449
  }
450
450
  asBytes() {
@@ -474,13 +474,13 @@ class o {
474
474
  return (e >>> 0).toString(16).padStart(r, "0");
475
475
  }
476
476
  }
477
- class m {
477
+ class g {
478
478
  static INITIAL_CAPACITY = 256;
479
479
  buffer;
480
480
  dataView;
481
481
  length = 0;
482
482
  constructor() {
483
- this.buffer = new Uint8Array(m.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
483
+ this.buffer = new Uint8Array(g.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
484
484
  }
485
485
  ensureCapacity(e) {
486
486
  const r = this.length + e;
@@ -526,101 +526,101 @@ class m {
526
526
  return this.buffer.slice(0, this.length);
527
527
  }
528
528
  }
529
- function _(t, e = 0) {
529
+ function D(t, e = 0) {
530
530
  if ((e & 240) !== 0)
531
531
  throw new Error("Teleport flags must fit into 4 bits");
532
532
  return (t & 15) << 4 | e & 15;
533
533
  }
534
- function q(t) {
534
+ function J(t) {
535
535
  return t === 12 || t === 13 || t === 9 || t === 11 || t === 10;
536
536
  }
537
- function G(t) {
537
+ function X(t) {
538
538
  if (t === 9 || t === 11 || t === 10 || t === 1)
539
539
  throw new Error("Dictionary keys must be primitive Teleport types");
540
540
  }
541
- function v(t) {
541
+ function k(t) {
542
542
  return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
543
543
  }
544
- var R = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.Opus = 1] = "Opus", t[t.Mp3 = 2] = "Mp3", t[t.RawPcm16 = 3] = "RawPcm16", t))(R || {});
545
- const N = 1, Y = 4194309, J = 205938238, Z = 717315017, Q = 1594075008, X = 2026534360, ee = 3409001585, te = 3466650495, re = 4007456593, ne = 4017217601, ie = 4065417427, se = 4086360332;
546
- function ae(t) {
544
+ var W = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.Opus = 1] = "Opus", t[t.Mp3 = 2] = "Mp3", t[t.RawPcm16 = 3] = "RawPcm16", t))(W || {});
545
+ const z = 1, Z = 4194309, Q = 205938238, ee = 717315017, te = 1594075008, re = 2026534360, ne = 3409001585, ie = 3466650495, se = 4007456593, ae = 4017217601, oe = 4065417427, ce = 4086360332;
546
+ function ue(t) {
547
547
  const e = {};
548
- return oe(e), t && Object.assign(e, t), e;
548
+ return le(e), t && Object.assign(e, t), e;
549
549
  }
550
- function oe(t) {
550
+ function le(t) {
551
551
  return t.Samples = new Uint8Array(0), t.Epoch = 0, t.Sequence = 0, t.FrameSizeInInterleavedSamples = 0, t.TimeStampInInterleavedSamples = 0n, t.IsFirst = !1, t.IsLast = !1, t.AverageVolume = 0, t.AudioEventEstimatedDuration = 0, t.ShapeSetValues = void 0, t;
552
552
  }
553
- function ue(t) {
554
- const e = new E(N);
555
- return ce(t, e), e.finish();
553
+ function de(t) {
554
+ const e = new S(z);
555
+ return he(t, e), e.finish();
556
556
  }
557
- function ce(t, e) {
558
- e.writeFloat32Field(J, t.AverageVolume);
557
+ function he(t, e) {
558
+ e.writeFloat32Field(Q, t.AverageVolume);
559
559
  const r = t.ShapeSetValues;
560
- r != null && e.writeArrayField(Z, f.Object, (n) => {
560
+ r != null && e.writeArrayField(ee, w.Object, (n) => {
561
561
  for (const i of r)
562
- n.writeObject(de, (s) => {
563
- pe(i, s);
562
+ n.writeObject(pe, (s) => {
563
+ Ie(i, s);
564
564
  });
565
- }), e.writeBoolField(Q, t.IsFirst), e.writeUInt64Field(X, t.TimeStampInInterleavedSamples), e.writeBinaryField(ee, t.Samples), e.writeFloat32Field(te, t.AudioEventEstimatedDuration), e.writeUInt32Field(re, t.FrameSizeInInterleavedSamples >>> 0), e.writeBoolField(ne, t.IsLast), e.writeUInt32Field(ie, t.Sequence >>> 0), e.writeUInt32Field(se, t.Epoch >>> 0);
565
+ }), e.writeBoolField(te, t.IsFirst), e.writeUInt64Field(re, t.TimeStampInInterleavedSamples), e.writeBinaryField(ne, t.Samples), e.writeFloat32Field(ie, t.AudioEventEstimatedDuration), e.writeUInt32Field(se, t.FrameSizeInInterleavedSamples >>> 0), e.writeBoolField(ae, t.IsLast), e.writeUInt32Field(oe, t.Sequence >>> 0), e.writeUInt32Field(ce, t.Epoch >>> 0);
566
566
  }
567
- function le(t, e, r) {
568
- const n = ue(t);
569
- return O(Y, n, N, e, r);
567
+ function fe(t, e, r) {
568
+ const n = de(t);
569
+ return L(Z, n, z, e, r);
570
570
  }
571
- const de = 1, he = 1154362099, fe = 3974819915;
572
- function pe(t, e) {
573
- e.writeUInt32Field(he, t.SetId >>> 0), e.writeArrayField(fe, f.Float32, (r) => {
571
+ const pe = 1, ye = 1154362099, we = 3974819915;
572
+ function Ie(t, e) {
573
+ e.writeUInt32Field(ye, t.SetId >>> 0), e.writeArrayField(we, w.Float32, (r) => {
574
574
  for (const n of t.Values)
575
575
  r.writeFloat32(n);
576
576
  });
577
577
  }
578
- const k = 5, ye = 4194305, we = 161083277, Ie = 265814330, me = 1368629611, Ee = 2431514951, ge = 2745379226, Se = 3282782683, Ae = 3284746250, be = 4101844078;
579
- function _e(t) {
578
+ const H = 5, me = 4194305, Ee = 161083277, ge = 265814330, Se = 1368629611, Ae = 2431514951, be = 2745379226, _e = 3282782683, Fe = 3284746250, Ue = 4101844078;
579
+ function De(t) {
580
580
  const e = {};
581
- return Fe(e), t && Object.assign(e, t), e;
581
+ return Oe(e), t && Object.assign(e, t), e;
582
582
  }
583
- function Fe(t) {
584
- return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = R.Unknown, t.CodecDetails = "", t.SampleRate = 0, t.Channels = 0, t.ShapeSets = void 0, t;
583
+ function Oe(t) {
584
+ return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = W.Unknown, t.CodecDetails = "", t.SampleRate = 0, t.Channels = 0, t.ShapeSets = void 0, t;
585
585
  }
586
- function Ue(t) {
587
- const e = new E(k);
588
- return De(t, e), e.finish();
586
+ function Be(t) {
587
+ const e = new S(H);
588
+ return Re(t, e), e.finish();
589
589
  }
590
- function De(t, e) {
591
- e.writeStringField(we, t.StreamId);
590
+ function Re(t, e) {
591
+ e.writeStringField(Ee, t.StreamId);
592
592
  const r = t.ShapeSets;
593
- r != null && e.writeArrayField(Ie, f.Object, (n) => {
593
+ r != null && e.writeArrayField(ge, w.Object, (n) => {
594
594
  for (const i of r)
595
- n.writeObject(Be, (s) => {
596
- Ve(i, s);
595
+ n.writeObject(Te, (s) => {
596
+ We(i, s);
597
597
  });
598
- }), e.writeStringField(me, t.Description), e.writeInt32Field(Ee, t.Channels | 0), e.writeStringField(ge, t.CodecDetails), e.writeStringField(Se, t.SourceType), e.writeInt32Field(Ae, t.Codec), e.writeInt32Field(be, t.SampleRate | 0);
598
+ }), e.writeStringField(Se, t.Description), e.writeInt32Field(Ae, t.Channels | 0), e.writeStringField(be, t.CodecDetails), e.writeStringField(_e, t.SourceType), e.writeInt32Field(Fe, t.Codec), e.writeInt32Field(Ue, t.SampleRate | 0);
599
599
  }
600
- function Oe(t, e, r) {
601
- const n = Ue(t);
602
- return O(ye, n, k, e, r);
600
+ function Me(t, e, r) {
601
+ const n = Be(t);
602
+ return L(me, n, H, e, r);
603
603
  }
604
- const Be = 5, Re = 1107713536, Me = 1154362099, Te = 1185721362;
605
- function Ve(t, e) {
606
- e.writeStringField(Re, t.Name), e.writeUInt32Field(Me, t.SetId >>> 0), e.writeArrayField(Te, f.String, (r) => {
604
+ const Te = 5, Ve = 1107713536, Le = 1154362099, Pe = 1185721362;
605
+ function We(t, e) {
606
+ e.writeStringField(Ve, t.Name), e.writeUInt32Field(Le, t.SetId >>> 0), e.writeArrayField(Pe, w.String, (r) => {
607
607
  for (const n of t.ShapeNames)
608
608
  r.writeString(n);
609
609
  });
610
610
  }
611
- const x = 1, Le = 4194306;
612
- function Pe(t) {
611
+ const K = 1, Ce = 4194306;
612
+ function ve(t) {
613
613
  const e = {};
614
614
  return t && Object.assign(e, t), e;
615
615
  }
616
- function We(t) {
617
- return new E(x).finish();
616
+ function Ne(t) {
617
+ return new S(K).finish();
618
618
  }
619
- function Ce(t, e, r) {
620
- const n = We();
621
- return O(Le, n, x, e, r);
619
+ function ke(t, e, r) {
620
+ const n = Ne();
621
+ return L(Ce, n, K, e, r);
622
622
  }
623
- class ve {
623
+ class xe {
624
624
  static getStorageForCapacity(e, r) {
625
625
  const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * e;
626
626
  return new SharedArrayBuffer(n + i);
@@ -674,19 +674,19 @@ class ve {
674
674
  return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
675
675
  }
676
676
  }
677
- let Ne = 1;
678
- const ke = /* @__PURE__ */ new Map(), xe = {
677
+ let ze = 1;
678
+ const He = /* @__PURE__ */ new Map(), Ke = {
679
679
  0: "DEBUG",
680
680
  1: "INFO",
681
681
  2: "WARN",
682
682
  3: "ERROR",
683
683
  4: "NONE"
684
684
  };
685
- function He(t, e) {
685
+ function $e(t, e) {
686
686
  return `[${t}] ${e}`;
687
687
  }
688
- function A(t, e, r, n) {
689
- const i = (/* @__PURE__ */ new Date()).toISOString(), s = xe[t], a = {
688
+ function _(t, e, r, n) {
689
+ const i = (/* @__PURE__ */ new Date()).toISOString(), s = Ke[t], a = {
690
690
  timestamp: i,
691
691
  level: t,
692
692
  levelName: s,
@@ -694,50 +694,50 @@ function A(t, e, r, n) {
694
694
  message: r,
695
695
  args: n
696
696
  };
697
- for (const [u, c] of ke) {
698
- const d = c?.minLevel ?? 2;
699
- if (t >= d)
697
+ for (const [c, l] of He) {
698
+ const o = l?.minLevel ?? 2;
699
+ if (t >= o)
700
700
  try {
701
- u(a);
701
+ c(a);
702
702
  } catch {
703
703
  }
704
704
  }
705
- if (Ne <= t) {
706
- const u = He(e, r);
705
+ if (ze <= t) {
706
+ const c = $e(e, r);
707
707
  switch (t) {
708
708
  case 0:
709
- console.debug(u, ...n);
709
+ console.debug(c, ...n);
710
710
  break;
711
711
  case 1:
712
- console.info(u, ...n);
712
+ console.info(c, ...n);
713
713
  break;
714
714
  case 2:
715
- console.warn(u, ...n);
715
+ console.warn(c, ...n);
716
716
  break;
717
717
  case 3:
718
- console.error(u, ...n);
718
+ console.error(c, ...n);
719
719
  break;
720
720
  }
721
721
  }
722
722
  }
723
- function ze(t) {
723
+ function je(t) {
724
724
  return {
725
725
  debug(e, ...r) {
726
- A(0, t, e, r);
726
+ _(0, t, e, r);
727
727
  },
728
728
  info(e, ...r) {
729
- A(1, t, e, r);
729
+ _(1, t, e, r);
730
730
  },
731
731
  warn(e, ...r) {
732
- A(2, t, e, r);
732
+ _(2, t, e, r);
733
733
  },
734
734
  error(e, ...r) {
735
- A(3, t, e, r);
735
+ _(3, t, e, r);
736
736
  }
737
737
  };
738
738
  }
739
- const Ke = 20, M = 32e3, $e = 5, T = 8e3, F = ze("AudioCaptureWorker");
740
- class je {
739
+ const qe = 20, b = 32e3, Ge = 5, M = 8e3, E = je("AudioCaptureWorker");
740
+ class $ {
741
741
  encoder = null;
742
742
  isReady = !1;
743
743
  sampleRate;
@@ -759,7 +759,7 @@ class je {
759
759
  channels: this.channels,
760
760
  bitrate: this.bitrate,
761
761
  application: r,
762
- complexity: $e
762
+ complexity: Ge
763
763
  }), await this.encoder.ready, this.isReady = !0;
764
764
  } catch (e) {
765
765
  this.onError(e instanceof Error ? e : new Error(String(e)));
@@ -794,24 +794,24 @@ class je {
794
794
  return this.bitrate;
795
795
  }
796
796
  }
797
- const V = (t) => self.postMessage(t);
798
- let p = null;
799
- function g(t, e) {
797
+ const O = (t) => self.postMessage(t);
798
+ let m = null;
799
+ function I(t, e) {
800
800
  const r = t instanceof Error ? t : new Error(String(t));
801
- V({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
801
+ O({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
802
802
  }
803
- function qe(t) {
803
+ function Ye(t) {
804
804
  return t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.slice().buffer;
805
805
  }
806
- function L(t) {
807
- if (!p) {
808
- F.warn("Audio capture message dropped: sendPort not available");
806
+ function C(t) {
807
+ if (!m) {
808
+ E.warn("Audio capture message dropped: sendPort not available");
809
809
  return;
810
810
  }
811
- const e = qe(t);
812
- p.postMessage({ type: "send", message: e }, [e]);
811
+ const e = Ye(t);
812
+ m.postMessage({ type: "send", message: e }, [e]);
813
813
  }
814
- function Ge(t) {
814
+ function Je(t) {
815
815
  if (t.length === 0)
816
816
  return 0;
817
817
  let e = 0;
@@ -819,41 +819,71 @@ function Ge(t) {
819
819
  e += Math.abs(t[r] ?? 0);
820
820
  return e / t.length;
821
821
  }
822
- const h = /* @__PURE__ */ new Map();
823
- let S = null;
824
- function Ye() {
825
- S === null && (S = self.setInterval(() => {
826
- for (const t of h.values())
827
- if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
828
- try {
829
- const e = t.ringBuffer.pop(t.ringTemp);
830
- if (e <= 0)
831
- continue;
832
- W(t, t.ringTemp.subarray(0, e));
833
- } catch (e) {
834
- g(e, t.captureId);
835
- }
836
- }, 10));
822
+ const f = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
823
+ let A = null;
824
+ const x = 1;
825
+ function Xe() {
826
+ return typeof Atomics < "u" && typeof Atomics.waitAsync == "function";
837
827
  }
838
- function Je() {
839
- if (S === null)
828
+ async function Ze(t) {
829
+ if (!t.ringBuffer || !t.ringTemp)
840
830
  return;
841
- let t = !1;
842
- for (const e of h.values())
843
- if (e.transport === "sab" && !e.stopped) {
844
- t = !0;
845
- break;
831
+ const e = t.ringBuffer, r = t.ringTemp;
832
+ for (; !t.stopped && t.transport === "sab"; ) {
833
+ try {
834
+ const n = e.pop(r);
835
+ n > 0 && T(t, r.subarray(0, n));
836
+ } catch (n) {
837
+ I(n, t.captureId);
846
838
  }
847
- if (!t) {
848
839
  try {
849
- self.clearInterval(S);
840
+ const n = Atomics.load(e.readWrite, x), i = Atomics.waitAsync(e.readWrite, x, n, 100);
841
+ i.async && await i.value;
850
842
  } catch {
843
+ await new Promise((n) => setTimeout(n, 10));
851
844
  }
852
- S = null;
853
845
  }
854
846
  }
855
- function P(t) {
856
- if (t.stopped)
847
+ function Qe() {
848
+ for (const t of f.values())
849
+ if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
850
+ try {
851
+ const e = t.ringBuffer.pop(t.ringTemp);
852
+ e > 0 && T(t, t.ringTemp.subarray(0, e));
853
+ } catch (e) {
854
+ I(e, t.captureId);
855
+ }
856
+ }
857
+ function et(t) {
858
+ if (Xe()) {
859
+ if (!F.has(t.captureId)) {
860
+ const e = Ze(t);
861
+ F.set(t.captureId, e), e.finally(() => {
862
+ F.delete(t.captureId);
863
+ });
864
+ }
865
+ } else
866
+ A === null && (A = self.setInterval(Qe, 50));
867
+ }
868
+ function tt(t) {
869
+ if (F.delete(t), A !== null) {
870
+ let e = !1;
871
+ for (const r of f.values())
872
+ if (r.transport === "sab" && !r.stopped) {
873
+ e = !0;
874
+ break;
875
+ }
876
+ if (!e) {
877
+ try {
878
+ self.clearInterval(A);
879
+ } catch {
880
+ }
881
+ A = null;
882
+ }
883
+ }
884
+ }
885
+ function v(t) {
886
+ if (t.stopped || t.isReconfiguring)
857
887
  return;
858
888
  if (!t.inSegment) {
859
889
  t.pendingReadOffset = 0, t.pendingWriteOffset = 0, t.pendingSamples = 0;
@@ -869,7 +899,7 @@ function P(t) {
869
899
  r.set(t.pendingBuffer.subarray(i, n)), r.set(t.pendingBuffer.subarray(0, e - a), a);
870
900
  }
871
901
  t.pendingReadOffset = (i + e) % n, t.pendingSamples -= e;
872
- const s = Ge(r);
902
+ const s = Je(r);
873
903
  t.lastVolume = s;
874
904
  try {
875
905
  if (t.useWasmEncoder)
@@ -886,12 +916,12 @@ function P(t) {
886
916
  t.encoder.encode(a), a.close();
887
917
  }
888
918
  } catch (a) {
889
- g(a, t.captureId);
919
+ I(a, t.captureId);
890
920
  }
891
921
  t.timestampUs += t.frameDurationUs;
892
922
  }
893
923
  }
894
- function W(t, e) {
924
+ function T(t, e) {
895
925
  if (t.stopped)
896
926
  return;
897
927
  const r = e.length;
@@ -899,42 +929,42 @@ function W(t, e) {
899
929
  return;
900
930
  const n = t.pendingSamples + r;
901
931
  if (n > t.pendingBuffer.length) {
902
- const a = Math.max(n, t.pendingBuffer.length * 2), u = new Float32Array(a);
932
+ const a = Math.max(n, t.pendingBuffer.length * 2), c = new Float32Array(a);
903
933
  if (t.pendingSamples > 0) {
904
- const c = t.pendingBuffer.length;
905
- if (t.pendingReadOffset + t.pendingSamples <= c)
906
- u.set(t.pendingBuffer.subarray(t.pendingReadOffset, t.pendingReadOffset + t.pendingSamples));
934
+ const l = t.pendingBuffer.length;
935
+ if (t.pendingReadOffset + t.pendingSamples <= l)
936
+ c.set(t.pendingBuffer.subarray(t.pendingReadOffset, t.pendingReadOffset + t.pendingSamples));
907
937
  else {
908
- const d = c - t.pendingReadOffset;
909
- u.set(t.pendingBuffer.subarray(t.pendingReadOffset, c)), u.set(t.pendingBuffer.subarray(0, t.pendingSamples - d), d);
938
+ const o = l - t.pendingReadOffset;
939
+ c.set(t.pendingBuffer.subarray(t.pendingReadOffset, l)), c.set(t.pendingBuffer.subarray(0, t.pendingSamples - o), o);
910
940
  }
911
941
  }
912
- t.pendingBuffer = u, t.pendingReadOffset = 0, t.pendingWriteOffset = t.pendingSamples;
942
+ t.pendingBuffer = c, t.pendingReadOffset = 0, t.pendingWriteOffset = t.pendingSamples;
913
943
  }
914
944
  const i = t.pendingBuffer.length, s = Math.min(r, i - t.pendingWriteOffset);
915
- t.pendingBuffer.set(e.subarray(0, s), t.pendingWriteOffset), s < r && t.pendingBuffer.set(e.subarray(s), 0), t.pendingWriteOffset = (t.pendingWriteOffset + r) % i, t.pendingSamples += r, P(t);
945
+ t.pendingBuffer.set(e.subarray(0, s), t.pendingWriteOffset), s < r && t.pendingBuffer.set(e.subarray(s), 0), t.pendingWriteOffset = (t.pendingWriteOffset + r) % i, t.pendingSamples += r, v(t);
916
946
  }
917
- function H(t, e, r, n, i = !0) {
918
- const s = h.get(t.captureId);
947
+ function B(t, e, r, n, i = !0) {
948
+ const s = f.get(t.captureId);
919
949
  if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
920
950
  return;
921
951
  const a = e.byteLength;
922
952
  s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(e);
923
- const u = s.encoderOutputBuffer.subarray(0, a), c = s.segmentStartPending;
924
- c && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
925
- const d = s.segmentEndPending;
926
- d && (s.segmentEndPending = !1, s.inSegment = !1);
927
- const w = s.frameSize * s.channels, I = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
928
- L(
929
- le(
930
- ae({
931
- Samples: u,
953
+ const c = s.encoderOutputBuffer.subarray(0, a), l = s.segmentStartPending;
954
+ l && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
955
+ const o = s.segmentEndPending;
956
+ o && (s.segmentEndPending = !1, s.inSegment = !1);
957
+ const d = s.frameSize * s.channels, y = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
958
+ C(
959
+ fe(
960
+ ue({
961
+ Samples: c,
932
962
  Epoch: s.epoch,
933
963
  Sequence: s.sequence,
934
- FrameSizeInInterleavedSamples: w,
935
- TimeStampInInterleavedSamples: I,
936
- IsFirst: c,
937
- IsLast: d,
964
+ FrameSizeInInterleavedSamples: d,
965
+ TimeStampInInterleavedSamples: y,
966
+ IsFirst: l,
967
+ IsLast: o,
938
968
  AverageVolume: s.lastVolume,
939
969
  AudioEventEstimatedDuration: 0
940
970
  }),
@@ -943,14 +973,14 @@ function H(t, e, r, n, i = !0) {
943
973
  )
944
974
  ), s.sequence++;
945
975
  }
946
- function Ze(t) {
947
- const e = Math.max(T, Math.floor(t.options?.bitrate ?? M)), r = new AudioEncoder({
976
+ function rt(t) {
977
+ const e = Math.max(M, Math.floor(t.options?.bitrate ?? b)), r = new AudioEncoder({
948
978
  output: (n) => {
949
- const i = h.get(t.captureId);
979
+ const i = f.get(t.captureId);
950
980
  if (!i)
951
981
  return;
952
982
  const s = n.byteLength;
953
- i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer), H(
983
+ i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer), B(
954
984
  i,
955
985
  i.encoderOutputBuffer.subarray(0, s),
956
986
  n.timestamp ?? i.timestampUs,
@@ -959,7 +989,7 @@ function Ze(t) {
959
989
  );
960
990
  },
961
991
  error: (n) => {
962
- g(n, t.captureId);
992
+ I(n, t.captureId);
963
993
  }
964
994
  });
965
995
  return r.configure({
@@ -975,23 +1005,23 @@ function Ze(t) {
975
1005
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
976
1006
  }), r;
977
1007
  }
978
- function Qe(t) {
979
- const e = Math.max(T, Math.floor(t.options?.bitrate ?? M));
980
- return new je({
1008
+ function nt(t) {
1009
+ const e = Math.max(M, Math.floor(t.options?.bitrate ?? b));
1010
+ return new $({
981
1011
  sampleRate: t.sampleRate,
982
1012
  channels: t.channels,
983
1013
  bitrate: e,
984
1014
  frameSize: t.frameSize,
985
1015
  onOutput: (r, n, i) => {
986
- const s = h.get(t.captureId);
987
- s && H(s, r, n, i, !0);
1016
+ const s = f.get(t.captureId);
1017
+ s && B(s, r, n, i, !0);
988
1018
  },
989
1019
  onError: (r) => {
990
- g(r, t.captureId);
1020
+ I(r, t.captureId);
991
1021
  }
992
1022
  });
993
1023
  }
994
- async function Xe() {
1024
+ async function it() {
995
1025
  if (typeof AudioEncoder > "u")
996
1026
  return !1;
997
1027
  try {
@@ -1004,12 +1034,15 @@ async function Xe() {
1004
1034
  return !1;
1005
1035
  }
1006
1036
  }
1007
- async function et(t) {
1008
- if (!p)
1037
+ async function st(t) {
1038
+ if (!m)
1009
1039
  throw new Error("Audio capture worker missing send port");
1010
- if (h.has(t.captureId))
1040
+ if (f.has(t.captureId)) {
1041
+ const h = f.get(t.captureId);
1042
+ O({ type: "started", captureId: t.captureId, sampleRate: h.sampleRate, channels: h.channels });
1011
1043
  return;
1012
- const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * Ke / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
1044
+ }
1045
+ const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * qe / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
1013
1046
  captureId: t.captureId,
1014
1047
  streamId: t.streamId,
1015
1048
  sourceType: t.sourceType,
@@ -1039,52 +1072,53 @@ async function et(t) {
1039
1072
  lastVolume: 0,
1040
1073
  targetIds: t.options?.targetIds,
1041
1074
  options: t.options
1042
- }, c = (t.options?.preferWebCodecs ?? !0) && await Xe();
1043
- let d, w = !1;
1044
- const I = Math.max(T, Math.floor(t.options?.bitrate ?? M));
1045
- if (c)
1046
- d = Ze(a), F.info(
1047
- `Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1075
+ }, l = (t.options?.preferWebCodecs ?? !0) && await it();
1076
+ let o, d = !1;
1077
+ const y = Math.max(M, Math.floor(t.options?.bitrate ?? b));
1078
+ if (l)
1079
+ o = rt(a), E.debug(
1080
+ `Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
1048
1081
  );
1049
1082
  else {
1050
- const l = Qe(a);
1051
- await l.initialize(), d = l, w = !0, F.info(
1052
- `Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1083
+ const h = nt(a);
1084
+ await h.initialize(), o = h, d = !0, E.debug(
1085
+ `Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
1053
1086
  );
1054
1087
  }
1055
- const y = {
1088
+ const p = {
1056
1089
  ...a,
1057
- encoder: d,
1058
- useWasmEncoder: w
1090
+ encoder: o,
1091
+ useWasmEncoder: d,
1092
+ isReconfiguring: !1
1059
1093
  };
1060
1094
  if (t.transport === "sab") {
1061
1095
  if (!t.sharedArrayBuffer)
1062
1096
  throw new Error("Missing SharedArrayBuffer for sab transport");
1063
- const l = new ve(t.sharedArrayBuffer, Float32Array);
1064
- y.ringBuffer = l, y.ringTemp = new Float32Array(Math.max(y.frameSize * 4, 4096)), Ye();
1097
+ const h = new xe(t.sharedArrayBuffer, Float32Array);
1098
+ p.ringBuffer = h, p.ringTemp = new Float32Array(Math.max(p.frameSize * 4, 4096)), et(p);
1065
1099
  }
1066
- h.set(t.captureId, y), L(
1067
- Oe(
1068
- _e({
1100
+ f.set(t.captureId, p), C(
1101
+ Me(
1102
+ De({
1069
1103
  StreamId: t.streamId,
1070
1104
  Description: `mic:${t.streamId}`,
1071
1105
  SourceType: t.sourceType,
1072
- Codec: R.Opus,
1106
+ Codec: W.Opus,
1073
1107
  CodecDetails: "",
1074
1108
  SampleRate: e,
1075
1109
  Channels: r
1076
1110
  }),
1077
1111
  t.senderId,
1078
- { trackId: t.trackId, targetIds: y.targetIds }
1112
+ { trackId: t.trackId, targetIds: p.targetIds }
1079
1113
  )
1080
- ), V({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1114
+ ), O({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1081
1115
  }
1082
- async function z(t) {
1083
- const e = h.get(t);
1116
+ async function j(t) {
1117
+ const e = f.get(t);
1084
1118
  if (e) {
1085
- e.stopped = !0, h.delete(t);
1119
+ e.stopped = !0, f.delete(t);
1086
1120
  try {
1087
- P(e);
1121
+ v(e);
1088
1122
  } catch {
1089
1123
  }
1090
1124
  try {
@@ -1095,75 +1129,161 @@ async function z(t) {
1095
1129
  e.encoder.close();
1096
1130
  } catch {
1097
1131
  }
1098
- L(Ce(Pe({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), V({ type: "stopped", captureId: e.captureId }), Je();
1132
+ C(ke(ve({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), O({ type: "stopped", captureId: e.captureId }), tt(t);
1099
1133
  }
1100
1134
  }
1101
- function tt(t) {
1102
- const e = h.get(t);
1135
+ function at(t) {
1136
+ const e = f.get(t);
1103
1137
  !e || e.stopped || (e.inSegment = !0, e.segmentStartPending = !0);
1104
1138
  }
1105
- function rt(t) {
1106
- const e = h.get(t);
1107
- if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, P(e), e.segmentEndPending && !e.stopped)) {
1139
+ function ot(t) {
1140
+ const e = f.get(t);
1141
+ if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, v(e), e.segmentEndPending && !e.stopped)) {
1108
1142
  const r = e.frameSize - e.pendingSamples;
1109
1143
  if (r > 0) {
1110
1144
  const n = new Float32Array(r);
1111
- W(e, n);
1145
+ T(e, n);
1112
1146
  }
1113
1147
  }
1114
1148
  }
1115
- function nt() {
1116
- for (const t of Array.from(h.keys()))
1117
- z(t);
1118
- if (p) {
1149
+ async function ct(t, e) {
1150
+ const r = f.get(t);
1151
+ if (!r || r.stopped)
1152
+ return;
1153
+ const n = r.options?.bitrate ?? b, i = e.bitrate ?? b;
1154
+ if (n === i) {
1155
+ r.options = e;
1156
+ return;
1157
+ }
1158
+ r.isReconfiguring = !0, r.options = e;
1159
+ const s = Math.max(M, Math.floor(i));
1160
+ let a;
1161
+ if (r.useWasmEncoder) {
1162
+ const l = new $({
1163
+ sampleRate: r.sampleRate,
1164
+ channels: r.channels,
1165
+ bitrate: s,
1166
+ frameSize: r.frameSize,
1167
+ onOutput: (o, d, y) => {
1168
+ const p = f.get(r.captureId);
1169
+ !p || p.isReconfiguring || B(p, o, d, y, !0);
1170
+ },
1171
+ onError: (o) => {
1172
+ I(o, r.captureId);
1173
+ }
1174
+ });
1119
1175
  try {
1120
- p.close();
1176
+ await l.initialize();
1177
+ } catch (o) {
1178
+ r.isReconfiguring = !1, I(o, t);
1179
+ return;
1180
+ }
1181
+ a = l;
1182
+ } else {
1183
+ const l = new AudioEncoder({
1184
+ output: (o) => {
1185
+ const d = f.get(r.captureId);
1186
+ if (!d || d.isReconfiguring)
1187
+ return;
1188
+ const y = o.byteLength;
1189
+ d.encoderOutputBuffer.length < y && (d.encoderOutputBuffer = new Uint8Array(Math.max(y, d.encoderOutputBuffer.length * 2))), o.copyTo(d.encoderOutputBuffer), B(
1190
+ d,
1191
+ d.encoderOutputBuffer.subarray(0, y),
1192
+ o.timestamp ?? d.timestampUs,
1193
+ o.duration ?? d.frameDurationUs,
1194
+ o.type === "key"
1195
+ );
1196
+ },
1197
+ error: (o) => {
1198
+ I(o, r.captureId);
1199
+ }
1200
+ });
1201
+ l.configure({
1202
+ codec: "opus",
1203
+ numberOfChannels: r.channels,
1204
+ sampleRate: r.sampleRate,
1205
+ bitrate: s,
1206
+ bitrateMode: "constant",
1207
+ opus: {
1208
+ application: "lowdelay",
1209
+ signal: "voice"
1210
+ }
1211
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1212
+ }), a = l;
1213
+ }
1214
+ const c = r.encoder;
1215
+ try {
1216
+ await c.flush();
1217
+ } catch {
1218
+ }
1219
+ try {
1220
+ c.close();
1221
+ } catch {
1222
+ }
1223
+ r.encoder = a, r.isReconfiguring = !1, E.debug(`Audio capture bitrate updated: ${s}bps`);
1224
+ }
1225
+ async function ut() {
1226
+ const t = Array.from(f.keys()).map(
1227
+ (e) => j(e).catch(() => {
1228
+ })
1229
+ );
1230
+ if (await Promise.all(t), m) {
1231
+ try {
1232
+ m.close();
1121
1233
  } catch {
1122
1234
  }
1123
- p = null;
1235
+ m = null;
1124
1236
  }
1125
1237
  }
1126
1238
  self.addEventListener("message", (t) => {
1127
1239
  const e = t.data;
1128
1240
  if (e.type === "attachSendPort") {
1129
- if (p)
1241
+ if (m)
1130
1242
  try {
1131
- p.close();
1243
+ m.close();
1132
1244
  } catch {
1133
1245
  }
1134
- p = e.port;
1246
+ m = e.port;
1135
1247
  try {
1136
- p.start?.();
1248
+ m.start?.();
1137
1249
  } catch {
1138
1250
  }
1139
1251
  return;
1140
1252
  }
1141
1253
  if (e.type === "start") {
1142
- et(e).catch((r) => {
1143
- g(r, e.captureId);
1254
+ st(e).catch((r) => {
1255
+ I(r, e.captureId);
1144
1256
  });
1145
1257
  return;
1146
1258
  }
1147
1259
  if (e.type === "pcm") {
1148
- const r = h.get(e.captureId);
1260
+ const r = f.get(e.captureId);
1149
1261
  if (!r || r.stopped)
1150
1262
  return;
1151
- W(r, e.pcm);
1263
+ T(r, e.pcm);
1152
1264
  return;
1153
1265
  }
1154
1266
  if (e.type === "stop") {
1155
- z(e.captureId).catch((r) => {
1156
- F.warn(`Failed to stop audio capture: ${r}`), g(r, e.captureId);
1267
+ j(e.captureId).catch((r) => {
1268
+ E.warn(`Failed to stop audio capture: ${r}`), I(r, e.captureId);
1157
1269
  });
1158
1270
  return;
1159
1271
  }
1160
1272
  if (e.type === "startSegment") {
1161
- tt(e.captureId);
1273
+ at(e.captureId);
1162
1274
  return;
1163
1275
  }
1164
1276
  if (e.type === "endSegment") {
1165
- rt(e.captureId);
1277
+ ot(e.captureId);
1278
+ return;
1279
+ }
1280
+ if (e.type === "updateOptions") {
1281
+ ct(e.captureId, e.options).catch((r) => {
1282
+ E.warn(`Failed to update audio capture options: ${r}`), I(r, e.captureId);
1283
+ });
1166
1284
  return;
1167
1285
  }
1168
- e.type === "dispose" && nt();
1286
+ e.type === "dispose" && ut().catch((r) => {
1287
+ E.warn(`Failed to dispose audio capture worker: ${r}`);
1288
+ });
1169
1289
  });