@ikonai/sdk 1.0.13 → 1.0.14

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,17 +1,17 @@
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 R(t, e, r, n, i) {
2
+ const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, c = i?.flags ?? 0, u = i?.targetIds ?? [], d = i?.payloadType ?? 8, w = 27 + u.length * 4, I = w + e.length, p = new Uint8Array(I), l = new DataView(p.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, u.length >>> 0, !0), l.setUint8(24, r & 255), l.setUint8(25, d & 255), l.setUint8(26, c & 255);
4
+ let v = 27;
5
+ for (let O = 0; O < u.length; O++)
6
+ l.setUint32(v, u[O] >>> 0, !0), v += 4;
7
+ return p.set(e, w), p;
8
8
  }
9
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();
10
+ const j = 161, q = 162, _ = new TextEncoder();
11
11
  new TextDecoder("utf-8", { fatal: !0 });
12
- class E {
12
+ class g {
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(j), this.buffer.writeVarUInt(e >>> 0);
15
15
  }
16
16
  buffer = new m();
17
17
  closed = !1;
@@ -44,32 +44,32 @@ class E {
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 = _.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 g(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 D(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 M(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(q), 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,10 +78,10 @@ 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(F(r)), Y(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
- class U {
84
+ class D {
85
85
  constructor(e) {
86
86
  this.elementType = e;
87
87
  }
@@ -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 = _.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 g(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 D(e);
172
172
  r(n);
173
173
  const i = n.finish();
174
174
  this.payload.writeBytes(i);
@@ -178,23 +178,23 @@ class U {
178
178
  10
179
179
  /* Dict */
180
180
  ), this.count++;
181
- const i = new B(e, r);
181
+ const i = new M(e, r);
182
182
  n(i);
183
183
  const s = i.finish();
184
184
  this.payload.writeBytes(s);
185
185
  }
186
186
  finish() {
187
187
  const e = new m();
188
- return e.writeByte(_(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
188
+ return e.writeByte(F(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
192
  throw new Error(`Array element type is ${f[this.elementType]}, expected ${f[e]}`);
193
193
  }
194
194
  }
195
- class B {
195
+ class M {
196
196
  constructor(e, r) {
197
- this.keyType = e, this.valueType = r, G(e);
197
+ this.keyType = e, this.valueType = r, J(e);
198
198
  }
199
199
  payload = new m();
200
200
  count = 0;
@@ -202,7 +202,7 @@ class B {
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 G(this.keyType, this.valueType, this.payload, () => {
206
206
  this.entryOpen = !1;
207
207
  });
208
208
  }
@@ -210,10 +210,10 @@ class B {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
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();
213
+ return e.writeByte(F(this.keyType)), e.writeByte(F(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
214
214
  }
215
215
  }
216
- class j {
216
+ class G {
217
217
  constructor(e, r, n, i) {
218
218
  this.keyType = e, this.valueType = r, this.payload = n, this.onComplete = i;
219
219
  }
@@ -277,7 +277,7 @@ class j {
277
277
  12
278
278
  /* String */
279
279
  );
280
- const r = b.encode(e ?? "");
280
+ const r = _.encode(e ?? "");
281
281
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
282
282
  }
283
283
  writeKeyBinary(e) {
@@ -355,7 +355,7 @@ class j {
355
355
  12
356
356
  /* String */
357
357
  );
358
- const r = b.encode(e ?? "");
358
+ const r = _.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 g(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 D(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 M(e, r);
387
387
  n(i);
388
388
  const s = i.finish();
389
389
  this.payload.writeBytes(s), this.valueWritten = !0;
@@ -416,8 +416,8 @@ class o {
416
416
  throw new Error("Guid string must be 32 hex characters");
417
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
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);
419
+ for (let c = 0; c < 8; c++)
420
+ n[8 + c] = o.parseHexSlice(r, 16 + c * 2, 2);
421
421
  return new o(n);
422
422
  }
423
423
  static fromBytes(e) {
@@ -443,8 +443,8 @@ class o {
443
443
  o.toHex(o.readUInt32LE(e, 0), 8),
444
444
  o.toHex(o.readUInt16LE(e, 4), 4),
445
445
  o.toHex(o.readUInt16LE(e, 6), 4),
446
- v(e.subarray(8, 10)),
447
- v(e.subarray(10, 16))
446
+ N(e.subarray(8, 10)),
447
+ N(e.subarray(10, 16))
448
448
  ].join("-");
449
449
  }
450
450
  asBytes() {
@@ -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 F(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 Y(t) {
535
535
  return t === 12 || t === 13 || t === 9 || t === 11 || t === 10;
536
536
  }
537
- function G(t) {
537
+ function J(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 N(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 T = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.Opus = 1] = "Opus", t[t.Mp3 = 2] = "Mp3", t[t.RawPcm16 = 3] = "RawPcm16", t))(T || {});
545
+ const x = 1, X = 4194309, Z = 205938238, Q = 717315017, ee = 1594075008, te = 2026534360, re = 3409001585, ne = 3466650495, ie = 4007456593, se = 4017217601, ae = 4065417427, oe = 4086360332;
546
+ function ce(t) {
547
547
  const e = {};
548
- return oe(e), t && Object.assign(e, t), e;
548
+ return ue(e), t && Object.assign(e, t), e;
549
549
  }
550
- function oe(t) {
550
+ function ue(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 le(t) {
554
+ const e = new g(x);
555
+ return de(t, e), e.finish();
556
556
  }
557
- function ce(t, e) {
558
- e.writeFloat32Field(J, t.AverageVolume);
557
+ function de(t, e) {
558
+ e.writeFloat32Field(Z, t.AverageVolume);
559
559
  const r = t.ShapeSetValues;
560
- r != null && e.writeArrayField(Z, f.Object, (n) => {
560
+ r != null && e.writeArrayField(Q, f.Object, (n) => {
561
561
  for (const i of r)
562
- n.writeObject(de, (s) => {
563
- pe(i, s);
562
+ n.writeObject(fe, (s) => {
563
+ we(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(ee, t.IsFirst), e.writeUInt64Field(te, t.TimeStampInInterleavedSamples), e.writeBinaryField(re, t.Samples), e.writeFloat32Field(ne, t.AudioEventEstimatedDuration), e.writeUInt32Field(ie, t.FrameSizeInInterleavedSamples >>> 0), e.writeBoolField(se, t.IsLast), e.writeUInt32Field(ae, t.Sequence >>> 0), e.writeUInt32Field(oe, 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 he(t, e, r) {
568
+ const n = le(t);
569
+ return R(X, n, x, 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 fe = 1, pe = 1154362099, ye = 3974819915;
572
+ function we(t, e) {
573
+ e.writeUInt32Field(pe, t.SetId >>> 0), e.writeArrayField(ye, f.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, Ie = 4194305, me = 161083277, Ee = 265814330, ge = 1368629611, Se = 2431514951, Ae = 2745379226, be = 3282782683, _e = 3284746250, Fe = 4101844078;
579
+ function Ue(t) {
580
580
  const e = {};
581
- return Fe(e), t && Object.assign(e, t), e;
581
+ return De(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 De(t) {
584
+ return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = T.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 g(H);
588
+ return Oe(t, e), e.finish();
589
589
  }
590
- function De(t, e) {
591
- e.writeStringField(we, t.StreamId);
590
+ function Oe(t, e) {
591
+ e.writeStringField(me, t.StreamId);
592
592
  const r = t.ShapeSets;
593
- r != null && e.writeArrayField(Ie, f.Object, (n) => {
593
+ r != null && e.writeArrayField(Ee, f.Object, (n) => {
594
594
  for (const i of r)
595
- n.writeObject(Be, (s) => {
596
- Ve(i, s);
595
+ n.writeObject(Me, (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(ge, t.Description), e.writeInt32Field(Se, t.Channels | 0), e.writeStringField(Ae, t.CodecDetails), e.writeStringField(be, t.SourceType), e.writeInt32Field(_e, t.Codec), e.writeInt32Field(Fe, 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 Re(t, e, r) {
601
+ const n = Be(t);
602
+ return R(Ie, 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 Me = 5, Te = 1107713536, Ve = 1154362099, Le = 1185721362;
605
+ function We(t, e) {
606
+ e.writeStringField(Te, t.Name), e.writeUInt32Field(Ve, t.SetId >>> 0), e.writeArrayField(Le, f.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 z = 1, Pe = 4194306;
612
+ function Ce(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 ve(t) {
617
+ return new g(z).finish();
618
618
  }
619
- function Ce(t, e, r) {
620
- const n = We();
621
- return O(Le, n, x, e, r);
619
+ function Ne(t, e, r) {
620
+ const n = ve();
621
+ return R(Pe, n, z, e, r);
622
622
  }
623
- class ve {
623
+ class ke {
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 xe = 1;
678
+ const He = /* @__PURE__ */ new Map(), ze = {
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 Ke(t, e) {
686
686
  return `[${t}] ${e}`;
687
687
  }
688
688
  function A(t, e, r, n) {
689
- const i = (/* @__PURE__ */ new Date()).toISOString(), s = xe[t], a = {
689
+ const i = (/* @__PURE__ */ new Date()).toISOString(), s = ze[t], a = {
690
690
  timestamp: i,
691
691
  level: t,
692
692
  levelName: s,
@@ -694,33 +694,33 @@ 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;
697
+ for (const [c, u] of He) {
698
+ const d = u?.minLevel ?? 2;
699
699
  if (t >= d)
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 (xe <= t) {
706
+ const c = Ke(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 $e(t) {
724
724
  return {
725
725
  debug(e, ...r) {
726
726
  A(0, t, e, r);
@@ -736,8 +736,8 @@ function ze(t) {
736
736
  }
737
737
  };
738
738
  }
739
- const Ke = 20, M = 32e3, $e = 5, T = 8e3, F = ze("AudioCaptureWorker");
740
- class je {
739
+ const je = 20, V = 32e3, qe = 5, L = 8e3, U = $e("AudioCaptureWorker");
740
+ class Ge {
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: qe
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 W = (t) => self.postMessage(t);
798
+ let y = null;
799
+ function E(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
+ W({ 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 P(t) {
807
+ if (!y) {
808
+ U.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
+ y.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,40 +819,70 @@ 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();
822
+ const h = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map();
823
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));
824
+ const k = 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 && B(t, r.subarray(0, n));
836
+ } catch (n) {
837
+ E(n, t.captureId);
846
838
  }
847
- if (!t) {
848
839
  try {
849
- self.clearInterval(S);
840
+ const n = Atomics.load(e.readWrite, k), i = Atomics.waitAsync(e.readWrite, k, 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) {
847
+ function Qe() {
848
+ for (const t of h.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 && B(t, t.ringTemp.subarray(0, e));
853
+ } catch (e) {
854
+ E(e, t.captureId);
855
+ }
856
+ }
857
+ function et(t) {
858
+ if (Xe()) {
859
+ if (!b.has(t.captureId)) {
860
+ const e = Ze(t);
861
+ b.set(t.captureId, e), e.finally(() => {
862
+ b.delete(t.captureId);
863
+ });
864
+ }
865
+ } else
866
+ S === null && (S = self.setInterval(Qe, 50));
867
+ }
868
+ function tt(t) {
869
+ if (b.delete(t), S !== null) {
870
+ let e = !1;
871
+ for (const r of h.values())
872
+ if (r.transport === "sab" && !r.stopped) {
873
+ e = !0;
874
+ break;
875
+ }
876
+ if (!e) {
877
+ try {
878
+ self.clearInterval(S);
879
+ } catch {
880
+ }
881
+ S = null;
882
+ }
883
+ }
884
+ }
885
+ function C(t) {
856
886
  if (t.stopped)
857
887
  return;
858
888
  if (!t.inSegment) {
@@ -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
+ E(a, t.captureId);
890
920
  }
891
921
  t.timestampUs += t.frameDurationUs;
892
922
  }
893
923
  }
894
- function W(t, e) {
924
+ function B(t, e) {
895
925
  if (t.stopped)
896
926
  return;
897
927
  const r = e.length;
@@ -899,41 +929,41 @@ 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 u = t.pendingBuffer.length;
935
+ if (t.pendingReadOffset + t.pendingSamples <= u)
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 d = u - t.pendingReadOffset;
939
+ c.set(t.pendingBuffer.subarray(t.pendingReadOffset, u)), c.set(t.pendingBuffer.subarray(0, t.pendingSamples - d), d);
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, C(t);
916
946
  }
917
- function H(t, e, r, n, i = !0) {
947
+ function K(t, e, r, n, i = !0) {
918
948
  const s = h.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);
953
+ const c = s.encoderOutputBuffer.subarray(0, a), u = s.segmentStartPending;
954
+ u && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
925
955
  const d = s.segmentEndPending;
926
956
  d && (s.segmentEndPending = !1, s.inSegment = !1);
927
957
  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,
958
+ P(
959
+ he(
960
+ ce({
961
+ Samples: c,
932
962
  Epoch: s.epoch,
933
963
  Sequence: s.sequence,
934
964
  FrameSizeInInterleavedSamples: w,
935
965
  TimeStampInInterleavedSamples: I,
936
- IsFirst: c,
966
+ IsFirst: u,
937
967
  IsLast: d,
938
968
  AverageVolume: s.lastVolume,
939
969
  AudioEventEstimatedDuration: 0
@@ -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(L, Math.floor(t.options?.bitrate ?? V)), r = new AudioEncoder({
948
978
  output: (n) => {
949
979
  const i = h.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), K(
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
+ E(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(L, Math.floor(t.options?.bitrate ?? V));
1010
+ return new Ge({
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
1016
  const s = h.get(t.captureId);
987
- s && H(s, r, n, i, !0);
1017
+ s && K(s, r, n, i, !0);
988
1018
  },
989
1019
  onError: (r) => {
990
- g(r, t.captureId);
1020
+ E(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,12 @@ 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 (!y)
1009
1039
  throw new Error("Audio capture worker missing send port");
1010
1040
  if (h.has(t.captureId))
1011
1041
  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 = {
1042
+ const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * je / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
1013
1043
  captureId: t.captureId,
1014
1044
  streamId: t.streamId,
1015
1045
  sourceType: t.sourceType,
@@ -1039,20 +1069,20 @@ async function et(t) {
1039
1069
  lastVolume: 0,
1040
1070
  targetIds: t.options?.targetIds,
1041
1071
  options: t.options
1042
- }, c = (t.options?.preferWebCodecs ?? !0) && await Xe();
1072
+ }, u = (t.options?.preferWebCodecs ?? !0) && await it();
1043
1073
  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(
1074
+ const I = Math.max(L, Math.floor(t.options?.bitrate ?? V));
1075
+ if (u)
1076
+ d = rt(a), U.info(
1047
1077
  `Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1048
1078
  );
1049
1079
  else {
1050
- const l = Qe(a);
1051
- await l.initialize(), d = l, w = !0, F.info(
1080
+ const l = nt(a);
1081
+ await l.initialize(), d = l, w = !0, U.info(
1052
1082
  `Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1053
1083
  );
1054
1084
  }
1055
- const y = {
1085
+ const p = {
1056
1086
  ...a,
1057
1087
  encoder: d,
1058
1088
  useWasmEncoder: w
@@ -1060,31 +1090,31 @@ async function et(t) {
1060
1090
  if (t.transport === "sab") {
1061
1091
  if (!t.sharedArrayBuffer)
1062
1092
  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();
1093
+ const l = new ke(t.sharedArrayBuffer, Float32Array);
1094
+ p.ringBuffer = l, p.ringTemp = new Float32Array(Math.max(p.frameSize * 4, 4096)), et(p);
1065
1095
  }
1066
- h.set(t.captureId, y), L(
1067
- Oe(
1068
- _e({
1096
+ h.set(t.captureId, p), P(
1097
+ Re(
1098
+ Ue({
1069
1099
  StreamId: t.streamId,
1070
1100
  Description: `mic:${t.streamId}`,
1071
1101
  SourceType: t.sourceType,
1072
- Codec: R.Opus,
1102
+ Codec: T.Opus,
1073
1103
  CodecDetails: "",
1074
1104
  SampleRate: e,
1075
1105
  Channels: r
1076
1106
  }),
1077
1107
  t.senderId,
1078
- { trackId: t.trackId, targetIds: y.targetIds }
1108
+ { trackId: t.trackId, targetIds: p.targetIds }
1079
1109
  )
1080
- ), V({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1110
+ ), W({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1081
1111
  }
1082
- async function z(t) {
1112
+ async function $(t) {
1083
1113
  const e = h.get(t);
1084
1114
  if (e) {
1085
1115
  e.stopped = !0, h.delete(t);
1086
1116
  try {
1087
- P(e);
1117
+ C(e);
1088
1118
  } catch {
1089
1119
  }
1090
1120
  try {
@@ -1095,52 +1125,52 @@ async function z(t) {
1095
1125
  e.encoder.close();
1096
1126
  } catch {
1097
1127
  }
1098
- L(Ce(Pe({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), V({ type: "stopped", captureId: e.captureId }), Je();
1128
+ P(Ne(Ce({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), W({ type: "stopped", captureId: e.captureId }), tt(t);
1099
1129
  }
1100
1130
  }
1101
- function tt(t) {
1131
+ function at(t) {
1102
1132
  const e = h.get(t);
1103
1133
  !e || e.stopped || (e.inSegment = !0, e.segmentStartPending = !0);
1104
1134
  }
1105
- function rt(t) {
1135
+ function ot(t) {
1106
1136
  const e = h.get(t);
1107
- if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, P(e), e.segmentEndPending && !e.stopped)) {
1137
+ if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, C(e), e.segmentEndPending && !e.stopped)) {
1108
1138
  const r = e.frameSize - e.pendingSamples;
1109
1139
  if (r > 0) {
1110
1140
  const n = new Float32Array(r);
1111
- W(e, n);
1141
+ B(e, n);
1112
1142
  }
1113
1143
  }
1114
1144
  }
1115
- function nt() {
1145
+ function ct() {
1116
1146
  for (const t of Array.from(h.keys()))
1117
- z(t);
1118
- if (p) {
1147
+ $(t);
1148
+ if (y) {
1119
1149
  try {
1120
- p.close();
1150
+ y.close();
1121
1151
  } catch {
1122
1152
  }
1123
- p = null;
1153
+ y = null;
1124
1154
  }
1125
1155
  }
1126
1156
  self.addEventListener("message", (t) => {
1127
1157
  const e = t.data;
1128
1158
  if (e.type === "attachSendPort") {
1129
- if (p)
1159
+ if (y)
1130
1160
  try {
1131
- p.close();
1161
+ y.close();
1132
1162
  } catch {
1133
1163
  }
1134
- p = e.port;
1164
+ y = e.port;
1135
1165
  try {
1136
- p.start?.();
1166
+ y.start?.();
1137
1167
  } catch {
1138
1168
  }
1139
1169
  return;
1140
1170
  }
1141
1171
  if (e.type === "start") {
1142
- et(e).catch((r) => {
1143
- g(r, e.captureId);
1172
+ st(e).catch((r) => {
1173
+ E(r, e.captureId);
1144
1174
  });
1145
1175
  return;
1146
1176
  }
@@ -1148,22 +1178,22 @@ self.addEventListener("message", (t) => {
1148
1178
  const r = h.get(e.captureId);
1149
1179
  if (!r || r.stopped)
1150
1180
  return;
1151
- W(r, e.pcm);
1181
+ B(r, e.pcm);
1152
1182
  return;
1153
1183
  }
1154
1184
  if (e.type === "stop") {
1155
- z(e.captureId).catch((r) => {
1156
- F.warn(`Failed to stop audio capture: ${r}`), g(r, e.captureId);
1185
+ $(e.captureId).catch((r) => {
1186
+ U.warn(`Failed to stop audio capture: ${r}`), E(r, e.captureId);
1157
1187
  });
1158
1188
  return;
1159
1189
  }
1160
1190
  if (e.type === "startSegment") {
1161
- tt(e.captureId);
1191
+ at(e.captureId);
1162
1192
  return;
1163
1193
  }
1164
1194
  if (e.type === "endSegment") {
1165
- rt(e.captureId);
1195
+ ot(e.captureId);
1166
1196
  return;
1167
1197
  }
1168
- e.type === "dispose" && nt();
1198
+ e.type === "dispose" && ct();
1169
1199
  });