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