@ikonai/sdk 1.0.45 → 1.0.47

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,13 +1,13 @@
1
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);
2
+ const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, c = i?.flags ?? 0, d = i?.targetIds ?? [], o = i?.payloadType ?? 8, h = 27 + d.length * 4, y = h + e.length, u = new Uint8Array(y), f = new DataView(u.buffer);
3
+ f.setUint32(0, y, !0), f.setUint32(4, t >>> 0, !0), f.setUint32(8, n >>> 0, !0), f.setUint32(12, s >>> 0, !0), f.setUint32(16, a >>> 0, !0), f.setUint32(20, d.length >>> 0, !0), f.setUint8(24, r & 255), f.setUint8(25, o & 255), f.setUint8(26, c & 255);
4
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;
5
+ for (let V = 0; V < d.length; V++)
6
+ f.setUint32(N, d[V] >>> 0, !0), N += 4;
7
+ return u.set(e, h), u;
8
8
  }
9
9
  var m = /* @__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))(m || {});
10
- const q = 161, G = 162, B = new TextEncoder();
10
+ const q = 161, G = 162, _ = new TextEncoder();
11
11
  new TextDecoder("utf-8", { fatal: !0 });
12
12
  class S {
13
13
  constructor(e = 1) {
@@ -38,13 +38,13 @@ class S {
38
38
  this.writeFixedField(e, 2, () => this.buffer.writeByte(r ? 1 : 0));
39
39
  }
40
40
  writeGuidField(e, r) {
41
- const n = r instanceof u ? r.asBytes() : r;
41
+ const n = r instanceof l ? 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 = _.encode(r ?? "");
48
48
  this.writeVariableField(e, 12, n);
49
49
  }
50
50
  writeBinaryField(e, r) {
@@ -78,7 +78,7 @@ class S {
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)), J(r) && this.buffer.writeVarUInt(n >>> 0);
81
+ this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(B(r)), J(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
84
  class R {
@@ -134,7 +134,7 @@ class R {
134
134
  14
135
135
  /* Guid */
136
136
  ), this.count++;
