@ikonai/sdk 0.0.31 → 0.0.33

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 U(e, t, r, i, n) {
2
- const s = n?.trackId ?? 0, o = n?.sequenceId ?? 0, d = n?.flags ?? 0, c = n?.targetIds ?? [], g = n?.payloadType ?? 8, V = 27 + c.length * 4, O = V + t.length, D = new Uint8Array(O), u = new DataView(D.buffer);
3
- u.setUint32(0, O, !0), u.setUint32(4, e >>> 0, !0), u.setUint32(8, i >>> 0, !0), u.setUint32(12, s >>> 0, !0), u.setUint32(16, o >>> 0, !0), u.setUint32(20, c.length >>> 0, !0), u.setUint8(24, r & 255), u.setUint8(25, g & 255), u.setUint8(26, d & 255);
1
+ function F(e, t, r, n, i) {
2
+ const s = i?.trackId ?? 0, o = i?.sequenceId ?? 0, u = i?.flags ?? 0, c = i?.targetIds ?? [], w = i?.payloadType ?? 8, V = 27 + c.length * 4, R = V + t.length, B = new Uint8Array(R), d = new DataView(B.buffer);
3
+ d.setUint32(0, R, !0), d.setUint32(4, e >>> 0, !0), d.setUint32(8, n >>> 0, !0), d.setUint32(12, s >>> 0, !0), d.setUint32(16, o >>> 0, !0), d.setUint32(20, c.length >>> 0, !0), d.setUint8(24, r & 255), d.setUint8(25, w & 255), d.setUint8(26, u & 255);
4
4
  let L = 27;
5
- for (let B = 0; B < c.length; B++)
6
- u.setUint32(L, c[B] >>> 0, !0), L += 4;
7
- return D.set(t, V), D;
5
+ for (let D = 0; D < c.length; D++)
6
+ d.setUint32(L, c[D] >>> 0, !0), L += 4;
7
+ return B.set(t, V), B;
8
8
  }
9
- var w = /* @__PURE__ */ ((e) => (e[e.Null = 1] = "Null", e[e.Bool = 2] = "Bool", e[e.Int32 = 3] = "Int32", e[e.Int64 = 4] = "Int64", e[e.UInt32 = 5] = "UInt32", e[e.UInt64 = 6] = "UInt64", e[e.Float32 = 7] = "Float32", e[e.Float64 = 8] = "Float64", e[e.Array = 9] = "Array", e[e.Dict = 10] = "Dict", e[e.Object = 11] = "Object", e[e.String = 12] = "String", e[e.Binary = 13] = "Binary", e[e.Guid = 14] = "Guid", e))(w || {});
9
+ var y = /* @__PURE__ */ ((e) => (e[e.Null = 1] = "Null", e[e.Bool = 2] = "Bool", e[e.Int32 = 3] = "Int32", e[e.Int64 = 4] = "Int64", e[e.UInt32 = 5] = "UInt32", e[e.UInt64 = 6] = "UInt64", e[e.Float32 = 7] = "Float32", e[e.Float64 = 8] = "Float64", e[e.Array = 9] = "Array", e[e.Dict = 10] = "Dict", e[e.Object = 11] = "Object", e[e.String = 12] = "String", e[e.Binary = 13] = "Binary", e[e.Guid = 14] = "Guid", e))(y || {});
10
10
  const C = 161, K = 162, E = new TextEncoder();
11
11
  new TextDecoder("utf-8", { fatal: !0 });
12
- class y {
12
+ class f {
13
13
  constructor(t = 1) {
14
14
  this.version = t, this.buffer.writeByte(C), this.buffer.writeVarUInt(t >>> 0);
15
15
  }
16
- buffer = new p();
16
+ buffer = new I();
17
17
  closed = !1;
18
18
  cached;
19
19
  writeInt32Field(t, r) {
@@ -38,54 +38,54 @@ class y {
38
38
  this.writeFixedField(t, 2, () => this.buffer.writeByte(r ? 1 : 0));
39
39
  }
40
40
  writeGuidField(t, r) {
41
- const i = r instanceof a ? r.asBytes() : r;
42
- if (i.length !== 16)
41
+ const n = r instanceof a ? r.asBytes() : r;
42
+ if (n.length !== 16)
43
43
  throw new Error("Guid payload must be 16 bytes");
44
- this.writeFixedField(t, 14, () => this.buffer.writeBytes(i));
44
+ this.writeFixedField(t, 14, () => this.buffer.writeBytes(n));
45
45
  }
46
46
  writeStringField(t, r) {
47
- const i = E.encode(r ?? "");
48
- this.writeVariableField(t, 12, i);
47
+ const n = E.encode(r ?? "");
48
+ this.writeVariableField(t, 12, n);
49
49
  }
50
50
  writeBinaryField(t, r) {
51
51
  this.writeVariableField(t, 13, r);
52
52
  }
53
- writeObjectField(t, r, i) {
54
- const n = new y(r);
55
- i(n);
56
- const s = n.finish();
53
+ writeObjectField(t, r, n) {
54
+ const i = new f(r);
55
+ n(i);
56
+ const s = i.finish();
57
57
  this.writeVariableField(t, 11, s);
58
58
  }
59
- writeArrayField(t, r, i) {
60
- const n = new b(r);
61
- i(n);
62
- const s = n.finish();
59
+ writeArrayField(t, r, n) {
60
+ const i = new b(r);
61
+ n(i);
62
+ const s = i.finish();
63
63
  this.writeVariableField(t, 9, s);
64
64
  }
65
- writeDictionaryField(t, r, i, n) {
66
- const s = new _(r, i);
67
- n(s);
65
+ writeDictionaryField(t, r, n, i) {
66
+ const s = new S(r, n);
67
+ i(s);
68
68
  const o = s.finish();
69
69
  this.writeVariableField(t, 10, o);
70
70
  }
71
71
  finish() {
72
72
  return this.closed || (this.buffer.writeByte(K), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
73
73
  }
74
- writeFixedField(t, r, i) {
75
- this.writeFieldHeader(t, r, 0), i();
74
+ writeFixedField(t, r, n) {
75
+ this.writeFieldHeader(t, r, 0), n();
76
76
  }
77
- writeVariableField(t, r, i) {
78
- this.writeFieldHeader(t, r, i.length), this.buffer.writeBytes(i);
77
+ writeVariableField(t, r, n) {
78
+ this.writeFieldHeader(t, r, n.length), this.buffer.writeBytes(n);
79
79
  }
80
- writeFieldHeader(t, r, i) {
81
- this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(F(r)), z(r) && this.buffer.writeVarUInt(i >>> 0);
80
+ writeFieldHeader(t, r, n) {
81
+ this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(U(r)), j(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
84
  class b {
85
85
  constructor(t) {
86
86
  this.elementType = t;
87
87
  }
88
- payload = new p();
88
+ payload = new I();
89
89
  count = 0;
90
90
  writeInt32(t) {
91
91
  this.ensureElementType(
@@ -158,45 +158,45 @@ class b {
158
158
  11
159
159
  /* Object */
160
160
  ), this.count++;
161
- const i = new y(t);
162
- r(i);
163
- const n = i.finish();
164
- this.payload.writeVarUInt(n.length), this.payload.writeBytes(n);
161
+ const n = new f(t);
162
+ r(n);
163
+ const i = n.finish();
164
+ this.payload.writeVarUInt(i.length), this.payload.writeBytes(i);
165
165
  }
166
166
  writeArray(t, r) {
167
167
  this.ensureElementType(
168
168
  9
169
169
  /* Array */
170
170
  ), this.count++;
171
- const i = new b(t);
172
- r(i);
173
- const n = i.finish();
174
- this.payload.writeBytes(n);
171
+ const n = new b(t);
172
+ r(n);
173
+ const i = n.finish();
174
+ this.payload.writeBytes(i);
175
175
  }
176
- writeDictionary(t, r, i) {
176
+ writeDictionary(t, r, n) {
177
177
  this.ensureElementType(
178
178
  10
179
179
  /* Dict */
180
180
  ), this.count++;
181
- const n = new _(t, r);
182
- i(n);
183
- const s = n.finish();
181
+ const i = new S(t, r);
182
+ n(i);
183
+ const s = i.finish();
184
184
  this.payload.writeBytes(s);
185
185
  }
186
186
  finish() {
187
- const t = new p();
188
- return t.writeByte(F(this.elementType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
187
+ const t = new I();
188
+ return t.writeByte(U(this.elementType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
189
189
  }
190
190
  ensureElementType(t) {
191
191
  if (this.elementType !== t)
192
- throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[t]}`);
192
+ throw new Error(`Array element type is ${y[this.elementType]}, expected ${y[t]}`);
193
193
  }
194
194
  }
195
- class _ {
195
+ class S {
196
196
  constructor(t, r) {
197
- this.keyType = t, this.valueType = r, j(t);
197
+ this.keyType = t, this.valueType = r, z(t);
198
198
  }
199
- payload = new p();
199
+ payload = new I();
200
200
  count = 0;
201
201
  entryOpen = !1;
202
202
  beginEntry() {
@@ -209,13 +209,13 @@ class _ {
209
209
  finish() {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
- const t = new p();
213
- return t.writeByte(F(this.keyType)), t.writeByte(F(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
212
+ const t = new I();
213
+ return t.writeByte(U(this.keyType)), t.writeByte(U(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
214
214
  }
215
215
  }
216
216
  class H {
217
- constructor(t, r, i, n) {
218
- this.keyType = t, this.valueType = r, this.payload = i, this.onComplete = n;
217
+ constructor(t, r, n, i) {
218
+ this.keyType = t, this.valueType = r, this.payload = n, this.onComplete = i;
219
219
  }
220
220
  keyWritten = !1;
221
221
  valueWritten = !1;
@@ -363,29 +363,29 @@ class H {
363
363
  11
364
364
  /* Object */
365
365
  );
366
- const i = new y(t);
367
- r(i);
368
- const n = i.finish();
369
- this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.valueWritten = !0;
366
+ const n = new f(t);
367
+ r(n);
368
+ const i = n.finish();
369
+ this.payload.writeVarUInt(i.length), this.payload.writeBytes(i), this.valueWritten = !0;
370
370
  }
371
371
  writeValueArray(t, r) {
372
372
  this.ensureValueType(
373
373
  9
374
374
  /* Array */
375
375
  );
376
- const i = new b(t);
377
- r(i);
378
- const n = i.finish();
379
- this.payload.writeBytes(n), this.valueWritten = !0;
376
+ const n = new b(t);
377
+ r(n);
378
+ const i = n.finish();
379
+ this.payload.writeBytes(i), this.valueWritten = !0;
380
380
  }
381
- writeValueDictionary(t, r, i) {
381
+ writeValueDictionary(t, r, n) {
382
382
  this.ensureValueType(
383
383
  10
384
384
  /* Dict */
385
385
  );
386
- const n = new _(t, r);
387
- i(n);
388
- const s = n.finish();
386
+ const i = new S(t, r);
387
+ n(i);
388
+ const s = i.finish();
389
389
  this.payload.writeBytes(s), this.valueWritten = !0;
390
390
  }
391
391
  complete() {
@@ -397,11 +397,11 @@ class H {
397
397
  }
398
398
  ensureKeyType(t) {
399
399
  if (this.keyType !== t)
400
- throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[t]}`);
400
+ throw new Error(`Dictionary key type is ${y[this.keyType]}, expected ${y[t]}`);
401
401
  }
402
402
  ensureValueType(t) {
403
403
  if (this.valueType !== t)
404
- throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[t]}`);
404
+ throw new Error(`Dictionary value type is ${y[this.valueType]}, expected ${y[t]}`);
405
405
  }
406
406
  }
407
407
  class a {
@@ -414,11 +414,11 @@ class a {
414
414
  const r = t.replace(/-/g, "");
415
415
  if (r.length !== 32)
416
416
  throw new Error("Guid string must be 32 hex characters");
417
- const i = new Uint8Array(16), n = a.parseHexSlice(r, 0, 8), s = a.parseHexSlice(r, 8, 4), o = a.parseHexSlice(r, 12, 4);
418
- a.writeUInt32LE(i, 0, n), a.writeUInt16LE(i, 4, s), a.writeUInt16LE(i, 6, o);
419
- for (let d = 0; d < 8; d++)
420
- i[8 + d] = a.parseHexSlice(r, 16 + d * 2, 2);
421
- return new a(i);
417
+ const n = new Uint8Array(16), i = a.parseHexSlice(r, 0, 8), s = a.parseHexSlice(r, 8, 4), o = a.parseHexSlice(r, 12, 4);
418
+ a.writeUInt32LE(n, 0, i), a.writeUInt16LE(n, 4, s), a.writeUInt16LE(n, 6, o);
419
+ for (let u = 0; u < 8; u++)
420
+ n[8 + u] = a.parseHexSlice(r, 16 + u * 2, 2);
421
+ return new a(n);
422
422
  }
423
423
  static fromBytes(t) {
424
424
  if (t.length !== 16)
@@ -433,8 +433,8 @@ class a {
433
433
  if (r?.getRandomValues)
434
434
  r.getRandomValues(t);
435
435
  else
436
- for (let i = 0; i < t.length; i++)
437
- t[i] = Math.floor(Math.random() * 256);
436
+ for (let n = 0; n < t.length; n++)
437
+ t[n] = Math.floor(Math.random() * 256);
438
438
  return t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, new a(t);
439
439
  }
440
440
  toString() {
@@ -443,26 +443,26 @@ class a {
443
443
  a.toHex(a.readUInt32LE(t, 0), 8),
444
444
  a.toHex(a.readUInt16LE(t, 4), 4),
445
445
  a.toHex(a.readUInt16LE(t, 6), 4),
446
- R(t.subarray(8, 10)),
447
- R(t.subarray(10, 16))
446
+ T(t.subarray(8, 10)),
447
+ T(t.subarray(10, 16))
448
448
  ].join("-");
449
449
  }
450
450
  asBytes() {
451
451
  return this.bytes.slice();
452
452
  }
453
- static parseHexSlice(t, r, i) {
454
- const n = t.substr(r, i), s = Number.parseInt(n, 16);
453
+ static parseHexSlice(t, r, n) {
454
+ const i = t.substr(r, n), s = Number.parseInt(i, 16);
455
455
  if (Number.isNaN(s))
456
456
  throw new Error("Guid string contains invalid characters");
457
457
  return s >>> 0;
458
458
  }
459
- static writeUInt32LE(t, r, i) {
460
- const n = i >>> 0;
461
- t[r] = n & 255, t[r + 1] = n >>> 8 & 255, t[r + 2] = n >>> 16 & 255, t[r + 3] = n >>> 24 & 255;
459
+ static writeUInt32LE(t, r, n) {
460
+ const i = n >>> 0;
461
+ t[r] = i & 255, t[r + 1] = i >>> 8 & 255, t[r + 2] = i >>> 16 & 255, t[r + 3] = i >>> 24 & 255;
462
462
  }
463
- static writeUInt16LE(t, r, i) {
464
- const n = i & 65535;
465
- t[r] = n & 255, t[r + 1] = n >>> 8 & 255;
463
+ static writeUInt16LE(t, r, n) {
464
+ const i = n & 65535;
465
+ t[r] = i & 255, t[r + 1] = i >>> 8 & 255;
466
466
  }
467
467
  static readUInt32LE(t, r) {
468
468
  return (t[r] | t[r + 1] << 8 | t[r + 2] << 16 | t[r + 3] << 24) >>> 0;
@@ -474,7 +474,7 @@ class a {
474
474
  return (t >>> 0).toString(16).padStart(r, "0");
475
475
  }
476
476
  }
477
- class p {
477
+ class I {
478
478
  bytes = [];
479
479
  writeByte(t) {
480
480
  this.bytes.push(t & 255);
@@ -515,103 +515,103 @@ class p {
515
515
  return Uint8Array.from(this.bytes);
516
516
  }
517
517
  }
518
- function F(e, t = 0) {
518
+ function U(e, t = 0) {
519
519
  if ((t & 240) !== 0)
520
520
  throw new Error("Teleport flags must fit into 4 bits");
521
521
  return (e & 15) << 4 | t & 15;
522
522
  }
523
- function z(e) {
523
+ function j(e) {
524
524
  return e === 12 || e === 13 || e === 9 || e === 11 || e === 10;
525
525
  }
526
- function j(e) {
526
+ function z(e) {
527
527
  if (e === 9 || e === 11 || e === 10 || e === 1)
528
528
  throw new Error("Dictionary keys must be primitive Teleport types");
529
529
  }
530
- function R(e) {
530
+ function T(e) {
531
531
  return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
532
532
  }
533
- var S = /* @__PURE__ */ ((e) => (e[e.Unknown = 0] = "Unknown", e[e.Opus = 1] = "Opus", e[e.Mp3 = 2] = "Mp3", e[e.RawPcm16 = 3] = "RawPcm16", e))(S || {});
534
- const T = 1, $ = 4194307, G = 271275304, Y = 668699606, q = 945580544, J = 1594075008, Z = 2079085407, Q = 2541432218, X = 2986785889, tt = 3105403172, et = 4017217601;
533
+ var _ = /* @__PURE__ */ ((e) => (e[e.Unknown = 0] = "Unknown", e[e.Opus = 1] = "Opus", e[e.Mp3 = 2] = "Mp3", e[e.RawPcm16 = 3] = "RawPcm16", e))(_ || {});
534
+ const W = 1, $ = 4194307, q = 271275304, G = 668699606, Y = 945580544, J = 1594075008, Z = 2079085407, Q = 2541432218, X = 2986785889, tt = 3105403172, et = 4017217601;
535
535
  function rt(e) {
536
536
  const t = {};
537
- return it(t), e && Object.assign(t, e), t;
537
+ return nt(t), e && Object.assign(t, e), t;
538
538
  }
539
- function it(e) {
539
+ function nt(e) {
540
540
  return e.Data = new Uint8Array(0), e.IsKey = !1, e.IsLast = !1, e.TimestampInUs = 0n, e.DurationInUs = 0, e.IsFirst = !1, e.TotalDurationInUs = 0, e.Volume = 0, e.VolumeSampleCount = 0, e;
541
541
  }
542
- function nt(e) {
543
- const t = new y(T);
542
+ function it(e) {
543
+ const t = new f(W);
544
544
  return st(e, t), t.finish();
545
545
  }
546
546
  function st(e, t) {
547
- t.writeUInt64Field(G, e.TimestampInUs), t.writeUInt32Field(Y, e.TotalDurationInUs >>> 0), t.writeInt32Field(q, e.VolumeSampleCount | 0), t.writeBoolField(J, e.IsFirst), t.writeFloat32Field(Z, e.Volume), t.writeUInt32Field(Q, e.DurationInUs >>> 0), t.writeBinaryField(X, e.Data), t.writeBoolField(tt, e.IsKey), t.writeBoolField(et, e.IsLast);
547
+ t.writeUInt64Field(q, e.TimestampInUs), t.writeUInt32Field(G, e.TotalDurationInUs >>> 0), t.writeInt32Field(Y, e.VolumeSampleCount | 0), t.writeBoolField(J, e.IsFirst), t.writeFloat32Field(Z, e.Volume), t.writeUInt32Field(Q, e.DurationInUs >>> 0), t.writeBinaryField(X, e.Data), t.writeBoolField(tt, e.IsKey), t.writeBoolField(et, e.IsLast);
548
548
  }
549
549
  function at(e, t, r) {
550
- const i = nt(e);
551
- return U($, i, T, t, r);
550
+ const n = it(e);
551
+ return F($, n, W, t, r);
552
552
  }
553
- const W = 1, ot = 4194308, ut = 2079085407, lt = 3485914759;
554
- function ct(e) {
553
+ const P = 1, ot = 4194308, ut = 2079085407, ct = 3485914759;
554
+ function lt(e) {
555
555
  const t = {};
556
- return ht(t), e && Object.assign(t, e), t;
556
+ return dt(t), e && Object.assign(t, e), t;
557
557
  }
558
- function ht(e) {
558
+ function dt(e) {
559
559
  return e.Volume = 0, e.Count = 0, e;
560
560
  }
561
- function dt(e) {
562
- const t = new y(W);
563
- return yt(e, t), t.finish();
561
+ function ht(e) {
562
+ const t = new f(P);
563
+ return ft(e, t), t.finish();
564
564
  }
565
- function yt(e, t) {
566
- t.writeFloat32Field(ut, e.Volume), t.writeInt32Field(lt, e.Count | 0);
565
+ function ft(e, t) {
566
+ t.writeFloat32Field(ut, e.Volume), t.writeInt32Field(ct, e.Count | 0);
567
567
  }
568
- function wt(e, t, r) {
569
- const i = dt(e);
570
- return U(ot, i, W, t, r);
568
+ function yt(e, t, r) {
569
+ const n = ht(e);
570
+ return F(ot, n, P, t, r);
571
571
  }
572
- const k = 1, ft = 4194305, pt = 1368629611, It = 2431514951, mt = 2914494629, Et = 3284746250, Ft = 4101844078;
572
+ const k = 1, wt = 4194305, pt = 1368629611, It = 2431514951, mt = 2914494629, gt = 3284746250, Et = 4101844078;
573
573
  function Ut(e) {
574
574
  const t = {};
575
- return bt(t), e && Object.assign(t, e), t;
575
+ return Ft(t), e && Object.assign(t, e), t;
576
576
  }
577
- function bt(e) {
578
- return e.Description = "", e.Codec = S.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
577
+ function Ft(e) {
578
+ return e.Description = "", e.Codec = _.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
579
579
  }
580
- function At(e) {
581
- const t = new y(k);
582
- return gt(e, t), t.finish();
580
+ function bt(e) {
581
+ const t = new f(k);
582
+ return At(e, t), t.finish();
583
583
  }
584
- function gt(e, t) {
585
- t.writeStringField(pt, e.Description), t.writeInt32Field(It, e.Channels | 0), t.writeInt32Field(mt, e.BitDepth | 0), t.writeInt32Field(Et, e.Codec), t.writeInt32Field(Ft, e.SampleRate | 0);
584
+ function At(e, t) {
585
+ t.writeStringField(pt, e.Description), t.writeInt32Field(It, e.Channels | 0), t.writeInt32Field(mt, e.BitDepth | 0), t.writeInt32Field(gt, e.Codec), t.writeInt32Field(Et, e.SampleRate | 0);
586
586
  }
587
- function Dt(e, t, r) {
588
- const i = At(e);
589
- return U(ft, i, k, t, r);
587
+ function Bt(e, t, r) {
588
+ const n = bt(e);
589
+ return F(wt, n, k, t, r);
590
590
  }
591
- const v = 1, Bt = 4194306;
592
- function _t(e) {
591
+ const N = 1, Dt = 4194306;
592
+ function St(e) {
593
593
  const t = {};
594
594
  return e && Object.assign(t, e), t;
595
595
  }
596
- function St(e) {
597
- return new y(v).finish();
596
+ function _t(e) {
597
+ return new f(N).finish();
598
598
  }
599
- function Mt(e, t, r) {
600
- const i = St();
601
- return U(Bt, i, v, t, r);
599
+ function Ot(e, t, r) {
600
+ const n = _t();
601
+ return F(Dt, n, N, t, r);
602
602
  }
603
- class Vt {
603
+ class Mt {
604
604
  static getStorageForCapacity(t, r) {
605
- const i = Int32Array.BYTES_PER_ELEMENT * 2, n = r.BYTES_PER_ELEMENT * t;
606
- return new SharedArrayBuffer(i + n);
605
+ const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * t;
606
+ return new SharedArrayBuffer(n + i);
607
607
  }
608
608
  readWrite;
609
609
  storage;
610
610
  buf;
611
611
  constructor(t, r) {
612
612
  this.buf = t, this.readWrite = new Int32Array(t, 0, 2);
613
- const i = Int32Array.BYTES_PER_ELEMENT * 2, n = (t.byteLength - i) / Float32Array.BYTES_PER_ELEMENT;
614
- this.storage = new r(t, i, n);
613
+ const n = Int32Array.BYTES_PER_ELEMENT * 2, i = (t.byteLength - n) / Float32Array.BYTES_PER_ELEMENT;
614
+ this.storage = new r(t, n, i);
615
615
  }
616
616
  get capacity() {
617
617
  return this.storage.length;
@@ -630,85 +630,85 @@ class Vt {
630
630
  const r = Math.min(this.availableWrite(), t.length);
631
631
  if (r <= 0)
632
632
  return 0;
633
- let i = Atomics.load(this.readWrite, 1);
634
- const n = Math.min(r, this.capacity - i);
635
- this.storage.set(t.subarray(0, n), i);
636
- const s = r - n;
637
- return s > 0 && this.storage.set(t.subarray(n, n + s), 0), i = (i + r) % this.capacity, Atomics.store(this.readWrite, 1, i), Atomics.notify(this.readWrite, 1), r;
633
+ let n = Atomics.load(this.readWrite, 1);
634
+ const i = Math.min(r, this.capacity - n);
635
+ this.storage.set(t.subarray(0, i), n);
636
+ const s = r - i;
637
+ return s > 0 && this.storage.set(t.subarray(i, i + s), 0), n = (n + r) % this.capacity, Atomics.store(this.readWrite, 1, n), Atomics.notify(this.readWrite, 1), r;
638
638
  }
639
639
  pop(t) {
640
640
  const r = Math.min(this.availableRead(), t.length);
641
641
  if (r <= 0)
642
642
  return 0;
643
- let i = Atomics.load(this.readWrite, 0);
644
- const n = Math.min(r, this.capacity - i);
645
- t.set(this.storage.subarray(i, i + n), 0);
646
- const s = r - n;
647
- return s > 0 && t.set(this.storage.subarray(0, s), n), i = (i + r) % this.capacity, Atomics.store(this.readWrite, 0, i), r;
643
+ let n = Atomics.load(this.readWrite, 0);
644
+ const i = Math.min(r, this.capacity - n);
645
+ t.set(this.storage.subarray(n, n + i), 0);
646
+ const s = r - i;
647
+ return s > 0 && t.set(this.storage.subarray(0, s), i), n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
648
648
  }
649
649
  skip(t) {
650
650
  const r = Math.min(this.availableRead(), t);
651
651
  if (r <= 0)
652
652
  return 0;
653
- let i = Atomics.load(this.readWrite, 0);
654
- return i = (i + r) % this.capacity, Atomics.store(this.readWrite, 0, i), r;
653
+ let n = Atomics.load(this.readWrite, 0);
654
+ return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
655
655
  }
656
656
  }
657
- let Ot = 1;
658
- function Lt(e, t) {
657
+ let Vt = 1;
658
+ function Rt(e, t) {
659
659
  return `[${e}] ${t}`;
660
660
  }
661
- function m(e, t, r, i) {
662
- if ((/* @__PURE__ */ new Date()).toISOString(), Ot <= e) {
663
- const n = Lt(t, r);
661
+ function g(e, t, r, n) {
662
+ if ((/* @__PURE__ */ new Date()).toISOString(), Vt <= e) {
663
+ const i = Rt(t, r);
664
664
  switch (e) {
665
665
  case 0:
666
- console.debug(n, ...i);
666
+ console.debug(i, ...n);
667
667
  break;
668
668
  case 1:
669
- console.info(n, ...i);
669
+ console.info(i, ...n);
670
670
  break;
671
671
  case 2:
672
- console.warn(n, ...i);
672
+ console.warn(i, ...n);
673
673
  break;
674
674
  case 3:
675
- console.error(n, ...i);
675
+ console.error(i, ...n);
676
676
  break;
677
677
  }
678
678
  }
679
679
  }
680
- function Rt(e) {
680
+ function Lt(e) {
681
681
  return {
682
682
  debug(t, ...r) {
683
- m(0, e, t, r);
683
+ g(0, e, t, r);
684
684
  },
685
685
  info(t, ...r) {
686
- m(1, e, t, r);
686
+ g(1, e, t, r);
687
687
  },
688
688
  warn(t, ...r) {
689
- m(2, e, t, r);
689
+ g(2, e, t, r);
690
690
  },
691
691
  error(t, ...r) {
692
- m(3, e, t, r);
692
+ g(3, e, t, r);
693
693
  }
694
694
  };
695
695
  }
696
- const Tt = Rt("AudioCaptureWorker"), M = (e) => self.postMessage(e);
697
- let l = null;
698
- function I(e, t) {
696
+ const Tt = 20, Wt = 32e3, Pt = Lt("AudioCaptureWorker"), O = (e) => self.postMessage(e);
697
+ let h = null;
698
+ function m(e, t) {
699
699
  const r = e instanceof Error ? e : new Error(String(e));
700
- M({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
700
+ O({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
701
701
  }
702
- function Wt(e) {
702
+ function kt(e) {
703
703
  return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
704
704
  }
705
705
  function A(e) {
706
- if (!l)
706
+ if (!h)
707
707
  return;
708
- const t = Wt(e);
709
- l.postMessage({ type: "send", message: t }, [t]);
708
+ const t = kt(e);
709
+ h.postMessage({ type: "send", message: t }, [t]);
710
710
  }
711
- function kt(e) {
711
+ function Nt(e) {
712
712
  if (e.length === 0)
713
713
  return 0;
714
714
  let t = 0;
@@ -716,90 +716,126 @@ function kt(e) {
716
716
  t += Math.abs(e[r] ?? 0);
717
717
  return t / e.length;
718
718
  }
719
- const h = /* @__PURE__ */ new Map();
720
- let f = null;
719
+ const l = /* @__PURE__ */ new Map();
720
+ let p = null;
721
721
  function vt() {
722
- f === null && (f = self.setInterval(() => {
723
- for (const e of h.values())
722
+ p === null && (p = self.setInterval(() => {
723
+ for (const e of l.values())
724
724
  if (!(e.transport !== "sab" || !e.ringBuffer || !e.ringTemp || e.stopped))
725
725
  try {
726
726
  const t = e.ringBuffer.pop(e.ringTemp);
727
727
  if (t <= 0)
728
728
  continue;
729
- const r = e.ringTemp.subarray(0, t);
730
- x(e, new Float32Array(r));
729
+ v(e, e.ringTemp.subarray(0, t));
731
730
  } catch (t) {
732
- I(t, e.captureId);
731
+ m(t, e.captureId);
733
732
  }
734
733
  }, 10));
735
734
  }
736
- function Nt() {
737
- if (!(f === null || Array.from(h.values()).some((t) => t.transport === "sab" && !t.stopped))) {
735
+ function xt() {
736
+ if (p === null)
737
+ return;
738
+ let e = !1;
739
+ for (const t of l.values())
740
+ if (t.transport === "sab" && !t.stopped) {
741
+ e = !0;
742
+ break;
743
+ }
744
+ if (!e) {
738
745
  try {
739
- self.clearInterval(f);
746
+ self.clearInterval(p);
740
747
  } catch {
741
748
  }
742
- f = null;
749
+ p = null;
743
750
  }
744
751
  }
745
- function N(e) {
746
- if (!e.stopped)
747
- for (; e.pendingSamples >= e.frameSize; ) {
748
- const t = new Float32Array(e.frameSize);
749
- let r = 0;
750
- for (; r < e.frameSize && e.pending.length > 0; ) {
751
- const n = e.pending[0], s = Math.min(n.length, e.frameSize - r);
752
- t.set(n.subarray(0, s), r), r += s, s === n.length ? e.pending.shift() : e.pending[0] = n.subarray(s);
753
- }
754
- e.pendingSamples -= e.frameSize;
755
- const i = kt(t);
756
- A(wt(ct({ Volume: i, Count: e.frameSize }), e.senderId, { trackId: e.trackId }));
757
- try {
758
- const n = new AudioData({
759
- format: "f32",
760
- sampleRate: e.sampleRate,
761
- numberOfFrames: e.frameSize,
762
- numberOfChannels: e.channels,
763
- timestamp: e.timestampUs,
764
- data: t
765
- });
766
- e.encoder.encode(n), n.close();
767
- } catch (n) {
768
- I(n, e.captureId);
769
- }
770
- e.timestampUs += e.frameDurationUs;
752
+ function M(e) {
753
+ if (e.stopped)
754
+ return;
755
+ if (!e.inSegment) {
756
+ e.pendingReadOffset = 0, e.pendingWriteOffset = 0, e.pendingSamples = 0;
757
+ return;
758
+ }
759
+ const t = e.frameSize, r = e.frameBuffer, n = e.pendingBuffer.length;
760
+ for (; e.pendingSamples >= t; ) {
761
+ const i = e.pendingReadOffset;
762
+ if (i + t <= n)
763
+ r.set(e.pendingBuffer.subarray(i, i + t));
764
+ else {
765
+ const o = n - i;
766
+ r.set(e.pendingBuffer.subarray(i, n)), r.set(e.pendingBuffer.subarray(0, t - o), o);
767
+ }
768
+ e.pendingReadOffset = (i + t) % n, e.pendingSamples -= t;
769
+ const s = Nt(r);
770
+ A(yt(lt({ Volume: s, Count: t }), e.senderId, { trackId: e.trackId }));
771
+ try {
772
+ const o = new AudioData({
773
+ format: "f32",
774
+ sampleRate: e.sampleRate,
775
+ numberOfFrames: t,
776
+ numberOfChannels: e.channels,
777
+ timestamp: e.timestampUs,
778
+ data: r.buffer
779
+ });
780
+ e.encoder.encode(o), o.close();
781
+ } catch (o) {
782
+ m(o, e.captureId);
771
783
  }
784
+ e.timestampUs += e.frameDurationUs;
785
+ }
772
786
  }
773
- function x(e, t) {
774
- e.stopped || t.length !== 0 && (e.pending.push(t), e.pendingSamples += t.length, N(e));
787
+ function v(e, t) {
788
+ if (e.stopped)
789
+ return;
790
+ const r = t.length;
791
+ if (r === 0)
792
+ return;
793
+ const n = e.pendingSamples + r;
794
+ if (n > e.pendingBuffer.length) {
795
+ const o = Math.max(n, e.pendingBuffer.length * 2), u = new Float32Array(o);
796
+ if (e.pendingSamples > 0) {
797
+ const c = e.pendingBuffer.length;
798
+ if (e.pendingReadOffset + e.pendingSamples <= c)
799
+ u.set(e.pendingBuffer.subarray(e.pendingReadOffset, e.pendingReadOffset + e.pendingSamples));
800
+ else {
801
+ const w = c - e.pendingReadOffset;
802
+ u.set(e.pendingBuffer.subarray(e.pendingReadOffset, c)), u.set(e.pendingBuffer.subarray(0, e.pendingSamples - w), w);
803
+ }
804
+ }
805
+ e.pendingBuffer = u, e.pendingReadOffset = 0, e.pendingWriteOffset = e.pendingSamples;
806
+ }
807
+ const i = e.pendingBuffer.length, s = Math.min(r, i - e.pendingWriteOffset);
808
+ e.pendingBuffer.set(t.subarray(0, s), e.pendingWriteOffset), s < r && e.pendingBuffer.set(t.subarray(s), 0), e.pendingWriteOffset = (e.pendingWriteOffset + r) % i, e.pendingSamples += r, M(e);
775
809
  }
776
- function xt(e) {
777
- const t = Math.max(8e3, Math.floor(e.options?.bitrate ?? 16e3)), r = new AudioEncoder({
778
- output: (i) => {
779
- const n = h.get(e.captureId);
780
- if (!n || n.stopped)
810
+ function Ct(e) {
811
+ const t = Math.max(8e3, Math.floor(e.options?.bitrate ?? Wt)), r = new AudioEncoder({
812
+ output: (n) => {
813
+ const i = l.get(e.captureId);
814
+ if (!i || i.stopped || !i.inSegment && !i.segmentEndPending)
781
815
  return;
782
- const s = new Uint8Array(i.byteLength);
783
- i.copyTo(s);
784
- const o = !n.sentFirst;
785
- o && (n.sentFirst = !0), A(
816
+ const s = n.byteLength;
817
+ i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer);
818
+ const o = i.encoderOutputBuffer.subarray(0, s), u = i.segmentStartPending;
819
+ u && (i.segmentStartPending = !1);
820
+ const c = i.segmentEndPending;
821
+ c && (i.segmentEndPending = !1, i.inSegment = !1), A(
786
822
  at(
787
823
  rt({
788
- Data: s,
789
- IsKey: i.type === "key",
790
- IsFirst: o,
791
- IsLast: !1,
792
- TimestampInUs: BigInt(Math.max(0, Math.round(i.timestamp ?? n.timestampUs))),
793
- DurationInUs: Math.max(0, Math.round(i.duration ?? n.frameDurationUs)),
824
+ Data: o,
825
+ IsKey: n.type === "key",
826
+ IsFirst: u,
827
+ IsLast: c,
828
+ TimestampInUs: BigInt(Math.max(0, Math.round(n.timestamp ?? i.timestampUs))),
829
+ DurationInUs: Math.max(0, Math.round(n.duration ?? i.frameDurationUs)),
794
830
  TotalDurationInUs: 0
795
831
  }),
796
- n.senderId,
797
- { trackId: n.trackId }
832
+ i.senderId,
833
+ { trackId: i.trackId }
798
834
  )
799
835
  );
800
836
  },
801
- error: (i) => {
802
- I(i, e.captureId);
837
+ error: (n) => {
838
+ m(n, e.captureId);
803
839
  }
804
840
  });
805
841
  return r.configure({
@@ -815,45 +851,52 @@ function xt(e) {
815
851
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
816
852
  }), r;
817
853
  }
818
- function Pt(e) {
819
- if (!l)
854
+ function Kt(e) {
855
+ if (!h)
820
856
  throw new Error("Audio capture worker missing send port");
821
- if (h.has(e.captureId))
857
+ if (l.has(e.captureId))
822
858
  return;
823
859
  if (typeof AudioEncoder > "u")
824
860
  throw new Error("AudioEncoder is not available in this browser");
825
- const t = Math.max(8e3, Math.floor(e.sampleRate)), r = Math.max(1, Math.floor(e.channels)), i = Math.max(10, Math.min(60, Math.floor(e.options?.frameDurationMs ?? 20))), n = Math.max(1, Math.floor(t * i / 1e3)), s = Math.max(1, Math.floor(n * 1e6 / t)), o = {
861
+ const t = Math.max(8e3, Math.floor(e.sampleRate)), r = Math.max(1, Math.floor(e.channels)), n = Math.max(1, Math.floor(t * Tt / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / t)), s = n * 4, o = {
826
862
  captureId: e.captureId,
827
863
  senderId: e.senderId,
828
864
  trackId: e.trackId,
829
865
  sampleRate: t,
830
866
  channels: r,
831
867
  frameSize: n,
832
- frameDurationUs: s,
868
+ frameDurationUs: i,
833
869
  timestampUs: 0,
834
870
  sentFirst: !1,
835
871
  stopped: !1,
836
872
  transport: e.transport,
837
873
  ringBuffer: null,
838
874
  ringTemp: null,
839
- pending: [],
875
+ pendingBuffer: new Float32Array(s),
876
+ pendingReadOffset: 0,
877
+ pendingWriteOffset: 0,
840
878
  pendingSamples: 0,
879
+ frameBuffer: new Float32Array(n),
880
+ encoderOutputBuffer: new Uint8Array(1024),
881
+ inSegment: !1,
882
+ segmentStartPending: !1,
883
+ segmentEndPending: !1,
841
884
  options: e.options
842
- }, d = xt(o), c = {
885
+ }, u = Ct(o), c = {
843
886
  ...o,
844
- encoder: d
887
+ encoder: u
845
888
  };
846
889
  if (e.transport === "sab") {
847
890
  if (!e.sharedArrayBuffer)
848
891
  throw new Error("Missing SharedArrayBuffer for sab transport");
849
- const g = new Vt(e.sharedArrayBuffer, Float32Array);
850
- c.ringBuffer = g, c.ringTemp = new Float32Array(Math.max(c.frameSize * 4, 4096)), vt();
892
+ const w = new Mt(e.sharedArrayBuffer, Float32Array);
893
+ c.ringBuffer = w, c.ringTemp = new Float32Array(Math.max(c.frameSize * 4, 4096)), vt();
851
894
  }
852
- h.set(e.captureId, c), A(
853
- Dt(
895
+ l.set(e.captureId, c), A(
896
+ Bt(
854
897
  Ut({
855
898
  Description: `mic:${e.captureId}`,
856
- Codec: S.Opus,
899
+ Codec: _.Opus,
857
900
  SampleRate: t,
858
901
  Channels: r,
859
902
  BitDepth: 32
@@ -861,14 +904,14 @@ function Pt(e) {
861
904
  e.senderId,
862
905
  { trackId: e.trackId }
863
906
  )
864
- ), M({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
907
+ ), O({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
865
908
  }
866
- async function P(e) {
867
- const t = h.get(e);
909
+ async function x(e) {
910
+ const t = l.get(e);
868
911
  if (t) {
869
- t.stopped = !0, h.delete(e);
912
+ t.stopped = !0, l.delete(e);
870
913
  try {
871
- N(t);
914
+ M(t);
872
915
  } catch {
873
916
  }
874
917
  try {
@@ -879,55 +922,71 @@ async function P(e) {
879
922
  t.encoder.close();
880
923
  } catch {
881
924
  }
882
- A(Mt(_t({}), t.senderId, { trackId: t.trackId })), M({ type: "stopped", captureId: e }), Nt();
925
+ A(Ot(St({}), t.senderId, { trackId: t.trackId })), O({ type: "stopped", captureId: e }), xt();
883
926
  }
884
927
  }
885
- function Ct() {
886
- for (const e of Array.from(h.keys()))
887
- P(e);
888
- if (l) {
928
+ function Ht(e) {
929
+ const t = l.get(e);
930
+ !t || t.stopped || (t.inSegment = !0, t.segmentStartPending = !0);
931
+ }
932
+ function jt(e) {
933
+ const t = l.get(e);
934
+ !t || t.stopped || !t.inSegment || (t.segmentEndPending = !0, M(t));
935
+ }
936
+ function zt() {
937
+ for (const e of Array.from(l.keys()))
938
+ x(e);
939
+ if (h) {
889
940
  try {
890
- l.close();
941
+ h.close();
891
942
  } catch {
892
943
  }
893
- l = null;
944
+ h = null;
894
945
  }
895
946
  }
896
947
  self.addEventListener("message", (e) => {
897
948
  const t = e.data;
898
949
  if (t.type === "attachSendPort") {
899
- if (l)
950
+ if (h)
900
951
  try {
901
- l.close();
952
+ h.close();
902
953
  } catch {
903
954
  }
904
- l = t.port;
955
+ h = t.port;
905
956
  try {
906
- l.start?.();
957
+ h.start?.();
907
958
  } catch {
908
959
  }
909
960
  return;
910
961
  }
911
962
  if (t.type === "start") {
912
963
  try {
913
- Pt(t);
964
+ Kt(t);
914
965
  } catch (r) {
915
- I(r, t.captureId);
966
+ m(r, t.captureId);
916
967
  }
917
968
  return;
918
969
  }
919
970
  if (t.type === "pcm") {
920
- const r = h.get(t.captureId);
971
+ const r = l.get(t.captureId);
921
972
  if (!r || r.stopped)
922
973
  return;
923
- x(r, t.pcm);
974
+ v(r, t.pcm);
924
975
  return;
925
976
  }
926
977
  if (t.type === "stop") {
927
- P(t.captureId).catch((r) => {
928
- Tt.warn(`Failed to stop audio capture: ${r}`), I(r, t.captureId);
978
+ x(t.captureId).catch((r) => {
979
+ Pt.warn(`Failed to stop audio capture: ${r}`), m(r, t.captureId);
929
980
  });
930
981
  return;
931
982
  }
932
- t.type === "dispose" && Ct();
983
+ if (t.type === "startSegment") {
984
+ Ht(t.captureId);
985
+ return;
986
+ }
987
+ if (t.type === "endSegment") {
988
+ jt(t.captureId);
989
+ return;
990
+ }
991
+ t.type === "dispose" && zt();
933
992
  });