@ikonai/sdk 0.0.34 → 0.0.37

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 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
- let L = 27;
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
- }
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
- const C = 161, K = 162, E = new TextEncoder();
1
+ function S(e, t, r, n, i) {
2
+ const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, c = i?.flags ?? 0, l = i?.targetIds ?? [], h = i?.payloadType ?? 8, I = 27 + l.length * 4, E = I + t.length, y = new Uint8Array(E), u = new DataView(y.buffer);
3
+ u.setUint32(0, E, !0), u.setUint32(4, e >>> 0, !0), u.setUint32(8, n >>> 0, !0), u.setUint32(12, s >>> 0, !0), u.setUint32(16, a >>> 0, !0), u.setUint32(20, l.length >>> 0, !0), u.setUint8(24, r & 255), u.setUint8(25, h & 255), u.setUint8(26, c & 255);
4
+ let U = 27;
5
+ for (let _ = 0; _ < l.length; _++)
6
+ u.setUint32(U, l[_] >>> 0, !0), U += 4;
7
+ return y.set(t, I), y;
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 || {});
10
+ const $ = 161, j = 162, F = new TextEncoder();
11
11
  new TextDecoder("utf-8", { fatal: !0 });
12
- class f {
12
+ class p {
13
13
  constructor(t = 1) {
14
- this.version = t, this.buffer.writeByte(C), this.buffer.writeVarUInt(t >>> 0);
14
+ this.version = t, this.buffer.writeByte($), this.buffer.writeVarUInt(t >>> 0);
15
15
  }
16
- buffer = new I();
16
+ buffer = new b();
17
17
  closed = !1;
18
18
  cached;
19
19
  writeInt32Field(t, r) {
@@ -38,38 +38,38 @@ class f {
38
38
  this.writeFixedField(t, 2, () => this.buffer.writeByte(r ? 1 : 0));
39
39
  }
40
40
  writeGuidField(t, r) {
41
- const n = r instanceof a ? r.asBytes() : r;
41
+ const n = r instanceof o ? r.asBytes() : r;
42
42
  if (n.length !== 16)
43
43
  throw new Error("Guid payload must be 16 bytes");
44
44
  this.writeFixedField(t, 14, () => this.buffer.writeBytes(n));
45
45
  }
46
46
  writeStringField(t, r) {
47
- const n = E.encode(r ?? "");
47
+ const n = F.encode(r ?? "");
48
48
  this.writeVariableField(t, 12, n);
49
49
  }
50
50
  writeBinaryField(t, r) {
51
51
  this.writeVariableField(t, 13, r);
52
52
  }
53
53
  writeObjectField(t, r, n) {
54
- const i = new f(r);
54
+ const i = new p(r);
55
55
  n(i);
56
56
  const s = i.finish();
57
57
  this.writeVariableField(t, 11, s);
58
58
  }
59
59
  writeArrayField(t, r, n) {
60
- const i = new b(r);
60
+ const i = new O(r);
61
61
  n(i);
62
62
  const s = i.finish();
63
63
  this.writeVariableField(t, 9, s);
64
64
  }
65
65
  writeDictionaryField(t, r, n, i) {
66
- const s = new S(r, n);
66
+ const s = new R(r, n);
67
67
  i(s);
68
- const o = s.finish();
69
- this.writeVariableField(t, 10, o);
68
+ const a = s.finish();
69
+ this.writeVariableField(t, 10, a);
70
70
  }
71
71
  finish() {
72
- return this.closed || (this.buffer.writeByte(K), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
72
+ return this.closed || (this.buffer.writeByte(j), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
73
73
  }
74
74
  writeFixedField(t, r, n) {
75
75
  this.writeFieldHeader(t, r, 0), n();
@@ -78,14 +78,14 @@ class f {
78
78
  this.writeFieldHeader(t, r, n.length), this.buffer.writeBytes(n);
79
79
  }
80
80
  writeFieldHeader(t, r, n) {
81
- this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(U(r)), j(r) && this.buffer.writeVarUInt(n >>> 0);
81
+ this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(B(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
82
82
  }
83
83
  }
84
- class b {
84
+ class O {
85
85
  constructor(t) {
86
86
  this.elementType = t;
87
87
  }
88
- payload = new I();
88
+ payload = new b();
89
89
  count = 0;
90
90
  writeInt32(t) {
91
91
  this.ensureElementType(
@@ -134,7 +134,7 @@ class b {
134
134
  14
135
135
  /* Guid */
136
136
  ), this.count++;
137
- const r = t instanceof a ? t.asBytes() : t;
137
+ const r = t instanceof o ? t.asBytes() : t;
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 b {
144
144
  12
145
145
  /* String */
146
146
  ), this.count++;
147
- const r = E.encode(t ?? "");
147
+ const r = F.encode(t ?? "");
148
148
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
149
149
  }
150
150
  writeBinary(t) {
@@ -158,7 +158,7 @@ class b {
158
158
  11
159
159
  /* Object */
160
160
  ), this.count++;
161
- const n = new f(t);
161
+ const n = new p(t);
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 b {
168
168
  9
169
169
  /* Array */
170
170
  ), this.count++;
171
- const n = new b(t);
171
+ const n = new O(t);
172
172
  r(n);
173
173
  const i = n.finish();
174
174
  this.payload.writeBytes(i);
@@ -178,42 +178,42 @@ class b {
178
178
  10
179
179
  /* Dict */
180
180
  ), this.count++;
181
- const i = new S(t, r);
181
+ const i = new R(t, r);
182
182
  n(i);
183
183
  const s = i.finish();
184
184
  this.payload.writeBytes(s);
185
185
  }
186
186
  finish() {
187
- const t = new I();
188
- return t.writeByte(U(this.elementType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
187
+ const t = new b();
188
+ return t.writeByte(B(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 ${y[this.elementType]}, expected ${y[t]}`);
192
+ throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[t]}`);
193
193
  }
194
194
  }
195
- class S {
195
+ class R {
196
196
  constructor(t, r) {
197
- this.keyType = t, this.valueType = r, z(t);
197
+ this.keyType = t, this.valueType = r, G(t);
198
198
  }
199
- payload = new I();
199
+ payload = new b();
200
200
  count = 0;
201
201
  entryOpen = !1;
202
202
  beginEntry() {
203
203
  if (this.entryOpen)
204
204
  throw new Error("Previous dictionary entry not completed");
205
- return this.count++, this.entryOpen = !0, new H(this.keyType, this.valueType, this.payload, () => {
205
+ return this.count++, this.entryOpen = !0, new Y(this.keyType, this.valueType, this.payload, () => {
206
206
  this.entryOpen = !1;
207
207
  });
208
208
  }
209
209
  finish() {
210
210
  if (this.entryOpen)
211
211
  throw new Error("Dictionary entry not completed");
212
- const 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();
212
+ const t = new b();
213
+ return t.writeByte(B(this.keyType)), t.writeByte(B(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
214
214
  }
215
215
  }
216
- class H {
216
+ class Y {
217
217
  constructor(t, r, n, i) {
218
218
  this.keyType = t, this.valueType = r, this.payload = n, this.onComplete = i;
219
219
  }
@@ -267,7 +267,7 @@ class H {
267
267
  14
268
268
  /* Guid */
269
269
  );
270
- const r = t instanceof a ? t.asBytes() : t;
270
+ const r = t instanceof o ? t.asBytes() : t;
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 H {
277
277
  12
278
278
  /* String */
279
279
  );
280
- const r = E.encode(t ?? "");
280
+ const r = F.encode(t ?? "");
281
281
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
282
282
  }
283
283
  writeKeyBinary(t) {
@@ -333,7 +333,7 @@ class H {
333
333
  14
334
334
  /* Guid */
335
335
  );
336
- const r = t instanceof a ? t.asBytes() : t;
336
+ const r = t instanceof o ? t.asBytes() : t;
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 H {
355
355
  12
356
356
  /* String */
357
357
  );
358
- const r = E.encode(t ?? "");
358
+ const r = F.encode(t ?? "");
359
359
  this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
360
360
  }
361
361
  writeValueObject(t, r) {
@@ -363,7 +363,7 @@ class H {
363
363
  11
364
364
  /* Object */
365
365
  );
366
- const n = new f(t);
366
+ const n = new p(t);
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 H {
373
373
  9
374
374
  /* Array */
375
375
  );
376
- const n = new b(t);
376
+ const n = new O(t);
377
377
  r(n);
378
378
  const i = n.finish();
379
379
  this.payload.writeBytes(i), this.valueWritten = !0;
@@ -383,7 +383,7 @@ class H {
383
383
  10
384
384
  /* Dict */
385
385
  );
386
- const i = new S(t, r);
386
+ const i = new R(t, r);
387
387
  n(i);
388
388
  const s = i.finish();
389
389
  this.payload.writeBytes(s), this.valueWritten = !0;
@@ -397,14 +397,14 @@ class H {
397
397
  }
398
398
  ensureKeyType(t) {
399
399
  if (this.keyType !== t)
400
- throw new Error(`Dictionary key type is ${y[this.keyType]}, expected ${y[t]}`);
400
+ throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[t]}`);
401
401
  }
402
402
  ensureValueType(t) {
403
403
  if (this.valueType !== t)
404
- throw new Error(`Dictionary value type is ${y[this.valueType]}, expected ${y[t]}`);
404
+ throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[t]}`);
405
405
  }
406
406
  }
407
- class a {
407
+ class o {
408
408
  constructor(t) {
409
409
  this.bytes = t;
410
410
  }
@@ -414,19 +414,19 @@ 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 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);
417
+ const n = new Uint8Array(16), i = o.parseHexSlice(r, 0, 8), s = o.parseHexSlice(r, 8, 4), a = o.parseHexSlice(r, 12, 4);
418
+ o.writeUInt32LE(n, 0, i), o.writeUInt16LE(n, 4, s), o.writeUInt16LE(n, 6, a);
419
+ for (let c = 0; c < 8; c++)
420
+ n[8 + c] = o.parseHexSlice(r, 16 + c * 2, 2);
421
+ return new o(n);
422
422
  }
423
423
  static fromBytes(t) {
424
424
  if (t.length !== 16)
425
425
  throw new Error("Guid byte array must be 16 bytes");
426
- return new a(Uint8Array.from(t));
426
+ return new o(Uint8Array.from(t));
427
427
  }
428
428
  static createZero() {
429
- return new a(new Uint8Array(16));
429
+ return new o(new Uint8Array(16));
430
430
  }
431
431
  static createRandom() {
432
432
  const t = new Uint8Array(16), r = globalThis.crypto;
@@ -435,16 +435,16 @@ class a {
435
435
  else
436
436
  for (let n = 0; n < t.length; n++)
437
437
  t[n] = Math.floor(Math.random() * 256);
438
- return t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, new a(t);
438
+ return t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, new o(t);
439
439
  }
440
440
  toString() {
441
441
  const t = this.bytes;
442
442
  return [
443
- a.toHex(a.readUInt32LE(t, 0), 8),
444
- a.toHex(a.readUInt16LE(t, 4), 4),
445
- a.toHex(a.readUInt16LE(t, 6), 4),
446
- T(t.subarray(8, 10)),
447
- T(t.subarray(10, 16))
443
+ o.toHex(o.readUInt32LE(t, 0), 8),
444
+ o.toHex(o.readUInt16LE(t, 4), 4),
445
+ o.toHex(o.readUInt16LE(t, 6), 4),
446
+ k(t.subarray(8, 10)),
447
+ k(t.subarray(10, 16))
448
448
  ].join("-");
449
449
  }
450
450
  asBytes() {
@@ -474,7 +474,7 @@ class a {
474
474
  return (t >>> 0).toString(16).padStart(r, "0");
475
475
  }
476
476
  }
477
- class I {
477
+ class b {
478
478
  bytes = [];
479
479
  writeByte(t) {
480
480
  this.bytes.push(t & 255);
@@ -515,92 +515,92 @@ class I {
515
515
  return Uint8Array.from(this.bytes);
516
516
  }
517
517
  }
518
- function U(e, t = 0) {
518
+ function B(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 j(e) {
523
+ function q(e) {
524
524
  return e === 12 || e === 13 || e === 9 || e === 11 || e === 10;
525
525
  }
526
- function z(e) {
526
+ function G(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 T(e) {
530
+ function k(e) {
531
531
  return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
532
532
  }
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
- function rt(e) {
533
+ var V = /* @__PURE__ */ ((e) => (e[e.Unknown = 0] = "Unknown", e[e.Opus = 1] = "Opus", e[e.Mp3 = 2] = "Mp3", e[e.RawPcm16 = 3] = "RawPcm16", e))(V || {});
534
+ const C = 1, J = 4194307, X = 271275304, Z = 668699606, Q = 945580544, tt = 1594075008, et = 2079085407, rt = 2541432218, nt = 2986785889, it = 3105403172, st = 4017217601;
535
+ function at(e) {
536
536
  const t = {};
537
- return nt(t), e && Object.assign(t, e), t;
537
+ return ot(t), e && Object.assign(t, e), t;
538
538
  }
539
- function nt(e) {
539
+ function ot(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 it(e) {
543
- const t = new f(W);
544
- return st(e, t), t.finish();
542
+ function ut(e) {
543
+ const t = new p(C);
544
+ return ct(e, t), t.finish();
545
545
  }
546
- function st(e, t) {
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);
546
+ function ct(e, t) {
547
+ t.writeUInt64Field(X, e.TimestampInUs), t.writeUInt32Field(Z, e.TotalDurationInUs >>> 0), t.writeInt32Field(Q, e.VolumeSampleCount | 0), t.writeBoolField(tt, e.IsFirst), t.writeFloat32Field(et, e.Volume), t.writeUInt32Field(rt, e.DurationInUs >>> 0), t.writeBinaryField(nt, e.Data), t.writeBoolField(it, e.IsKey), t.writeBoolField(st, e.IsLast);
548
548
  }
549
- function at(e, t, r) {
550
- const n = it(e);
551
- return F($, n, W, t, r);
549
+ function lt(e, t, r) {
550
+ const n = ut(e);
551
+ return S(J, n, C, t, r);
552
552
  }
553
- const P = 1, ot = 4194308, ut = 2079085407, ct = 3485914759;
554
- function lt(e) {
553
+ const x = 1, dt = 4194308, ht = 2079085407, ft = 3485914759;
554
+ function yt(e) {
555
555
  const t = {};
556
- return dt(t), e && Object.assign(t, e), t;
556
+ return pt(t), e && Object.assign(t, e), t;
557
557
  }
558
- function dt(e) {
558
+ function pt(e) {
559
559
  return e.Volume = 0, e.Count = 0, e;
560
560
  }
561
- function ht(e) {
562
- const t = new f(P);
563
- return ft(e, t), t.finish();
561
+ function wt(e) {
562
+ const t = new p(x);
563
+ return mt(e, t), t.finish();
564
564
  }
565
- function ft(e, t) {
566
- t.writeFloat32Field(ut, e.Volume), t.writeInt32Field(ct, e.Count | 0);
565
+ function mt(e, t) {
566
+ t.writeFloat32Field(ht, e.Volume), t.writeInt32Field(ft, e.Count | 0);
567
567
  }
568
- function yt(e, t, r) {
569
- const n = ht(e);
570
- return F(ot, n, P, t, r);
568
+ function It(e, t, r) {
569
+ const n = wt(e);
570
+ return S(dt, n, x, t, r);
571
571
  }
572
- const k = 1, wt = 4194305, pt = 1368629611, It = 2431514951, mt = 2914494629, gt = 3284746250, Et = 4101844078;
573
- function Ut(e) {
572
+ const N = 1, Et = 4194305, gt = 1368629611, bt = 2431514951, Ut = 2914494629, At = 3284746250, Ft = 4101844078;
573
+ function Bt(e) {
574
574
  const t = {};
575
- return Ft(t), e && Object.assign(t, e), t;
575
+ return St(t), e && Object.assign(t, e), t;
576
576
  }
577
- function Ft(e) {
578
- return e.Description = "", e.Codec = _.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
577
+ function St(e) {
578
+ return e.Description = "", e.Codec = V.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
579
579
  }
580
- function bt(e) {
581
- const t = new f(k);
582
- return At(e, t), t.finish();
580
+ function Ot(e) {
581
+ const t = new p(N);
582
+ return Dt(e, t), t.finish();
583
583
  }
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);
584
+ function Dt(e, t) {
585
+ t.writeStringField(gt, e.Description), t.writeInt32Field(bt, e.Channels | 0), t.writeInt32Field(Ut, e.BitDepth | 0), t.writeInt32Field(At, e.Codec), t.writeInt32Field(Ft, e.SampleRate | 0);
586
586
  }
587
- function Bt(e, t, r) {
588
- const n = bt(e);
589
- return F(wt, n, k, t, r);
587
+ function _t(e, t, r) {
588
+ const n = Ot(e);
589
+ return S(Et, n, N, t, r);
590
590
  }
591
- const N = 1, Dt = 4194306;
592
- function St(e) {
591
+ const v = 1, Mt = 4194306;
592
+ function Rt(e) {
593
593
  const t = {};
594
594
  return e && Object.assign(t, e), t;
595
595
  }
596
- function _t(e) {
597
- return new f(N).finish();
596
+ function Vt(e) {
597
+ return new p(v).finish();
598
598
  }
599
- function Ot(e, t, r) {
600
- const n = _t();
601
- return F(Dt, n, N, t, r);
599
+ function Lt(e, t, r) {
600
+ const n = Vt();
601
+ return S(Mt, n, v, t, r);
602
602
  }
603
- class Mt {
603
+ class Tt {
604
604
  static getStorageForCapacity(t, r) {
605
605
  const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * t;
606
606
  return new SharedArrayBuffer(n + i);
@@ -654,13 +654,13 @@ class Mt {
654
654
  return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
655
655
  }
656
656
  }
657
- let Vt = 1;
658
- function Rt(e, t) {
657
+ let Wt = 1;
658
+ function Pt(e, t) {
659
659
  return `[${e}] ${t}`;
660
660
  }
661
- function g(e, t, r, n) {
662
- if ((/* @__PURE__ */ new Date()).toISOString(), Vt <= e) {
663
- const i = Rt(t, r);
661
+ function A(e, t, r, n) {
662
+ if ((/* @__PURE__ */ new Date()).toISOString(), Wt <= e) {
663
+ const i = Pt(t, r);
664
664
  switch (e) {
665
665
  case 0:
666
666
  console.debug(i, ...n);
@@ -677,38 +677,100 @@ function g(e, t, r, n) {
677
677
  }
678
678
  }
679
679
  }
680
- function Lt(e) {
680
+ function kt(e) {
681
681
  return {
682
682
  debug(t, ...r) {
683
- g(0, e, t, r);
683
+ A(0, e, t, r);
684
684
  },
685
685
  info(t, ...r) {
686
- g(1, e, t, r);
686
+ A(1, e, t, r);
687
687
  },
688
688
  warn(t, ...r) {
689
- g(2, e, t, r);
689
+ A(2, e, t, r);
690
690
  },
691
691
  error(t, ...r) {
692
- g(3, e, t, r);
692
+ A(3, e, t, r);
693
693
  }
694
694
  };
695
695
  }
696
- const Tt = 20, Wt = 32e3, Pt = Lt("AudioCaptureWorker"), O = (e) => self.postMessage(e);
697
- let h = null;
696
+ const Ct = 20, L = 32e3, xt = 5, T = 8e3, M = kt("AudioCaptureWorker");
697
+ class Nt {
698
+ encoder = null;
699
+ isReady = !1;
700
+ simdEnabled = !1;
701
+ sampleRate;
702
+ channels;
703
+ bitrate;
704
+ frameSize;
705
+ onOutput;
706
+ onError;
707
+ timestampUs = 0;
708
+ frameDurationUs;
709
+ constructor(t) {
710
+ this.sampleRate = t.sampleRate, this.channels = t.channels, this.bitrate = t.bitrate, this.frameSize = t.frameSize, this.frameDurationUs = Math.floor(this.frameSize * 1e6 / this.sampleRate), this.onOutput = t.onOutput, this.onError = t.onError;
711
+ }
712
+ async initialize() {
713
+ try {
714
+ const { OpusEncoder: t, OPUS_APPLICATION_VOIP: r, isSimdSupported: n } = await import("./index-C-9F_--I.js"), i = await n();
715
+ this.encoder = new t({
716
+ sampleRate: this.sampleRate,
717
+ channels: this.channels,
718
+ bitrate: this.bitrate,
719
+ application: r,
720
+ complexity: xt
721
+ }), this.simdEnabled = i, await this.encoder.ready, this.isReady = !0;
722
+ } catch (t) {
723
+ this.onError(t instanceof Error ? t : new Error(String(t)));
724
+ }
725
+ }
726
+ encode(t) {
727
+ if (!(!this.isReady || !this.encoder))
728
+ try {
729
+ let r;
730
+ if (t instanceof Float32Array)
731
+ r = t;
732
+ else {
733
+ const i = t.numberOfFrames, s = t.numberOfChannels;
734
+ r = new Float32Array(i * s), t.copyTo(r, { planeIndex: 0, format: "f32" }), t.close();
735
+ }
736
+ const n = this.encoder.encodeAndCopy(r);
737
+ this.onOutput(n, this.timestampUs, this.frameDurationUs), this.timestampUs += this.frameDurationUs;
738
+ } catch (r) {
739
+ this.onError(r instanceof Error ? r : new Error(String(r)));
740
+ }
741
+ }
742
+ async flush() {
743
+ }
744
+ close() {
745
+ try {
746
+ this.encoder?.destroy();
747
+ } catch {
748
+ }
749
+ this.encoder = null, this.isReady = !1;
750
+ }
751
+ isSimdEnabled() {
752
+ return this.simdEnabled;
753
+ }
754
+ getBitrate() {
755
+ return this.bitrate;
756
+ }
757
+ }
758
+ const W = (e) => self.postMessage(e);
759
+ let f = null;
698
760
  function m(e, t) {
699
761
  const r = e instanceof Error ? e : new Error(String(e));
700
- O({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
762
+ W({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
701
763
  }
702
- function kt(e) {
764
+ function vt(e) {
703
765
  return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
704
766
  }
705
- function A(e) {
706
- if (!h)
767
+ function D(e) {
768
+ if (!f)
707
769
  return;
708
- const t = kt(e);
709
- h.postMessage({ type: "send", message: t }, [t]);
770
+ const t = vt(e);
771
+ f.postMessage({ type: "send", message: t }, [t]);
710
772
  }
711
- function Nt(e) {
773
+ function Kt(e) {
712
774
  if (e.length === 0)
713
775
  return 0;
714
776
  let t = 0;
@@ -716,40 +778,40 @@ function Nt(e) {
716
778
  t += Math.abs(e[r] ?? 0);
717
779
  return t / e.length;
718
780
  }
719
- const l = /* @__PURE__ */ new Map();
720
- let p = null;
721
- function vt() {
722
- p === null && (p = self.setInterval(() => {
723
- for (const e of l.values())
781
+ const d = /* @__PURE__ */ new Map();
782
+ let g = null;
783
+ function zt() {
784
+ g === null && (g = self.setInterval(() => {
785
+ for (const e of d.values())
724
786
  if (!(e.transport !== "sab" || !e.ringBuffer || !e.ringTemp || e.stopped))
725
787
  try {
726
788
  const t = e.ringBuffer.pop(e.ringTemp);
727
789
  if (t <= 0)
728
790
  continue;
729
- v(e, e.ringTemp.subarray(0, t));
791
+ K(e, e.ringTemp.subarray(0, t));
730
792
  } catch (t) {
731
793
  m(t, e.captureId);
732
794
  }
733
795
  }, 10));
734
796
  }
735
- function xt() {
736
- if (p === null)
797
+ function Ht() {
798
+ if (g === null)
737
799
  return;
738
800
  let e = !1;
739
- for (const t of l.values())
801
+ for (const t of d.values())
740
802
  if (t.transport === "sab" && !t.stopped) {
741
803
  e = !0;
742
804
  break;
743
805
  }
744
806
  if (!e) {
745
807
  try {
746
- self.clearInterval(p);
808
+ self.clearInterval(g);
747
809
  } catch {
748
810
  }
749
- p = null;
811
+ g = null;
750
812
  }
751
813
  }
752
- function M(e) {
814
+ function P(e) {
753
815
  if (e.stopped)
754
816
  return;
755
817
  if (!e.inSegment) {
@@ -762,29 +824,33 @@ function M(e) {
762
824
  if (i + t <= n)
763
825
  r.set(e.pendingBuffer.subarray(i, i + t));
764
826
  else {
765
- const o = n - i;
766
- r.set(e.pendingBuffer.subarray(i, n)), r.set(e.pendingBuffer.subarray(0, t - o), o);
827
+ const a = n - i;
828
+ r.set(e.pendingBuffer.subarray(i, n)), r.set(e.pendingBuffer.subarray(0, t - a), a);
767
829
  }
768
830
  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 }));
831
+ const s = Kt(r);
832
+ D(It(yt({ Volume: s, Count: t }), e.senderId, { trackId: e.trackId }));
771
833
  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);
834
+ if (e.useWasmEncoder)
835
+ e.encoder.encode(r);
836
+ else {
837
+ const a = new AudioData({
838
+ format: "f32",
839
+ sampleRate: e.sampleRate,
840
+ numberOfFrames: t,
841
+ numberOfChannels: e.channels,
842
+ timestamp: e.timestampUs,
843
+ data: r.buffer
844
+ });
845
+ e.encoder.encode(a), a.close();
846
+ }
847
+ } catch (a) {
848
+ m(a, e.captureId);
783
849
  }
784
850
  e.timestampUs += e.frameDurationUs;
785
851
  }
786
852
  }
787
- function v(e, t) {
853
+ function K(e, t) {
788
854
  if (e.stopped)
789
855
  return;
790
856
  const r = t.length;
@@ -792,46 +858,59 @@ function v(e, t) {
792
858
  return;
793
859
  const n = e.pendingSamples + r;
794
860
  if (n > e.pendingBuffer.length) {
795
- const o = Math.max(n, e.pendingBuffer.length * 2), u = new Float32Array(o);
861
+ const a = Math.max(n, e.pendingBuffer.length * 2), c = new Float32Array(a);
796
862
  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));
863
+ const l = e.pendingBuffer.length;
864
+ if (e.pendingReadOffset + e.pendingSamples <= l)
865
+ c.set(e.pendingBuffer.subarray(e.pendingReadOffset, e.pendingReadOffset + e.pendingSamples));
800
866
  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);
867
+ const h = l - e.pendingReadOffset;
868
+ c.set(e.pendingBuffer.subarray(e.pendingReadOffset, l)), c.set(e.pendingBuffer.subarray(0, e.pendingSamples - h), h);
803
869
  }
804
870
  }
805
- e.pendingBuffer = u, e.pendingReadOffset = 0, e.pendingWriteOffset = e.pendingSamples;
871
+ e.pendingBuffer = c, e.pendingReadOffset = 0, e.pendingWriteOffset = e.pendingSamples;
806
872
  }
807
873
  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);
874
+ 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, P(e);
809
875
  }
810
- function Ct(e) {
811
- const t = Math.max(8e3, Math.floor(e.options?.bitrate ?? Wt)), r = new AudioEncoder({
876
+ function z(e, t, r, n, i = !0) {
877
+ const s = d.get(e.captureId);
878
+ if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
879
+ return;
880
+ const a = t.byteLength;
881
+ s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(t);
882
+ const c = s.encoderOutputBuffer.subarray(0, a), l = s.segmentStartPending;
883
+ l && (s.segmentStartPending = !1);
884
+ const h = s.segmentEndPending;
885
+ h && (s.segmentEndPending = !1, s.inSegment = !1), D(
886
+ lt(
887
+ at({
888
+ Data: c,
889
+ IsKey: i,
890
+ IsFirst: l,
891
+ IsLast: h,
892
+ TimestampInUs: BigInt(Math.max(0, Math.round(r))),
893
+ DurationInUs: Math.max(0, Math.round(n)),
894
+ TotalDurationInUs: 0
895
+ }),
896
+ s.senderId,
897
+ { trackId: s.trackId }
898
+ )
899
+ );
900
+ }
901
+ function $t(e) {
902
+ const t = Math.max(T, Math.floor(e.options?.bitrate ?? L)), r = new AudioEncoder({
812
903
  output: (n) => {
813
- const i = l.get(e.captureId);
814
- if (!i || i.stopped || !i.inSegment && !i.segmentEndPending)
904
+ const i = d.get(e.captureId);
905
+ if (!i)
815
906
  return;
816
907
  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(
822
- at(
823
- rt({
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)),
830
- TotalDurationInUs: 0
831
- }),
832
- i.senderId,
833
- { trackId: i.trackId }
834
- )
908
+ i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer), z(
909
+ i,
910
+ i.encoderOutputBuffer.subarray(0, s),
911
+ n.timestamp ?? i.timestampUs,
912
+ n.duration ?? i.frameDurationUs,
913
+ n.type === "key"
835
914
  );
836
915
  },
837
916
  error: (n) => {
@@ -851,14 +930,41 @@ function Ct(e) {
851
930
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
852
931
  }), r;
853
932
  }
854
- function Kt(e) {
855
- if (!h)
933
+ function jt(e) {
934
+ const t = Math.max(T, Math.floor(e.options?.bitrate ?? L));
935
+ return new Nt({
936
+ sampleRate: e.sampleRate,
937
+ channels: e.channels,
938
+ bitrate: t,
939
+ frameSize: e.frameSize,
940
+ onOutput: (r, n, i) => {
941
+ const s = d.get(e.captureId);
942
+ s && z(s, r, n, i, !0);
943
+ },
944
+ onError: (r) => {
945
+ m(r, e.captureId);
946
+ }
947
+ });
948
+ }
949
+ async function Yt() {
950
+ if (typeof AudioEncoder > "u")
951
+ return !1;
952
+ try {
953
+ return (await AudioEncoder.isConfigSupported({
954
+ codec: "opus",
955
+ numberOfChannels: 1,
956
+ sampleRate: 48e3
957
+ })).supported === !0;
958
+ } catch {
959
+ return !1;
960
+ }
961
+ }
962
+ async function qt(e) {
963
+ if (!f)
856
964
  throw new Error("Audio capture worker missing send port");
857
- if (l.has(e.captureId))
965
+ if (d.has(e.captureId))
858
966
  return;
859
- if (typeof AudioEncoder > "u")
860
- throw new Error("AudioEncoder is not available in this browser");
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 = {
967
+ const t = Math.max(8e3, Math.floor(e.sampleRate)), r = Math.max(1, Math.floor(e.channels)), n = Math.max(1, Math.floor(t * Ct / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / t)), s = n * 4, a = {
862
968
  captureId: e.captureId,
863
969
  senderId: e.senderId,
864
970
  trackId: e.trackId,
@@ -882,21 +988,37 @@ function Kt(e) {
882
988
  segmentStartPending: !1,
883
989
  segmentEndPending: !1,
884
990
  options: e.options
885
- }, u = Ct(o), c = {
886
- ...o,
887
- encoder: u
991
+ }, l = (e.options?.preferWebCodecs ?? !0) && await Yt();
992
+ let h, I = !1;
993
+ const E = Math.max(T, Math.floor(e.options?.bitrate ?? L));
994
+ if (l)
995
+ h = $t(a), M.info(
996
+ `Audio capture started: encoder=WebCodecs, sampleRate=${t}Hz, channels=${r}, bitrate=${E}bps`
997
+ );
998
+ else {
999
+ const u = jt(a);
1000
+ await u.initialize(), h = u, I = !0;
1001
+ const U = u.isSimdEnabled() ? "SIMD" : "non-SIMD";
1002
+ M.info(
1003
+ `Audio capture started: encoder=WASM Opus (${U}), sampleRate=${t}Hz, channels=${r}, bitrate=${E}bps`
1004
+ );
1005
+ }
1006
+ const y = {
1007
+ ...a,
1008
+ encoder: h,
1009
+ useWasmEncoder: I
888
1010
  };
889
1011
  if (e.transport === "sab") {
890
1012
  if (!e.sharedArrayBuffer)
891
1013
  throw new Error("Missing SharedArrayBuffer for sab transport");
892
- const w = new Mt(e.sharedArrayBuffer, Float32Array);
893
- c.ringBuffer = w, c.ringTemp = new Float32Array(Math.max(c.frameSize * 4, 4096)), vt();
1014
+ const u = new Tt(e.sharedArrayBuffer, Float32Array);
1015
+ y.ringBuffer = u, y.ringTemp = new Float32Array(Math.max(y.frameSize * 4, 4096)), zt();
894
1016
  }
895
- l.set(e.captureId, c), A(
896
- Bt(
897
- Ut({
1017
+ d.set(e.captureId, y), D(
1018
+ _t(
1019
+ Bt({
898
1020
  Description: `mic:${e.captureId}`,
899
- Codec: _.Opus,
1021
+ Codec: V.Opus,
900
1022
  SampleRate: t,
901
1023
  Channels: r,
902
1024
  BitDepth: 32
@@ -904,14 +1026,14 @@ function Kt(e) {
904
1026
  e.senderId,
905
1027
  { trackId: e.trackId }
906
1028
  )
907
- ), O({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
1029
+ ), W({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
908
1030
  }
909
- async function x(e) {
910
- const t = l.get(e);
1031
+ async function H(e) {
1032
+ const t = d.get(e);
911
1033
  if (t) {
912
- t.stopped = !0, l.delete(e);
1034
+ t.stopped = !0, d.delete(e);
913
1035
  try {
914
- M(t);
1036
+ P(t);
915
1037
  } catch {
916
1038
  }
917
1039
  try {
@@ -922,71 +1044,69 @@ async function x(e) {
922
1044
  t.encoder.close();
923
1045
  } catch {
924
1046
  }
925
- A(Ot(St({}), t.senderId, { trackId: t.trackId })), O({ type: "stopped", captureId: e }), xt();
1047
+ D(Lt(Rt({}), t.senderId, { trackId: t.trackId })), W({ type: "stopped", captureId: e }), Ht();
926
1048
  }
927
1049
  }
928
- function Ht(e) {
929
- const t = l.get(e);
1050
+ function Gt(e) {
1051
+ const t = d.get(e);
930
1052
  !t || t.stopped || (t.inSegment = !0, t.segmentStartPending = !0);
931
1053
  }
932
- function jt(e) {
933
- const t = l.get(e);
934
- !t || t.stopped || !t.inSegment || (t.segmentEndPending = !0, M(t));
1054
+ function Jt(e) {
1055
+ const t = d.get(e);
1056
+ !t || t.stopped || !t.inSegment || (t.segmentEndPending = !0, P(t));
935
1057
  }
936
- function zt() {
937
- for (const e of Array.from(l.keys()))
938
- x(e);
939
- if (h) {
1058
+ function Xt() {
1059
+ for (const e of Array.from(d.keys()))
1060
+ H(e);
1061
+ if (f) {
940
1062
  try {
941
- h.close();
1063
+ f.close();
942
1064
  } catch {
943
1065
  }
944
- h = null;
1066
+ f = null;
945
1067
  }
946
1068
  }
947
1069
  self.addEventListener("message", (e) => {
948
1070
  const t = e.data;
949
1071
  if (t.type === "attachSendPort") {
950
- if (h)
1072
+ if (f)
951
1073
  try {
952
- h.close();
1074
+ f.close();
953
1075
  } catch {
954
1076
  }
955
- h = t.port;
1077
+ f = t.port;
956
1078
  try {
957
- h.start?.();
1079
+ f.start?.();
958
1080
  } catch {
959
1081
  }
960
1082
  return;
961
1083
  }
962
1084
  if (t.type === "start") {
963
- try {
964
- Kt(t);
965
- } catch (r) {
1085
+ qt(t).catch((r) => {
966
1086
  m(r, t.captureId);
967
- }
1087
+ });
968
1088
  return;
969
1089
  }
970
1090
  if (t.type === "pcm") {
971
- const r = l.get(t.captureId);
1091
+ const r = d.get(t.captureId);
972
1092
  if (!r || r.stopped)
973
1093
  return;
974
- v(r, t.pcm);
1094
+ K(r, t.pcm);
975
1095
  return;
976
1096
  }
977
1097
  if (t.type === "stop") {
978
- x(t.captureId).catch((r) => {
979
- Pt.warn(`Failed to stop audio capture: ${r}`), m(r, t.captureId);
1098
+ H(t.captureId).catch((r) => {
1099
+ M.warn(`Failed to stop audio capture: ${r}`), m(r, t.captureId);
980
1100
  });
981
1101
  return;
982
1102
  }
983
1103
  if (t.type === "startSegment") {
984
- Ht(t.captureId);
1104
+ Gt(t.captureId);
985
1105
  return;
986
1106
  }
987
1107
  if (t.type === "endSegment") {
988
- jt(t.captureId);
1108
+ Jt(t.captureId);
989
1109
  return;
990
1110
  }
991
- t.type === "dispose" && zt();
1111
+ t.type === "dispose" && Xt();
992
1112
  });