137
- const r = e instanceof u ? e.asBytes() : e;
137
+ const r = e instanceof l ? 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 R {
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) {
@@ -185,7 +185,7 @@ class R {
185
185
  }
186
186
  finish() {
187
187
  const e = new E();
188
- return e.writeByte(_(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
188
+ return e.writeByte(B(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)
@@ -210,7 +210,7 @@ class W {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
212
  const e = new E();
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(B(this.keyType)), e.writeByte(B(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
214
214
  }
215
215
  }
216
216
  class Y {
@@ -267,7 +267,7 @@ class Y {
267
267
  14
268
268
  /* Guid */
269
269
  );
270
- const r = e instanceof u ? e.asBytes() : e;
270
+ const r = e instanceof l ? 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 Y {
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) {
@@ -333,7 +333,7 @@ class Y {
333
333
  14
334
334
  /* Guid */
335
335
  );
336
- const r = e instanceof u ? e.asBytes() : e;
336
+ const r = e instanceof l ? 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 Y {
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) {
@@ -404,7 +404,7 @@ class Y {
404
404
  throw new Error(`Dictionary value type is ${m[this.valueType]}, expected ${m[e]}`);
405
405
  }
406
406
  }
407
- class u {
407
+ class l {
408
408
  constructor(e) {
409
409
  this.bytes = e;
410
410
  }
@@ -414,19 +414,19 @@ class u {
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 = 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);
417
+ const n = new Uint8Array(16), i = l.parseHexSlice(r, 0, 8), s = l.parseHexSlice(r, 8, 4), a = l.parseHexSlice(r, 12, 4);
418
+ l.writeUInt32LE(n, 0, i), l.writeUInt16LE(n, 4, s), l.writeUInt16LE(n, 6, a);
419
419
  for (let c = 0; c < 8; c++)
420
- n[8 + c] = u.parseHexSlice(r, 16 + c * 2, 2);
421
- return new u(n);
420
+ n[8 + c] = l.parseHexSlice(r, 16 + c * 2, 2);
421
+ return new l(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 u(Uint8Array.from(e));
426
+ return new l(Uint8Array.from(e));
427
427
  }
428
428
  static createZero() {
429
- return new u(new Uint8Array(16));
429
+ return new l(new Uint8Array(16));
430
430
  }
431
431
  static createRandom() {
432
432
  const e = new Uint8Array(16), r = globalThis.crypto;
@@ -435,14 +435,14 @@ class u {
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 u(e);
438
+ return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new l(e);
439
439
  }
440
440
  toString() {
441
441
  const e = this.bytes;
442
442
  return [
443
- u.toHex(u.readUInt32LE(e, 0), 8),
444
- u.toHex(u.readUInt16LE(e, 4), 4),
445
- u.toHex(u.readUInt16LE(e, 6), 4),
443
+ l.toHex(l.readUInt32LE(e, 0), 8),
444
+ l.toHex(l.readUInt16LE(e, 4), 4),
445
+ l.toHex(l.readUInt16LE(e, 6), 4),
446
446
  k(e.subarray(8, 10)),
447
447
  k(e.subarray(10, 16))
448
448
  ].join("-");
@@ -526,7 +526,7 @@ class E {
526
526
  return this.buffer.slice(0, this.length);
527
527
  }
528
528
  }
529
- function _(t, e = 0) {
529
+ function B(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;
@@ -561,52 +561,54 @@ function he(t, e, r) {
561
561
  const n = le(t);
562
562
  return L(Z, n, z, e, r);
563
563
  }
564
- const H = 5, fe = 4194305, pe = 161083277, ye = 265814330, we = 1368629611, Ie = 2431514951, me = 2745379226, ge = 3282782683, Ee = 3284746250, Se = 4101844078;
565
- function Ae(t) {
566
- const e = {};
567
- return be(e), t && Object.assign(e, t), e;
568
- }
564
+ const H = 6, fe = 4194305, pe = 161083277, ye = 265814330, we = 1368629611, Ie = 2431514951, me = 2514959030, ge = 2745379226, Ee = 3282782683, Se = 3284746250, Ae = 4101844078;
569
565
  function be(t) {
570
- return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = P.Unknown, t.CodecDetails = "", t.SampleRate = 0, t.Channels = 0, t.ShapeSets = void 0, t;
566
+ const e = {};
567
+ return Fe(e), t && Object.assign(e, t), e;
571
568
  }
572
569
  function Fe(t) {
570
+ return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = P.Unknown, t.CodecDetails = "", t.SampleRate = 0, t.Channels = 0, t.ShapeSets = void 0, t.CorrelationId = void 0, t;
571
+ }
572
+ function Ue(t) {
573
573
  const e = new S(H);
574
- return Ue(t, e), e.finish();
574
+ return _e(t, e), e.finish();
575
575
  }
576
- function Ue(t, e) {
576
+ function _e(t, e) {
577
577
  e.writeStringField(pe, t.StreamId);
578
578
  const r = t.ShapeSets;
579
- r != null && e.writeArrayField(ye, m.Object, (n) => {
580
- for (const i of r)
581
- n.writeObject(_e, (s) => {
582
- Me(i, s);
579
+ r != null && e.writeArrayField(ye, m.Object, (i) => {
580
+ for (const s of r)
581
+ i.writeObject(Oe, (a) => {
582
+ Te(s, a);
583
583
  });
584
- }), e.writeStringField(we, t.Description), e.writeInt32Field(Ie, t.Channels | 0), e.writeStringField(me, t.CodecDetails), e.writeStringField(ge, t.SourceType), e.writeInt32Field(Ee, t.Codec), e.writeInt32Field(Se, t.SampleRate | 0);
584
+ }), e.writeStringField(we, t.Description), e.writeInt32Field(Ie, t.Channels | 0);
585
+ const n = t.CorrelationId;
586
+ n != null && e.writeStringField(me, n), e.writeStringField(ge, t.CodecDetails), e.writeStringField(Ee, t.SourceType), e.writeInt32Field(Se, t.Codec), e.writeInt32Field(Ae, t.SampleRate | 0);
585
587
  }
586
588
  function Be(t, e, r) {
587
- const n = Fe(t);
589
+ const n = Ue(t);
588
590
  return L(fe, n, H, e, r);
589
591
  }
590
- const _e = 5, Oe = 1107713536, De = 1154362099, Re = 1185721362;
591
- function Me(t, e) {
592
- e.writeStringField(Oe, t.Name), e.writeUInt32Field(De, t.SetId >>> 0), e.writeArrayField(Re, m.String, (r) => {
592
+ const Oe = 6, De = 1107713536, Re = 1154362099, Me = 1185721362;
593
+ function Te(t, e) {
594
+ e.writeStringField(De, t.Name), e.writeUInt32Field(Re, t.SetId >>> 0), e.writeArrayField(Me, m.String, (r) => {
593
595
  for (const n of t.ShapeNames)
594
596
  r.writeString(n);
595
597
  });
596
598
  }
597
- const K = 1, Te = 4194306;
598
- function Ve(t) {
599
+ const K = 1, Ve = 4194306;
600
+ function Le(t) {
599
601
  const e = {};
600
602
  return t && Object.assign(e, t), e;
601
603
  }
602
- function Le(t) {
604
+ function We(t) {
603
605
  return new S(K).finish();
604
606
  }
605
- function We(t, e, r) {
606
- const n = Le();
607
- return L(Te, n, K, e, r);
607
+ function Pe(t, e, r) {
608
+ const n = We();
609
+ return L(Ve, n, K, e, r);
608
610
  }
609
- class Pe {
611
+ class Ce {
610
612
  static getStorageForCapacity(e, r) {
611
613
  const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * e;
612
614
  return new SharedArrayBuffer(n + i);
@@ -660,19 +662,19 @@ class Pe {
660
662
  return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
661
663
  }
662
664
  }
663
- let Ce = 1;
664
- const ve = /* @__PURE__ */ new Map(), Ne = {
665
+ let ve = 1;
666
+ const Ne = /* @__PURE__ */ new Map(), ke = {
665
667
  0: "DEBUG",
666
668
  1: "INFO",
667
669
  2: "WARN",
668
670
  3: "ERROR",
669
671
  4: "NONE"
670
672
  };
671
- function ke(t, e) {
673
+ function xe(t, e) {
672
674
  return `[${t}] ${e}`;
673
675
  }
674
676
  function F(t, e, r, n) {
675
- const i = (/* @__PURE__ */ new Date()).toISOString(), s = Ne[t], a = {
677
+ const i = (/* @__PURE__ */ new Date()).toISOString(), s = ke[t], a = {
676
678
  timestamp: i,
677
679
  level: t,
678
680
  levelName: s,
@@ -680,16 +682,16 @@ function F(t, e, r, n) {
680
682
  message: r,
681
683
  args: n
682
684
  };
683
- for (const [c, l] of ve) {
684
- const o = l?.minLevel ?? 2;
685
+ for (const [c, d] of Ne) {
686
+ const o = d?.minLevel ?? 2;
685
687
  if (t >= o)
686
688
  try {
687
689
  c(a);
688
690
  } catch {
689
691
  }
690
692
  }
691
- if (Ce <= t) {
692
- const c = ke(e, r);
693
+ if (ve <= t) {
694
+ const c = xe(e, r);
693
695
  switch (t) {
694
696
  case 0:
695
697
  console.debug(c, ...n);
@@ -706,7 +708,7 @@ function F(t, e, r, n) {
706
708
  }
707
709
  }
708
710
  }
709
- function xe(t) {
711
+ function ze(t) {
710
712
  return {
711
713
  debug(e, ...r) {
712
714
  F(0, t, e, r);
@@ -722,7 +724,7 @@ function xe(t) {
722
724
  }
723
725
  };
724
726
  }
725
- const ze = 20, b = 32e3, He = 5, M = 8e3, g = xe("AudioCaptureWorker");
727
+ const He = 20, b = 32e3, Ke = 5, M = 8e3, g = ze("AudioCaptureWorker");
726
728
  class $ {
727
729
  encoder = null;
728
730
  isReady = !1;
@@ -745,7 +747,7 @@ class $ {
745
747
  channels: this.channels,
746
748
  bitrate: this.bitrate,
747
749
  application: r,
748
- complexity: He
750
+ complexity: Ke
749
751
  }), await this.encoder.ready, this.isReady = !0;
750
752
  } catch (e) {
751
753
  this.onError(e instanceof Error ? e : new Error(String(e)));
@@ -786,7 +788,7 @@ function w(t, e) {
786
788
  const r = t instanceof Error ? t : new Error(String(t));
787
789
  O({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
788
790
  }
789
- function Ke(t) {
791
+ function $e(t) {
790
792
  return t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.slice().buffer;
791
793
  }
792
794
  function C(t) {
@@ -794,10 +796,10 @@ function C(t) {
794
796
  g.warn("Audio capture message dropped: sendPort not available");
795
797
  return;
796
798
  }
797
- const e = Ke(t);
799
+ const e = $e(t);
798
800
  I.postMessage({ type: "send", message: e }, [e]);
799
801
  }
800
- function $e(t) {
802
+ function je(t) {
801
803
  if (t.length === 0)
802
804
  return 0;
803
805
  let e = 0;
@@ -805,13 +807,13 @@ function $e(t) {
805
807
  e += Math.abs(t[r] ?? 0);
806
808
  return e / t.length;
807
809
  }
808
- const f = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map();
810
+ const p = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map();
809
811
  let A = null;
810
812
  const x = 1;
811
- function je() {
813
+ function qe() {
812
814
  return typeof Atomics < "u" && typeof Atomics.waitAsync == "function";
813
815
  }
814
- async function qe(t) {
816
+ async function Ge(t) {
815
817
  if (!t.ringBuffer || !t.ringTemp)
816
818
  return;
817
819
  const e = t.ringBuffer, r = t.ringTemp;
@@ -830,8 +832,8 @@ async function qe(t) {
830
832
  }
831
833
  }
832
834
  }
833
- function Ge() {
834
- for (const t of f.values())
835
+ function Ye() {
836
+ for (const t of p.values())
835
837
  if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
836
838
  try {
837
839
  const e = t.ringBuffer.pop(t.ringTemp);
@@ -840,21 +842,21 @@ function Ge() {
840
842
  w(e, t.captureId);
841
843
  }
842
844
  }
843
- function Ye(t) {
844
- if (je()) {
845
+ function Je(t) {
846
+ if (qe()) {
845
847
  if (!U.has(t.captureId)) {
846
- const e = qe(t);
848
+ const e = Ge(t);
847
849
  U.set(t.captureId, e), e.finally(() => {
848
850
  U.delete(t.captureId);
849
851
  });
850
852
  }
851
853
  } else
852
- A === null && (A = self.setInterval(Ge, 50));
854
+ A === null && (A = self.setInterval(Ye, 50));
853
855
  }
854
- function Je(t) {
856
+ function Xe(t) {
855
857
  if (U.delete(t), A !== null) {
856
858
  let e = !1;
857
- for (const r of f.values())
859
+ for (const r of p.values())
858
860
  if (r.transport === "sab" && !r.stopped) {
859
861
  e = !0;
860
862
  break;
@@ -885,7 +887,7 @@ function v(t) {
885
887
  r.set(t.pendingBuffer.subarray(i, n)), r.set(t.pendingBuffer.subarray(0, e - a), a);
886
888
  }
887
889
  t.pendingReadOffset = (i + e) % n, t.pendingSamples -= e;
888
- const s = $e(r);
890
+ const s = je(r);
889
891
  t.lastVolume = s;
890
892
  try {
891
893
  if (t.useWasmEncoder)
@@ -917,12 +919,12 @@ function T(t, e) {
917
919
  if (n > t.pendingBuffer.length) {
918
920
  const a = Math.max(n, t.pendingBuffer.length * 2), c = new Float32Array(a);
919
921
  if (t.pendingSamples > 0) {
920
- const l = t.pendingBuffer.length;
921
- if (t.pendingReadOffset + t.pendingSamples <= l)
922
+ const d = t.pendingBuffer.length;
923
+ if (t.pendingReadOffset + t.pendingSamples <= d)
922
924
  c.set(t.pendingBuffer.subarray(t.pendingReadOffset, t.pendingReadOffset + t.pendingSamples));
923
925
  else {
924
- const o = l - t.pendingReadOffset;
925
- c.set(t.pendingBuffer.subarray(t.pendingReadOffset, l)), c.set(t.pendingBuffer.subarray(0, t.pendingSamples - o), o);
926
+ const o = d - t.pendingReadOffset;
927
+ c.set(t.pendingBuffer.subarray(t.pendingReadOffset, d)), c.set(t.pendingBuffer.subarray(0, t.pendingSamples - o), o);
926
928
  }
927
929
  }
928
930
  t.pendingBuffer = c, t.pendingReadOffset = 0, t.pendingWriteOffset = t.pendingSamples;
@@ -931,25 +933,25 @@ function T(t, e) {
931
933
  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);
932
934
  }
933
935
  function D(t, e, r, n, i = !0) {
934
- const s = f.get(t.captureId);
936
+ const s = p.get(t.captureId);
935
937
  if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
936
938
  return;
937
939
  const a = e.byteLength;
938
940
  s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(e);
939
- const c = s.encoderOutputBuffer.subarray(0, a), l = s.segmentStartPending;
940
- l && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
941
+ const c = s.encoderOutputBuffer.subarray(0, a), d = s.segmentStartPending;
942
+ d && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
941
943
  const o = s.segmentEndPending;
942
944
  o && (s.segmentEndPending = !1, s.inSegment = !1);
943
- const d = s.frameSize * s.channels, y = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
945
+ const h = s.frameSize * s.channels, y = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
944
946
  C(
945
947
  he(
946
948
  ce({
947
949
  Samples: c,
948
950
  Epoch: s.epoch,
949
951
  Sequence: s.sequence,
950
- FrameSizeInInterleavedSamples: d,
952
+ FrameSizeInInterleavedSamples: h,
951
953
  TimeStampInInterleavedSamples: y,
952
- IsFirst: l,
954
+ IsFirst: d,
953
955
  IsLast: o,
954
956
  AverageVolume: s.lastVolume,
955
957
  AudioEventEstimatedDuration: 0
@@ -959,10 +961,10 @@ function D(t, e, r, n, i = !0) {
959
961
  )
960
962
  ), s.sequence++;
961
963
  }
962
- function Xe(t) {
964
+ function Ze(t) {
963
965
  const e = Math.max(M, Math.floor(t.options?.bitrate ?? b)), r = new AudioEncoder({
964
966
  output: (n) => {
965
- const i = f.get(t.captureId);
967
+ const i = p.get(t.captureId);
966
968
  if (!i)
967
969
  return;
968
970
  const s = n.byteLength;
@@ -991,7 +993,7 @@ function Xe(t) {
991
993
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
992
994
  }), r;
993
995
  }
994
- function Ze(t) {
996
+ function Qe(t) {
995
997
  const e = Math.max(M, Math.floor(t.options?.bitrate ?? b));
996
998
  return new $({
997
999
  sampleRate: t.sampleRate,
@@ -999,7 +1001,7 @@ function Ze(t) {
999
1001
  bitrate: e,
1000
1002
  frameSize: t.frameSize,
1001
1003
  onOutput: (r, n, i) => {
1002
- const s = f.get(t.captureId);
1004
+ const s = p.get(t.captureId);
1003
1005
  s && D(s, r, n, i, !0);
1004
1006
  },
1005
1007
  onError: (r) => {
@@ -1007,7 +1009,7 @@ function Ze(t) {
1007
1009
  }
1008
1010
  });
1009
1011
  }
1010
- async function Qe() {
1012
+ async function et() {
1011
1013
  if (typeof AudioEncoder > "u")
1012
1014
  return !1;
1013
1015
  try {
@@ -1020,15 +1022,15 @@ async function Qe() {
1020
1022
  return !1;
1021
1023
  }
1022
1024
  }
1023
- async function et(t) {
1025
+ async function tt(t) {
1024
1026
  if (!I)
1025
1027
  throw new Error("Audio capture worker missing send port");
1026
- if (f.has(t.captureId)) {
1027
- const h = f.get(t.captureId);
1028
- O({ type: "started", captureId: t.captureId, sampleRate: h.sampleRate, channels: h.channels });
1028
+ if (p.has(t.captureId)) {
1029
+ const f = p.get(t.captureId);
1030
+ O({ type: "started", captureId: t.captureId, sampleRate: f.sampleRate, channels: f.channels });
1029
1031
  return;
1030
1032
  }
1031
- const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * ze / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
1033
+ const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * He / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
1032
1034
  captureId: t.captureId,
1033
1035
  streamId: t.streamId,
1034
1036
  sourceType: t.sourceType,
@@ -1057,52 +1059,54 @@ async function et(t) {
1057
1059
  sequence: 0,
1058
1060
  lastVolume: 0,
1059
1061
  targetIds: t.options?.targetIds,
1060
- options: t.options
1061
- }, l = (t.options?.preferWebCodecs ?? !0) && await Qe();
1062
- let o, d = !1;
1062
+ options: t.options,
1063
+ correlationId: t.correlationId
1064
+ }, d = (t.options?.preferWebCodecs ?? !0) && await et();
1065
+ let o, h = !1;
1063
1066
  const y = Math.max(M, Math.floor(t.options?.bitrate ?? b));
1064
- if (l)
1065
- o = Xe(a), g.debug(
1067
+ if (d)
1068
+ o = Ze(a), g.debug(
1066
1069
  `Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
1067
1070
  );
1068
1071
  else {
1069
- const h = Ze(a);
1070
- await h.initialize(), o = h, d = !0, g.debug(
1072
+ const f = Qe(a);
1073
+ await f.initialize(), o = f, h = !0, g.debug(
1071
1074
  `Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
1072
1075
  );
1073
1076
  }
1074
- const p = {
1077
+ const u = {
1075
1078
  ...a,
1076
1079
  encoder: o,
1077
- useWasmEncoder: d,
1080
+ useWasmEncoder: h,
1078
1081
  isReconfiguring: !1
1079
1082
  };
1080
1083
  if (t.transport === "sab") {
1081
1084
  if (!t.sharedArrayBuffer)
1082
1085
  throw new Error("Missing SharedArrayBuffer for sab transport");
1083
- const h = new Pe(t.sharedArrayBuffer, Float32Array);
1084
- p.ringBuffer = h, p.ringTemp = new Float32Array(Math.max(p.frameSize * 4, 4096)), Ye(p);
1086
+ const f = new Ce(t.sharedArrayBuffer, Float32Array);
1087
+ u.ringBuffer = f, u.ringTemp = new Float32Array(Math.max(u.frameSize * 4, 4096)), Je(u);
1085
1088
  }
1086
- f.set(t.captureId, p), C(
1089
+ p.set(t.captureId, u), C(
1087
1090
  Be(
1088
- Ae({
1089
- StreamId: t.streamId,
1090
- Description: `mic:${t.streamId}`,
1091
- SourceType: t.sourceType,
1091
+ be({
1092
+ StreamId: u.streamId,
1093
+ Description: `mic:${u.streamId}`,
1094
+ SourceType: u.sourceType,
1092
1095
  Codec: P.Opus,
1093
1096
  CodecDetails: "",
1094
- SampleRate: e,
1095
- Channels: r
1097
+ SampleRate: u.sampleRate,
1098
+ Channels: u.channels,
1099
+ CorrelationId: u.correlationId
1096
1100
  }),
1097
- t.senderId,
1098
- { trackId: t.trackId, targetIds: p.targetIds }
1101
+ u.senderId,
1102
+ { trackId: u.trackId, targetIds: u.targetIds }
1099
1103
  )
1100
1104
  ), O({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1101
1105
  }
1102
1106
  async function j(t) {
1103
- const e = f.get(t);
1107
+ const e = p.get(t);
1104
1108
  if (e) {
1105
- e.stopped = !0, f.delete(t);
1109
+ e.stopped = !0, p.delete(t);
1106
1110
  try {
1107
1111
  v(e);
1108
1112
  } catch {
@@ -1115,15 +1119,15 @@ async function j(t) {
1115
1119
  e.encoder.close();
1116
1120
  } catch {
1117
1121
  }
1118
- C(We(Ve({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), O({ type: "stopped", captureId: e.captureId }), Je(t);
1122
+ C(Pe(Le({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), O({ type: "stopped", captureId: e.captureId }), Xe(t);
1119
1123
  }
1120
1124
  }
1121
- function tt(t) {
1122
- const e = f.get(t);
1125
+ function rt(t) {
1126
+ const e = p.get(t);
1123
1127
  !e || e.stopped || (e.inSegment = !0, e.segmentStartPending = !0);
1124
1128
  }
1125
- function rt(t) {
1126
- const e = f.get(t);
1129
+ function nt(t) {
1130
+ const e = p.get(t);
1127
1131
  if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, v(e), e.segmentEndPending && !e.stopped)) {
1128
1132
  const r = e.frameSize - e.pendingSamples;
1129
1133
  if (r > 0) {
@@ -1132,8 +1136,8 @@ function rt(t) {
1132
1136
  }
1133
1137
  }
1134
1138
  }
1135
- async function nt(t, e) {
1136
- const r = f.get(t);
1139
+ async function it(t, e) {
1140
+ const r = p.get(t);
1137
1141
  if (!r || r.stopped)
1138
1142
  return;
1139
1143
  const n = r.options?.bitrate ?? b, i = e.bitrate ?? b;
@@ -1145,38 +1149,38 @@ async function nt(t, e) {
1145
1149
  const s = Math.max(M, Math.floor(i));
1146
1150
  let a;
1147
1151
  if (r.useWasmEncoder) {
1148
- const l = new $({
1152
+ const d = new $({
1149
1153
  sampleRate: r.sampleRate,
1150
1154
  channels: r.channels,
1151
1155
  bitrate: s,
1152
1156
  frameSize: r.frameSize,
1153
- onOutput: (o, d, y) => {
1154
- const p = f.get(r.captureId);
1155
- !p || p.isReconfiguring || D(p, o, d, y, !0);
1157
+ onOutput: (o, h, y) => {
1158
+ const u = p.get(r.captureId);
1159
+ !u || u.isReconfiguring || D(u, o, h, y, !0);
1156
1160
  },
1157
1161
  onError: (o) => {
1158
1162
  w(o, r.captureId);
1159
1163
  }
1160
1164
  });
1161
1165
  try {
1162
- await l.initialize();
1166
+ await d.initialize();
1163
1167
  } catch (o) {
1164
1168
  r.isReconfiguring = !1, w(o, t);
1165
1169
  return;
1166
1170
  }
1167
- a = l;
1171
+ a = d;
1168
1172
  } else {
1169
- const l = new AudioEncoder({
1173
+ const d = new AudioEncoder({
1170
1174
  output: (o) => {
1171
- const d = f.get(r.captureId);
1172
- if (!d || d.isReconfiguring)
1175
+ const h = p.get(r.captureId);
1176
+ if (!h || h.isReconfiguring)
1173
1177
  return;
1174
1178
  const y = o.byteLength;
1175
- d.encoderOutputBuffer.length < y && (d.encoderOutputBuffer = new Uint8Array(Math.max(y, d.encoderOutputBuffer.length * 2))), o.copyTo(d.encoderOutputBuffer), D(
1176
- d,
1177
- d.encoderOutputBuffer.subarray(0, y),
1178
- o.timestamp ?? d.timestampUs,
1179
- o.duration ?? d.frameDurationUs,
1179
+ h.encoderOutputBuffer.length < y && (h.encoderOutputBuffer = new Uint8Array(Math.max(y, h.encoderOutputBuffer.length * 2))), o.copyTo(h.encoderOutputBuffer), D(
1180
+ h,
1181
+ h.encoderOutputBuffer.subarray(0, y),
1182
+ o.timestamp ?? h.timestampUs,
1183
+ o.duration ?? h.frameDurationUs,
1180
1184
  o.type === "key"
1181
1185
  );
1182
1186
  },
@@ -1184,7 +1188,7 @@ async function nt(t, e) {
1184
1188
  w(o, r.captureId);
1185
1189
  }
1186
1190
  });
1187
- l.configure({
1191
+ d.configure({
1188
1192
  codec: "opus",
1189
1193
  numberOfChannels: r.channels,
1190
1194
  sampleRate: r.sampleRate,
@@ -1195,7 +1199,7 @@ async function nt(t, e) {
1195
1199
  signal: "voice"
1196
1200
  }
1197
1201
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1198
- }), a = l;
1202
+ }), a = d;
1199
1203
  }
1200
1204
  const c = r.encoder;
1201
1205
  try {
@@ -1208,8 +1212,8 @@ async function nt(t, e) {
1208
1212
  }
1209
1213
  r.encoder = a, r.isReconfiguring = !1, g.debug(`Audio capture bitrate updated: ${s}bps`);
1210
1214
  }
1211
- async function it() {
1212
- const t = Array.from(f.keys()).map(
1215
+ async function st() {
1216
+ const t = Array.from(p.keys()).map(
1213
1217
  (e) => j(e).catch(() => {
1214
1218
  })
1215
1219
  );
@@ -1237,13 +1241,13 @@ self.addEventListener("message", (t) => {
1237
1241
  return;
1238
1242
  }
1239
1243
  if (e.type === "start") {
1240
- et(e).catch((r) => {
1244
+ tt(e).catch((r) => {
1241
1245
  w(r, e.captureId);
1242
1246
  });
1243
1247
  return;
1244
1248
  }
1245
1249
  if (e.type === "pcm") {
1246
- const r = f.get(e.captureId);
1250
+ const r = p.get(e.captureId);
1247
1251
  if (!r || r.stopped)
1248
1252
  return;
1249
1253
  T(r, e.pcm);
@@ -1256,20 +1260,20 @@ self.addEventListener("message", (t) => {
1256
1260
  return;
1257
1261
  }
1258
1262
  if (e.type === "startSegment") {
1259
- tt(e.captureId);
1263
+ rt(e.captureId);
1260
1264
  return;
1261
1265
  }
1262
1266
  if (e.type === "endSegment") {
1263
- rt(e.captureId);
1267
+ nt(e.captureId);
1264
1268
  return;
1265
1269
  }
1266
1270
  if (e.type === "updateOptions") {
1267
- nt(e.captureId, e.options).catch((r) => {
1271
+ it(e.captureId, e.options).catch((r) => {
1268
1272
  g.warn(`Failed to update audio capture options: ${r}`), w(r, e.captureId);
1269
1273
  });
1270
1274
  return;
1271
1275
  }
1272
- e.type === "dispose" && it().catch((r) => {
1276
+ e.type === "dispose" && st().catch((r) => {
1273
1277
  g.warn(`Failed to dispose audio capture worker: ${r}`);
1274
1278
  });
1275
1279
  });