@ikonai/sdk 1.0.10 → 1.0.12

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,9 +1,9 @@
1
- function B(t, e, r, n, i) {
2
- const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, u = i?.flags ?? 0, c = i?.targetIds ?? [], h = 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, h & 255), l.setUint8(26, u & 255);
4
- let v = 27;
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
5
  for (let D = 0; D < c.length; D++)
6
- l.setUint32(v, c[D] >>> 0, !0), v += 4;
6
+ l.setUint32(C, c[D] >>> 0, !0), C += 4;
7
7
  return y.set(e, w), y;
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 || {});
@@ -63,7 +63,7 @@ class E {
63
63
  this.writeVariableField(e, 9, s);
64
64
  }
65
65
  writeDictionaryField(e, r, n, i) {
66
- const s = new O(r, n);
66
+ const s = new B(r, n);
67
67
  i(s);
68
68
  const a = s.finish();
69
69
  this.writeVariableField(e, 10, a);
@@ -78,7 +78,7 @@ 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(F(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
81
+ this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(_(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
84
  class U {
@@ -178,21 +178,21 @@ class U {
178
178
  10
179
179
  /* Dict */
180
180
  ), this.count++;
181
- const i = new O(e, r);
181
+ const i = new B(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(F(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
188
+ return e.writeByte(_(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 O {
195
+ class B {
196
196
  constructor(e, r) {
197
197
  this.keyType = e, this.valueType = r, G(e);
198
198
  }
@@ -210,7 +210,7 @@ class O {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
212
  const e = new m();
213
- return e.writeByte(F(this.keyType)), e.writeByte(F(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
213
+ return e.writeByte(_(this.keyType)), e.writeByte(_(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
214
214
  }
215
215
  }
216
216
  class j {
@@ -383,7 +383,7 @@ class j {
383
383
  10
384
384
  /* Dict */
385
385
  );
386
- const i = new O(e, r);
386
+ const i = new B(e, r);
387
387
  n(i);
388
388
  const s = i.finish();
389
389
  this.payload.writeBytes(s), this.valueWritten = !0;
@@ -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
- C(e.subarray(8, 10)),
447
- C(e.subarray(10, 16))
446
+ v(e.subarray(8, 10)),
447
+ v(e.subarray(10, 16))
448
448
  ].join("-");
449
449
  }
450
450
  asBytes() {
@@ -526,7 +526,7 @@ class m {
526
526
  return this.buffer.slice(0, this.length);
527
527
  }
528
528
  }
529
- function F(t, e = 0) {
529
+ function _(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;
@@ -538,7 +538,7 @@ function G(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 C(t) {
541
+ function v(t) {
542
542
  return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
543
543
  }
544
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 || {});
@@ -559,67 +559,68 @@ function ce(t, e) {
559
559
  const r = t.ShapeSetValues;
560
560
  r != null && e.writeArrayField(Z, f.Object, (n) => {
561
561
  for (const i of r)
562
- n.writeObject(he, (s) => {
562
+ n.writeObject(de, (s) => {
563
563
  pe(i, s);
564
564
  });
565
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);
566
566
  }
567
567
  function le(t, e, r) {
568
568
  const n = ue(t);
569
- return B(Y, n, N, e, r);
569
+ return O(Y, n, N, e, r);
570
570
  }
571
- const he = 1, de = 1154362099, fe = 3974819915;
571
+ const de = 1, he = 1154362099, fe = 3974819915;
572
572
  function pe(t, e) {
573
- e.writeUInt32Field(de, t.SetId >>> 0), e.writeArrayField(fe, f.Float32, (r) => {
573
+ e.writeUInt32Field(he, t.SetId >>> 0), e.writeArrayField(fe, f.Float32, (r) => {
574
574
  for (const n of t.Values)
575
575
  r.writeFloat32(n);
576
576
  });
577
577
  }
578
- const k = 1, ye = 4194305, we = 265814330, Ie = 1368629611, me = 2431514951, Ee = 2914494629, ge = 3284746250, Se = 4101844078;
579
- function Ae(t) {
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) {
580
580
  const e = {};
581
- return be(e), t && Object.assign(e, t), e;
582
- }
583
- function be(t) {
584
- return t.Description = "", t.Codec = R.Unknown, t.SampleRate = 0, t.Channels = 0, t.BitDepth = 0, t.ShapeSets = void 0, t;
581
+ return Fe(e), t && Object.assign(e, t), e;
585
582
  }
586
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;
585
+ }
586
+ function Ue(t) {
587
587
  const e = new E(k);
588
- return _e(t, e), e.finish();
588
+ return De(t, e), e.finish();
589
589
  }
590
- function _e(t, e) {
590
+ function De(t, e) {
591
+ e.writeStringField(we, t.StreamId);
591
592
  const r = t.ShapeSets;
592
- r != null && e.writeArrayField(we, f.Object, (n) => {
593
+ r != null && e.writeArrayField(Ie, f.Object, (n) => {
593
594
  for (const i of r)
594
- n.writeObject(De, (s) => {
595
- Me(i, s);
595
+ n.writeObject(Be, (s) => {
596
+ Ve(i, s);
596
597
  });
597
- }), e.writeStringField(Ie, t.Description), e.writeInt32Field(me, t.Channels | 0), e.writeInt32Field(Ee, t.BitDepth | 0), e.writeInt32Field(ge, t.Codec), e.writeInt32Field(Se, t.SampleRate | 0);
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
599
  }
599
- function Ue(t, e, r) {
600
- const n = Fe(t);
601
- return B(ye, n, k, e, r);
600
+ function Oe(t, e, r) {
601
+ const n = Ue(t);
602
+ return O(ye, n, k, e, r);
602
603
  }
603
- const De = 1, Be = 1107713536, Oe = 1154362099, Re = 1185721362;
604
- function Me(t, e) {
605
- e.writeStringField(Be, t.Name), e.writeUInt32Field(Oe, t.SetId >>> 0), e.writeArrayField(Re, f.String, (r) => {
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) => {
606
607
  for (const n of t.ShapeNames)
607
608
  r.writeString(n);
608
609
  });
609
610
  }
610
- const x = 1, Ve = 4194306;
611
- function Te(t) {
611
+ const x = 1, Le = 4194306;
612
+ function Pe(t) {
612
613
  const e = {};
613
614
  return t && Object.assign(e, t), e;
614
615
  }
615
- function Le(t) {
616
+ function We(t) {
616
617
  return new E(x).finish();
617
618
  }
618
- function Pe(t, e, r) {
619
- const n = Le();
620
- return B(Ve, n, x, e, r);
619
+ function Ce(t, e, r) {
620
+ const n = We();
621
+ return O(Le, n, x, e, r);
621
622
  }
622
- class We {
623
+ class ve {
623
624
  static getStorageForCapacity(e, r) {
624
625
  const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * e;
625
626
  return new SharedArrayBuffer(n + i);
@@ -673,19 +674,19 @@ class We {
673
674
  return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
674
675
  }
675
676
  }
676
- let ve = 1;
677
- const Ce = /* @__PURE__ */ new Map(), Ne = {
677
+ let Ne = 1;
678
+ const ke = /* @__PURE__ */ new Map(), xe = {
678
679
  0: "DEBUG",
679
680
  1: "INFO",
680
681
  2: "WARN",
681
682
  3: "ERROR",
682
683
  4: "NONE"
683
684
  };
684
- function ke(t, e) {
685
+ function He(t, e) {
685
686
  return `[${t}] ${e}`;
686
687
  }
687
688
  function A(t, e, r, n) {
688
- const i = (/* @__PURE__ */ new Date()).toISOString(), s = Ne[t], a = {
689
+ const i = (/* @__PURE__ */ new Date()).toISOString(), s = xe[t], a = {
689
690
  timestamp: i,
690
691
  level: t,
691
692
  levelName: s,
@@ -693,16 +694,16 @@ function A(t, e, r, n) {
693
694
  message: r,
694
695
  args: n
695
696
  };
696
- for (const [u, c] of Ce) {
697
- const h = c?.minLevel ?? 2;
698
- if (t >= h)
697
+ for (const [u, c] of ke) {
698
+ const d = c?.minLevel ?? 2;
699
+ if (t >= d)
699
700
  try {
700
701
  u(a);
701
702
  } catch {
702
703
  }
703
704
  }
704
- if (ve <= t) {
705
- const u = ke(e, r);
705
+ if (Ne <= t) {
706
+ const u = He(e, r);
706
707
  switch (t) {
707
708
  case 0:
708
709
  console.debug(u, ...n);
@@ -719,7 +720,7 @@ function A(t, e, r, n) {
719
720
  }
720
721
  }
721
722
  }
722
- function xe(t) {
723
+ function ze(t) {
723
724
  return {
724
725
  debug(e, ...r) {
725
726
  A(0, t, e, r);
@@ -735,8 +736,8 @@ function xe(t) {
735
736
  }
736
737
  };
737
738
  }
738
- const He = 20, M = 32e3, ze = 5, V = 8e3, _ = xe("AudioCaptureWorker");
739
- class Ke {
739
+ const Ke = 20, M = 32e3, $e = 5, T = 8e3, F = ze("AudioCaptureWorker");
740
+ class je {
740
741
  encoder = null;
741
742
  isReady = !1;
742
743
  sampleRate;
@@ -758,7 +759,7 @@ class Ke {
758
759
  channels: this.channels,
759
760
  bitrate: this.bitrate,
760
761
  application: r,
761
- complexity: ze
762
+ complexity: $e
762
763
  }), await this.encoder.ready, this.isReady = !0;
763
764
  } catch (e) {
764
765
  this.onError(e instanceof Error ? e : new Error(String(e)));
@@ -793,24 +794,24 @@ class Ke {
793
794
  return this.bitrate;
794
795
  }
795
796
  }
796
- const T = (t) => self.postMessage(t);
797
+ const V = (t) => self.postMessage(t);
797
798
  let p = null;
798
799
  function g(t, e) {
799
800
  const r = t instanceof Error ? t : new Error(String(t));
800
- T({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
801
+ V({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
801
802
  }
802
- function $e(t) {
803
+ function qe(t) {
803
804
  return t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.slice().buffer;
804
805
  }
805
806
  function L(t) {
806
807
  if (!p) {
807
- _.warn("Audio capture message dropped: sendPort not available");
808
+ F.warn("Audio capture message dropped: sendPort not available");
808
809
  return;
809
810
  }
810
- const e = $e(t);
811
+ const e = qe(t);
811
812
  p.postMessage({ type: "send", message: e }, [e]);
812
813
  }
813
- function je(t) {
814
+ function Ge(t) {
814
815
  if (t.length === 0)
815
816
  return 0;
816
817
  let e = 0;
@@ -818,11 +819,11 @@ function je(t) {
818
819
  e += Math.abs(t[r] ?? 0);
819
820
  return e / t.length;
820
821
  }
821
- const d = /* @__PURE__ */ new Map();
822
+ const h = /* @__PURE__ */ new Map();
822
823
  let S = null;
823
- function qe() {
824
+ function Ye() {
824
825
  S === null && (S = self.setInterval(() => {
825
- for (const t of d.values())
826
+ for (const t of h.values())
826
827
  if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
827
828
  try {
828
829
  const e = t.ringBuffer.pop(t.ringTemp);
@@ -834,11 +835,11 @@ function qe() {
834
835
  }
835
836
  }, 10));
836
837
  }
837
- function Ge() {
838
+ function Je() {
838
839
  if (S === null)
839
840
  return;
840
841
  let t = !1;
841
- for (const e of d.values())
842
+ for (const e of h.values())
842
843
  if (e.transport === "sab" && !e.stopped) {
843
844
  t = !0;
844
845
  break;
@@ -868,7 +869,7 @@ function P(t) {
868
869
  r.set(t.pendingBuffer.subarray(i, n)), r.set(t.pendingBuffer.subarray(0, e - a), a);
869
870
  }
870
871
  t.pendingReadOffset = (i + e) % n, t.pendingSamples -= e;
871
- const s = je(r);
872
+ const s = Ge(r);
872
873
  t.lastVolume = s;
873
874
  try {
874
875
  if (t.useWasmEncoder)
@@ -904,8 +905,8 @@ function W(t, e) {
904
905
  if (t.pendingReadOffset + t.pendingSamples <= c)
905
906
  u.set(t.pendingBuffer.subarray(t.pendingReadOffset, t.pendingReadOffset + t.pendingSamples));
906
907
  else {
907
- const h = c - t.pendingReadOffset;
908
- u.set(t.pendingBuffer.subarray(t.pendingReadOffset, c)), u.set(t.pendingBuffer.subarray(0, t.pendingSamples - h), h);
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);
909
910
  }
910
911
  }
911
912
  t.pendingBuffer = u, t.pendingReadOffset = 0, t.pendingWriteOffset = t.pendingSamples;
@@ -914,15 +915,15 @@ function W(t, e) {
914
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);
915
916
  }
916
917
  function H(t, e, r, n, i = !0) {
917
- const s = d.get(t.captureId);
918
+ const s = h.get(t.captureId);
918
919
  if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
919
920
  return;
920
921
  const a = e.byteLength;
921
922
  s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(e);
922
923
  const u = s.encoderOutputBuffer.subarray(0, a), c = s.segmentStartPending;
923
924
  c && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
924
- const h = s.segmentEndPending;
925
- h && (s.segmentEndPending = !1, s.inSegment = !1);
925
+ const d = s.segmentEndPending;
926
+ d && (s.segmentEndPending = !1, s.inSegment = !1);
926
927
  const w = s.frameSize * s.channels, I = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
927
928
  L(
928
929
  le(
@@ -933,19 +934,19 @@ function H(t, e, r, n, i = !0) {
933
934
  FrameSizeInInterleavedSamples: w,
934
935
  TimeStampInInterleavedSamples: I,
935
936
  IsFirst: c,
936
- IsLast: h,
937
+ IsLast: d,
937
938
  AverageVolume: s.lastVolume,
938
939
  AudioEventEstimatedDuration: 0
939
940
  }),
940
941
  s.senderId,
941
- { trackId: s.trackId }
942
+ { trackId: s.trackId, targetIds: s.targetIds }
942
943
  )
943
944
  ), s.sequence++;
944
945
  }
945
- function Ye(t) {
946
- const e = Math.max(V, Math.floor(t.options?.bitrate ?? M)), r = new AudioEncoder({
946
+ function Ze(t) {
947
+ const e = Math.max(T, Math.floor(t.options?.bitrate ?? M)), r = new AudioEncoder({
947
948
  output: (n) => {
948
- const i = d.get(t.captureId);
949
+ const i = h.get(t.captureId);
949
950
  if (!i)
950
951
  return;
951
952
  const s = n.byteLength;
@@ -974,15 +975,15 @@ function Ye(t) {
974
975
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
975
976
  }), r;
976
977
  }
977
- function Je(t) {
978
- const e = Math.max(V, Math.floor(t.options?.bitrate ?? M));
979
- return new Ke({
978
+ function Qe(t) {
979
+ const e = Math.max(T, Math.floor(t.options?.bitrate ?? M));
980
+ return new je({
980
981
  sampleRate: t.sampleRate,
981
982
  channels: t.channels,
982
983
  bitrate: e,
983
984
  frameSize: t.frameSize,
984
985
  onOutput: (r, n, i) => {
985
- const s = d.get(t.captureId);
986
+ const s = h.get(t.captureId);
986
987
  s && H(s, r, n, i, !0);
987
988
  },
988
989
  onError: (r) => {
@@ -990,7 +991,7 @@ function Je(t) {
990
991
  }
991
992
  });
992
993
  }
993
- async function Ze() {
994
+ async function Xe() {
994
995
  if (typeof AudioEncoder > "u")
995
996
  return !1;
996
997
  try {
@@ -1003,13 +1004,15 @@ async function Ze() {
1003
1004
  return !1;
1004
1005
  }
1005
1006
  }
1006
- async function Qe(t) {
1007
+ async function et(t) {
1007
1008
  if (!p)
1008
1009
  throw new Error("Audio capture worker missing send port");
1009
- if (d.has(t.captureId))
1010
+ if (h.has(t.captureId))
1010
1011
  return;
1011
- 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 = {
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 = {
1012
1013
  captureId: t.captureId,
1014
+ streamId: t.streamId,
1015
+ sourceType: t.sourceType,
1013
1016
  senderId: t.senderId,
1014
1017
  trackId: t.trackId,
1015
1018
  sampleRate: e,
@@ -1034,49 +1037,52 @@ async function Qe(t) {
1034
1037
  epoch: 0,
1035
1038
  sequence: 0,
1036
1039
  lastVolume: 0,
1040
+ targetIds: t.options?.targetIds,
1037
1041
  options: t.options
1038
- }, c = (t.options?.preferWebCodecs ?? !0) && await Ze();
1039
- let h, w = !1;
1040
- const I = Math.max(V, Math.floor(t.options?.bitrate ?? M));
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));
1041
1045
  if (c)
1042
- h = Ye(a), _.info(
1046
+ d = Ze(a), F.info(
1043
1047
  `Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1044
1048
  );
1045
1049
  else {
1046
- const l = Je(a);
1047
- await l.initialize(), h = l, w = !0, _.info(
1050
+ const l = Qe(a);
1051
+ await l.initialize(), d = l, w = !0, F.info(
1048
1052
  `Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${I}bps`
1049
1053
  );
1050
1054
  }
1051
1055
  const y = {
1052
1056
  ...a,
1053
- encoder: h,
1057
+ encoder: d,
1054
1058
  useWasmEncoder: w
1055
1059
  };
1056
1060
  if (t.transport === "sab") {
1057
1061
  if (!t.sharedArrayBuffer)
1058
1062
  throw new Error("Missing SharedArrayBuffer for sab transport");
1059
- const l = new We(t.sharedArrayBuffer, Float32Array);
1060
- y.ringBuffer = l, y.ringTemp = new Float32Array(Math.max(y.frameSize * 4, 4096)), qe();
1061
- }
1062
- d.set(t.captureId, y), L(
1063
- Ue(
1064
- Ae({
1065
- Description: `mic:${t.captureId}`,
1063
+ const l = new ve(t.sharedArrayBuffer, Float32Array);
1064
+ y.ringBuffer = l, y.ringTemp = new Float32Array(Math.max(y.frameSize * 4, 4096)), Ye();
1065
+ }
1066
+ h.set(t.captureId, y), L(
1067
+ Oe(
1068
+ _e({
1069
+ StreamId: t.streamId,
1070
+ Description: `mic:${t.streamId}`,
1071
+ SourceType: t.sourceType,
1066
1072
  Codec: R.Opus,
1073
+ CodecDetails: "",
1067
1074
  SampleRate: e,
1068
- Channels: r,
1069
- BitDepth: 32
1075
+ Channels: r
1070
1076
  }),
1071
1077
  t.senderId,
1072
- { trackId: t.trackId }
1078
+ { trackId: t.trackId, targetIds: y.targetIds }
1073
1079
  )
1074
- ), T({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1080
+ ), V({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
1075
1081
  }
1076
1082
  async function z(t) {
1077
- const e = d.get(t);
1083
+ const e = h.get(t);
1078
1084
  if (e) {
1079
- e.stopped = !0, d.delete(t);
1085
+ e.stopped = !0, h.delete(t);
1080
1086
  try {
1081
1087
  P(e);
1082
1088
  } catch {
@@ -1089,15 +1095,15 @@ async function z(t) {
1089
1095
  e.encoder.close();
1090
1096
  } catch {
1091
1097
  }
1092
- L(Pe(Te({}), e.senderId, { trackId: e.trackId })), T({ type: "stopped", captureId: t }), Ge();
1098
+ L(Ce(Pe({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), V({ type: "stopped", captureId: e.captureId }), Je();
1093
1099
  }
1094
1100
  }
1095
- function Xe(t) {
1096
- const e = d.get(t);
1101
+ function tt(t) {
1102
+ const e = h.get(t);
1097
1103
  !e || e.stopped || (e.inSegment = !0, e.segmentStartPending = !0);
1098
1104
  }
1099
- function et(t) {
1100
- const e = d.get(t);
1105
+ function rt(t) {
1106
+ const e = h.get(t);
1101
1107
  if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, P(e), e.segmentEndPending && !e.stopped)) {
1102
1108
  const r = e.frameSize - e.pendingSamples;
1103
1109
  if (r > 0) {
@@ -1106,8 +1112,8 @@ function et(t) {
1106
1112
  }
1107
1113
  }
1108
1114
  }
1109
- function tt() {
1110
- for (const t of Array.from(d.keys()))
1115
+ function nt() {
1116
+ for (const t of Array.from(h.keys()))
1111
1117
  z(t);
1112
1118
  if (p) {
1113
1119
  try {
@@ -1133,13 +1139,13 @@ self.addEventListener("message", (t) => {
1133
1139
  return;
1134
1140
  }
1135
1141
  if (e.type === "start") {
1136
- Qe(e).catch((r) => {
1142
+ et(e).catch((r) => {
1137
1143
  g(r, e.captureId);
1138
1144
  });
1139
1145
  return;
1140
1146
  }
1141
1147
  if (e.type === "pcm") {
1142
- const r = d.get(e.captureId);
1148
+ const r = h.get(e.captureId);
1143
1149
  if (!r || r.stopped)
1144
1150
  return;
1145
1151
  W(r, e.pcm);
@@ -1147,17 +1153,17 @@ self.addEventListener("message", (t) => {
1147
1153
  }
1148
1154
  if (e.type === "stop") {
1149
1155
  z(e.captureId).catch((r) => {
1150
- _.warn(`Failed to stop audio capture: ${r}`), g(r, e.captureId);
1156
+ F.warn(`Failed to stop audio capture: ${r}`), g(r, e.captureId);
1151
1157
  });
1152
1158
  return;
1153
1159
  }
1154
1160
  if (e.type === "startSegment") {
1155
- Xe(e.captureId);
1161
+ tt(e.captureId);
1156
1162
  return;
1157
1163
  }
1158
1164
  if (e.type === "endSegment") {
1159
- et(e.captureId);
1165
+ rt(e.captureId);
1160
1166
  return;
1161
1167
  }
1162
- e.type === "dispose" && tt();
1168
+ e.type === "dispose" && nt();
1163
1169
  });