@ikonai/sdk 0.0.39 → 0.0.41
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-Bnqb8-xb.js → audio-capture-worker-BZ6P8AHQ.js} +64 -70
- package/assets/{audio-playback-worker-CXmAFv0O.js → audio-playback-worker-DU7j77Kb.js} +4 -2
- package/assets/{index-C-9F_--I.js → index-7lK3WfPs.js} +40 -96
- package/assets/{index-C3ZAK5YF.js → index-k5wFN_NP.js} +24 -76
- package/assets/libopus-BEPFPIM_.js +139 -0
- package/client/ikon-client-config.d.ts +3 -3
- package/index.js +57 -57
- package/media/ikon-audio-capture.d.ts +3 -3
- package/media/ikon-audio-playback.d.ts +2 -2
- package/media/ikon-video-playback.d.ts +2 -2
- package/package.json +1 -1
- package/assets/libopus-BBY7KH2-.js +0 -169
- package/assets/libopus-simd-CQXMVirP.js +0 -169
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
function
|
|
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,
|
|
3
|
-
u.setUint32(0,
|
|
4
|
-
let
|
|
5
|
-
for (let
|
|
6
|
-
u.setUint32(
|
|
1
|
+
function B(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, g = I + t.length, y = new Uint8Array(g), u = new DataView(y.buffer);
|
|
3
|
+
u.setUint32(0, g, !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 P = 27;
|
|
5
|
+
for (let S = 0; S < l.length; S++)
|
|
6
|
+
u.setUint32(P, l[S] >>> 0, !0), P += 4;
|
|
7
7
|
return y.set(t, I), y;
|
|
8
8
|
}
|
|
9
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,
|
|
10
|
+
const $ = 161, j = 162, A = new TextEncoder();
|
|
11
11
|
new TextDecoder("utf-8", { fatal: !0 });
|
|
12
12
|
class p {
|
|
13
13
|
constructor(t = 1) {
|
|
@@ -44,7 +44,7 @@ class p {
|
|
|
44
44
|
this.writeFixedField(t, 14, () => this.buffer.writeBytes(n));
|
|
45
45
|
}
|
|
46
46
|
writeStringField(t, r) {
|
|
47
|
-
const n =
|
|
47
|
+
const n = A.encode(r ?? "");
|
|
48
48
|
this.writeVariableField(t, 12, n);
|
|
49
49
|
}
|
|
50
50
|
writeBinaryField(t, r) {
|
|
@@ -63,7 +63,7 @@ class p {
|
|
|
63
63
|
this.writeVariableField(t, 9, s);
|
|
64
64
|
}
|
|
65
65
|
writeDictionaryField(t, r, n, i) {
|
|
66
|
-
const s = new
|
|
66
|
+
const s = new M(r, n);
|
|
67
67
|
i(s);
|
|
68
68
|
const a = s.finish();
|
|
69
69
|
this.writeVariableField(t, 10, a);
|
|
@@ -78,7 +78,7 @@ class p {
|
|
|
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(
|
|
81
|
+
this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(F(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
class O {
|
|
@@ -144,7 +144,7 @@ class O {
|
|
|
144
144
|
12
|
|
145
145
|
/* String */
|
|
146
146
|
), this.count++;
|
|
147
|
-
const r =
|
|
147
|
+
const r = A.encode(t ?? "");
|
|
148
148
|
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
|
|
149
149
|
}
|
|
150
150
|
writeBinary(t) {
|
|
@@ -178,21 +178,21 @@ class O {
|
|
|
178
178
|
10
|
|
179
179
|
/* Dict */
|
|
180
180
|
), this.count++;
|
|
181
|
-
const i = new
|
|
181
|
+
const i = new M(t, r);
|
|
182
182
|
n(i);
|
|
183
183
|
const s = i.finish();
|
|
184
184
|
this.payload.writeBytes(s);
|
|
185
185
|
}
|
|
186
186
|
finish() {
|
|
187
187
|
const t = new b();
|
|
188
|
-
return t.writeByte(
|
|
188
|
+
return t.writeByte(F(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
192
|
throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[t]}`);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
class
|
|
195
|
+
class M {
|
|
196
196
|
constructor(t, r) {
|
|
197
197
|
this.keyType = t, this.valueType = r, G(t);
|
|
198
198
|
}
|
|
@@ -210,7 +210,7 @@ class R {
|
|
|
210
210
|
if (this.entryOpen)
|
|
211
211
|
throw new Error("Dictionary entry not completed");
|
|
212
212
|
const t = new b();
|
|
213
|
-
return t.writeByte(
|
|
213
|
+
return t.writeByte(F(this.keyType)), t.writeByte(F(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
class Y {
|
|
@@ -277,7 +277,7 @@ class Y {
|
|
|
277
277
|
12
|
|
278
278
|
/* String */
|
|
279
279
|
);
|
|
280
|
-
const r =
|
|
280
|
+
const r = A.encode(t ?? "");
|
|
281
281
|
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
|
|
282
282
|
}
|
|
283
283
|
writeKeyBinary(t) {
|
|
@@ -355,7 +355,7 @@ class Y {
|
|
|
355
355
|
12
|
|
356
356
|
/* String */
|
|
357
357
|
);
|
|
358
|
-
const r =
|
|
358
|
+
const r = A.encode(t ?? "");
|
|
359
359
|
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
|
|
360
360
|
}
|
|
361
361
|
writeValueObject(t, r) {
|
|
@@ -383,7 +383,7 @@ class Y {
|
|
|
383
383
|
10
|
|
384
384
|
/* Dict */
|
|
385
385
|
);
|
|
386
|
-
const i = new
|
|
386
|
+
const i = new M(t, r);
|
|
387
387
|
n(i);
|
|
388
388
|
const s = i.finish();
|
|
389
389
|
this.payload.writeBytes(s), this.valueWritten = !0;
|
|
@@ -515,7 +515,7 @@ class b {
|
|
|
515
515
|
return Uint8Array.from(this.bytes);
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
function
|
|
518
|
+
function F(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;
|
|
@@ -530,7 +530,7 @@ function G(e) {
|
|
|
530
530
|
function k(e) {
|
|
531
531
|
return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
532
532
|
}
|
|
533
|
-
var
|
|
533
|
+
var R = /* @__PURE__ */ ((e) => (e[e.Unknown = 0] = "Unknown", e[e.Opus = 1] = "Opus", e[e.Mp3 = 2] = "Mp3", e[e.RawPcm16 = 3] = "RawPcm16", e))(R || {});
|
|
534
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
535
|
function at(e) {
|
|
536
536
|
const t = {};
|
|
@@ -548,7 +548,7 @@ function ct(e, t) {
|
|
|
548
548
|
}
|
|
549
549
|
function lt(e, t, r) {
|
|
550
550
|
const n = ut(e);
|
|
551
|
-
return
|
|
551
|
+
return B(J, n, C, t, r);
|
|
552
552
|
}
|
|
553
553
|
const x = 1, dt = 4194308, ht = 2079085407, ft = 3485914759;
|
|
554
554
|
function yt(e) {
|
|
@@ -567,26 +567,26 @@ function mt(e, t) {
|
|
|
567
567
|
}
|
|
568
568
|
function It(e, t, r) {
|
|
569
569
|
const n = wt(e);
|
|
570
|
-
return
|
|
570
|
+
return B(dt, n, x, t, r);
|
|
571
571
|
}
|
|
572
|
-
const N = 1,
|
|
572
|
+
const N = 1, gt = 4194305, Et = 1368629611, bt = 2431514951, Ut = 2914494629, At = 3284746250, Ft = 4101844078;
|
|
573
573
|
function Bt(e) {
|
|
574
574
|
const t = {};
|
|
575
|
-
return
|
|
576
|
-
}
|
|
577
|
-
function St(e) {
|
|
578
|
-
return e.Description = "", e.Codec = V.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
|
|
575
|
+
return Ot(t), e && Object.assign(t, e), t;
|
|
579
576
|
}
|
|
580
577
|
function Ot(e) {
|
|
578
|
+
return e.Description = "", e.Codec = R.Unknown, e.SampleRate = 0, e.Channels = 0, e.BitDepth = 0, e;
|
|
579
|
+
}
|
|
580
|
+
function Dt(e) {
|
|
581
581
|
const t = new p(N);
|
|
582
|
-
return
|
|
582
|
+
return St(e, t), t.finish();
|
|
583
583
|
}
|
|
584
|
-
function
|
|
585
|
-
t.writeStringField(
|
|
584
|
+
function St(e, t) {
|
|
585
|
+
t.writeStringField(Et, 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
587
|
function _t(e, t, r) {
|
|
588
|
-
const n =
|
|
589
|
-
return
|
|
588
|
+
const n = Dt(e);
|
|
589
|
+
return B(gt, n, N, t, r);
|
|
590
590
|
}
|
|
591
591
|
const v = 1, Mt = 4194306;
|
|
592
592
|
function Rt(e) {
|
|
@@ -598,7 +598,7 @@ function Vt(e) {
|
|
|
598
598
|
}
|
|
599
599
|
function Lt(e, t, r) {
|
|
600
600
|
const n = Vt();
|
|
601
|
-
return
|
|
601
|
+
return B(Mt, n, v, t, r);
|
|
602
602
|
}
|
|
603
603
|
class Tt {
|
|
604
604
|
static getStorageForCapacity(t, r) {
|
|
@@ -658,7 +658,7 @@ let Wt = 1;
|
|
|
658
658
|
function Pt(e, t) {
|
|
659
659
|
return `[${e}] ${t}`;
|
|
660
660
|
}
|
|
661
|
-
function
|
|
661
|
+
function U(e, t, r, n) {
|
|
662
662
|
if ((/* @__PURE__ */ new Date()).toISOString(), Wt <= e) {
|
|
663
663
|
const i = Pt(t, r);
|
|
664
664
|
switch (e) {
|
|
@@ -680,24 +680,23 @@ function A(e, t, r, n) {
|
|
|
680
680
|
function kt(e) {
|
|
681
681
|
return {
|
|
682
682
|
debug(t, ...r) {
|
|
683
|
-
|
|
683
|
+
U(0, e, t, r);
|
|
684
684
|
},
|
|
685
685
|
info(t, ...r) {
|
|
686
|
-
|
|
686
|
+
U(1, e, t, r);
|
|
687
687
|
},
|
|
688
688
|
warn(t, ...r) {
|
|
689
|
-
|
|
689
|
+
U(2, e, t, r);
|
|
690
690
|
},
|
|
691
691
|
error(t, ...r) {
|
|
692
|
-
|
|
692
|
+
U(3, e, t, r);
|
|
693
693
|
}
|
|
694
694
|
};
|
|
695
695
|
}
|
|
696
|
-
const Ct = 20,
|
|
696
|
+
const Ct = 20, V = 32e3, xt = 5, L = 8e3, _ = kt("AudioCaptureWorker");
|
|
697
697
|
class Nt {
|
|
698
698
|
encoder = null;
|
|
699
699
|
isReady = !1;
|
|
700
|
-
simdEnabled = !1;
|
|
701
700
|
sampleRate;
|
|
702
701
|
channels;
|
|
703
702
|
bitrate;
|
|
@@ -711,14 +710,14 @@ class Nt {
|
|
|
711
710
|
}
|
|
712
711
|
async initialize() {
|
|
713
712
|
try {
|
|
714
|
-
const { OpusEncoder: t, OPUS_APPLICATION_VOIP: r,
|
|
715
|
-
this.encoder = new t({
|
|
713
|
+
const { OpusEncoder: t, OPUS_APPLICATION_VOIP: r, getOpusModule: n } = await import("./index-7lK3WfPs.js");
|
|
714
|
+
await n(), this.encoder = new t({
|
|
716
715
|
sampleRate: this.sampleRate,
|
|
717
716
|
channels: this.channels,
|
|
718
717
|
bitrate: this.bitrate,
|
|
719
718
|
application: r,
|
|
720
719
|
complexity: xt
|
|
721
|
-
}),
|
|
720
|
+
}), await this.encoder.ready, this.isReady = !0;
|
|
722
721
|
} catch (t) {
|
|
723
722
|
this.onError(t instanceof Error ? t : new Error(String(t)));
|
|
724
723
|
}
|
|
@@ -748,18 +747,15 @@ class Nt {
|
|
|
748
747
|
}
|
|
749
748
|
this.encoder = null, this.isReady = !1;
|
|
750
749
|
}
|
|
751
|
-
isSimdEnabled() {
|
|
752
|
-
return this.simdEnabled;
|
|
753
|
-
}
|
|
754
750
|
getBitrate() {
|
|
755
751
|
return this.bitrate;
|
|
756
752
|
}
|
|
757
753
|
}
|
|
758
|
-
const
|
|
754
|
+
const T = (e) => self.postMessage(e);
|
|
759
755
|
let f = null;
|
|
760
756
|
function m(e, t) {
|
|
761
757
|
const r = e instanceof Error ? e : new Error(String(e));
|
|
762
|
-
|
|
758
|
+
T({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
|
|
763
759
|
}
|
|
764
760
|
function vt(e) {
|
|
765
761
|
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
@@ -779,9 +775,9 @@ function Kt(e) {
|
|
|
779
775
|
return t / e.length;
|
|
780
776
|
}
|
|
781
777
|
const d = /* @__PURE__ */ new Map();
|
|
782
|
-
let
|
|
778
|
+
let E = null;
|
|
783
779
|
function zt() {
|
|
784
|
-
|
|
780
|
+
E === null && (E = self.setInterval(() => {
|
|
785
781
|
for (const e of d.values())
|
|
786
782
|
if (!(e.transport !== "sab" || !e.ringBuffer || !e.ringTemp || e.stopped))
|
|
787
783
|
try {
|
|
@@ -795,7 +791,7 @@ function zt() {
|
|
|
795
791
|
}, 10));
|
|
796
792
|
}
|
|
797
793
|
function Ht() {
|
|
798
|
-
if (
|
|
794
|
+
if (E === null)
|
|
799
795
|
return;
|
|
800
796
|
let e = !1;
|
|
801
797
|
for (const t of d.values())
|
|
@@ -805,13 +801,13 @@ function Ht() {
|
|
|
805
801
|
}
|
|
806
802
|
if (!e) {
|
|
807
803
|
try {
|
|
808
|
-
self.clearInterval(
|
|
804
|
+
self.clearInterval(E);
|
|
809
805
|
} catch {
|
|
810
806
|
}
|
|
811
|
-
|
|
807
|
+
E = null;
|
|
812
808
|
}
|
|
813
809
|
}
|
|
814
|
-
function
|
|
810
|
+
function W(e) {
|
|
815
811
|
if (e.stopped)
|
|
816
812
|
return;
|
|
817
813
|
if (!e.inSegment) {
|
|
@@ -871,7 +867,7 @@ function K(e, t) {
|
|
|
871
867
|
e.pendingBuffer = c, e.pendingReadOffset = 0, e.pendingWriteOffset = e.pendingSamples;
|
|
872
868
|
}
|
|
873
869
|
const i = e.pendingBuffer.length, s = Math.min(r, i - e.pendingWriteOffset);
|
|
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,
|
|
870
|
+
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, W(e);
|
|
875
871
|
}
|
|
876
872
|
function z(e, t, r, n, i = !0) {
|
|
877
873
|
const s = d.get(e.captureId);
|
|
@@ -899,7 +895,7 @@ function z(e, t, r, n, i = !0) {
|
|
|
899
895
|
);
|
|
900
896
|
}
|
|
901
897
|
function $t(e) {
|
|
902
|
-
const t = Math.max(
|
|
898
|
+
const t = Math.max(L, Math.floor(e.options?.bitrate ?? V)), r = new AudioEncoder({
|
|
903
899
|
output: (n) => {
|
|
904
900
|
const i = d.get(e.captureId);
|
|
905
901
|
if (!i)
|
|
@@ -931,7 +927,7 @@ function $t(e) {
|
|
|
931
927
|
}), r;
|
|
932
928
|
}
|
|
933
929
|
function jt(e) {
|
|
934
|
-
const t = Math.max(
|
|
930
|
+
const t = Math.max(L, Math.floor(e.options?.bitrate ?? V));
|
|
935
931
|
return new Nt({
|
|
936
932
|
sampleRate: e.sampleRate,
|
|
937
933
|
channels: e.channels,
|
|
@@ -990,17 +986,15 @@ async function qt(e) {
|
|
|
990
986
|
options: e.options
|
|
991
987
|
}, l = (e.options?.preferWebCodecs ?? !0) && await Yt();
|
|
992
988
|
let h, I = !1;
|
|
993
|
-
const
|
|
989
|
+
const g = Math.max(L, Math.floor(e.options?.bitrate ?? V));
|
|
994
990
|
if (l)
|
|
995
|
-
h = $t(a),
|
|
996
|
-
`Audio capture started: encoder=WebCodecs, sampleRate=${t}Hz, channels=${r}, bitrate=${
|
|
991
|
+
h = $t(a), _.info(
|
|
992
|
+
`Audio capture started: encoder=WebCodecs, sampleRate=${t}Hz, channels=${r}, bitrate=${g}bps`
|
|
997
993
|
);
|
|
998
994
|
else {
|
|
999
995
|
const u = jt(a);
|
|
1000
|
-
await u.initialize(), h = u, I = !0
|
|
1001
|
-
|
|
1002
|
-
M.info(
|
|
1003
|
-
`Audio capture started: encoder=WASM Opus (${U}), sampleRate=${t}Hz, channels=${r}, bitrate=${E}bps`
|
|
996
|
+
await u.initialize(), h = u, I = !0, _.info(
|
|
997
|
+
`Audio capture started: encoder=WASM Opus, sampleRate=${t}Hz, channels=${r}, bitrate=${g}bps`
|
|
1004
998
|
);
|
|
1005
999
|
}
|
|
1006
1000
|
const y = {
|
|
@@ -1018,7 +1012,7 @@ async function qt(e) {
|
|
|
1018
1012
|
_t(
|
|
1019
1013
|
Bt({
|
|
1020
1014
|
Description: `mic:${e.captureId}`,
|
|
1021
|
-
Codec:
|
|
1015
|
+
Codec: R.Opus,
|
|
1022
1016
|
SampleRate: t,
|
|
1023
1017
|
Channels: r,
|
|
1024
1018
|
BitDepth: 32
|
|
@@ -1026,14 +1020,14 @@ async function qt(e) {
|
|
|
1026
1020
|
e.senderId,
|
|
1027
1021
|
{ trackId: e.trackId }
|
|
1028
1022
|
)
|
|
1029
|
-
),
|
|
1023
|
+
), T({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
|
|
1030
1024
|
}
|
|
1031
1025
|
async function H(e) {
|
|
1032
1026
|
const t = d.get(e);
|
|
1033
1027
|
if (t) {
|
|
1034
1028
|
t.stopped = !0, d.delete(e);
|
|
1035
1029
|
try {
|
|
1036
|
-
|
|
1030
|
+
W(t);
|
|
1037
1031
|
} catch {
|
|
1038
1032
|
}
|
|
1039
1033
|
try {
|
|
@@ -1044,7 +1038,7 @@ async function H(e) {
|
|
|
1044
1038
|
t.encoder.close();
|
|
1045
1039
|
} catch {
|
|
1046
1040
|
}
|
|
1047
|
-
D(Lt(Rt({}), t.senderId, { trackId: t.trackId })),
|
|
1041
|
+
D(Lt(Rt({}), t.senderId, { trackId: t.trackId })), T({ type: "stopped", captureId: e }), Ht();
|
|
1048
1042
|
}
|
|
1049
1043
|
}
|
|
1050
1044
|
function Gt(e) {
|
|
@@ -1053,7 +1047,7 @@ function Gt(e) {
|
|
|
1053
1047
|
}
|
|
1054
1048
|
function Jt(e) {
|
|
1055
1049
|
const t = d.get(e);
|
|
1056
|
-
!t || t.stopped || !t.inSegment || (t.segmentEndPending = !0,
|
|
1050
|
+
!t || t.stopped || !t.inSegment || (t.segmentEndPending = !0, W(t));
|
|
1057
1051
|
}
|
|
1058
1052
|
function Xt() {
|
|
1059
1053
|
for (const e of Array.from(d.keys()))
|
|
@@ -1096,7 +1090,7 @@ self.addEventListener("message", (e) => {
|
|
|
1096
1090
|
}
|
|
1097
1091
|
if (t.type === "stop") {
|
|
1098
1092
|
H(t.captureId).catch((r) => {
|
|
1099
|
-
|
|
1093
|
+
_.warn(`Failed to stop audio capture: ${r}`), m(r, t.captureId);
|
|
1100
1094
|
});
|
|
1101
1095
|
return;
|
|
1102
1096
|
}
|
|
@@ -984,8 +984,10 @@ class _e extends X {
|
|
|
984
984
|
decoderSampleRate = 48e3;
|
|
985
985
|
pendingChunks = [];
|
|
986
986
|
async initialise(e, r) {
|
|
987
|
-
const { OpusDecoder: s } = await import("./index-
|
|
988
|
-
|
|
987
|
+
const { OpusDecoder: s, getOpusModule: n } = await import("./index-k5wFN_NP.js");
|
|
988
|
+
await n();
|
|
989
|
+
const i = [8e3, 12e3, 16e3, 24e3, 48e3].reduce((o, _) => Math.abs(_ - r) < Math.abs(o - r) ? _ : o);
|
|
990
|
+
this.decoderSampleRate = i, this.decoder = new s({ channels: e, sampleRate: this.decoderSampleRate }), await this.decoder.ready, this.isReady = !0, this.flushPendingChunks();
|
|
989
991
|
}
|
|
990
992
|
flushPendingChunks() {
|
|
991
993
|
if (!this.isReady || !this.decoder) {
|
|
@@ -1,69 +1,14 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
115,
|
|
6
|
-
109,
|
|
7
|
-
// magic
|
|
8
|
-
1,
|
|
9
|
-
0,
|
|
10
|
-
0,
|
|
11
|
-
0,
|
|
12
|
-
// version
|
|
13
|
-
1,
|
|
14
|
-
5,
|
|
15
|
-
1,
|
|
16
|
-
96,
|
|
17
|
-
0,
|
|
18
|
-
1,
|
|
19
|
-
123,
|
|
20
|
-
// type section: () -> v128
|
|
21
|
-
3,
|
|
22
|
-
2,
|
|
23
|
-
1,
|
|
24
|
-
0,
|
|
25
|
-
// function section
|
|
26
|
-
10,
|
|
27
|
-
10,
|
|
28
|
-
1,
|
|
29
|
-
8,
|
|
30
|
-
0,
|
|
31
|
-
// code section start
|
|
32
|
-
65,
|
|
33
|
-
0,
|
|
34
|
-
// i32.const 0
|
|
35
|
-
253,
|
|
36
|
-
15,
|
|
37
|
-
// v128.load (SIMD)
|
|
38
|
-
253,
|
|
39
|
-
98,
|
|
40
|
-
// i32x4.extract_lane 0
|
|
41
|
-
11
|
|
42
|
-
// end
|
|
43
|
-
]);
|
|
44
|
-
async function d() {
|
|
45
|
-
try {
|
|
46
|
-
return WebAssembly.validate(h);
|
|
47
|
-
} catch {
|
|
48
|
-
return !1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async function m() {
|
|
52
|
-
return s || (n || (n = (async () => {
|
|
53
|
-
const r = await d();
|
|
54
|
-
let t;
|
|
55
|
-
r ? t = (await import("./libopus-simd-CQXMVirP.js")).default : t = (await import("./libopus-BBY7KH2-.js")).default;
|
|
56
|
-
const i = r ? "../wasm/libopus-simd.wasm" : "../wasm/libopus.wasm";
|
|
1
|
+
let o = null, s = null;
|
|
2
|
+
async function a() {
|
|
3
|
+
return s || (o || (o = (async () => {
|
|
4
|
+
const t = (await import("./libopus-BEPFPIM_.js")).default;
|
|
57
5
|
return s = await t({
|
|
58
|
-
locateFile: (e) => e.endsWith(".wasm") ? new URL(
|
|
6
|
+
locateFile: (e) => e.endsWith(".wasm") ? new URL("../wasm/libopus.wasm", import.meta.url).href : e
|
|
59
7
|
}), s;
|
|
60
|
-
})()),
|
|
61
|
-
}
|
|
62
|
-
async function f() {
|
|
63
|
-
return d();
|
|
8
|
+
})()), o);
|
|
64
9
|
}
|
|
65
|
-
const
|
|
66
|
-
class
|
|
10
|
+
const d = 2048, l = 4002, u = 4010, m = 4028, h = 4e3, n = 2880;
|
|
11
|
+
class _ {
|
|
67
12
|
module = null;
|
|
68
13
|
encoder = 0;
|
|
69
14
|
channels;
|
|
@@ -75,27 +20,27 @@ class P {
|
|
|
75
20
|
outputPtr = 0;
|
|
76
21
|
ready;
|
|
77
22
|
constructor(t) {
|
|
78
|
-
this.channels = t.channels, this.sampleRate = t.sampleRate, this.bitrate = t.bitrate ?? 32e3, this.application = t.application ??
|
|
23
|
+
this.channels = t.channels, this.sampleRate = t.sampleRate, this.bitrate = t.bitrate ?? 32e3, this.application = t.application ?? d, this.ready = this.initialize(t);
|
|
79
24
|
}
|
|
80
25
|
async initialize(t) {
|
|
81
|
-
this.module = await
|
|
82
|
-
const
|
|
26
|
+
this.module = await a();
|
|
27
|
+
const e = this.module._malloc(4);
|
|
83
28
|
this.encoder = this.module._opus_encoder_create(
|
|
84
29
|
this.sampleRate,
|
|
85
30
|
this.channels,
|
|
86
31
|
this.application,
|
|
87
|
-
|
|
32
|
+
e
|
|
88
33
|
);
|
|
89
|
-
const
|
|
90
|
-
if (this.module._free(
|
|
91
|
-
throw new Error(`opus_encoder_create failed with error code ${
|
|
92
|
-
this.setEncoderCtl(
|
|
34
|
+
const i = new DataView(this.module.HEAPU8.buffer).getInt32(e, !0);
|
|
35
|
+
if (this.module._free(e), i !== 0)
|
|
36
|
+
throw new Error(`opus_encoder_create failed with error code ${i}`);
|
|
37
|
+
this.setEncoderCtl(l, this.bitrate), t.complexity !== void 0 && this.setEncoderCtl(u, t.complexity), this.inputPtr = this.module._malloc(n * this.channels * 4), this.outputPtr = this.module._malloc(h);
|
|
93
38
|
}
|
|
94
|
-
setEncoderCtl(t,
|
|
39
|
+
setEncoderCtl(t, e) {
|
|
95
40
|
if (!this.module || !this.encoder)
|
|
96
41
|
return;
|
|
97
|
-
const
|
|
98
|
-
new DataView(this.module.HEAPU8.buffer).setInt32(
|
|
42
|
+
const i = this.module._malloc(4);
|
|
43
|
+
new DataView(this.module.HEAPU8.buffer).setInt32(i, e, !0), this.module._opus_encoder_ctl(this.encoder, t, i), this.module._free(i);
|
|
99
44
|
}
|
|
100
45
|
/**
|
|
101
46
|
* Encode PCM float samples to Opus.
|
|
@@ -110,21 +55,21 @@ class P {
|
|
|
110
55
|
encode(t) {
|
|
111
56
|
if (!this.module || !this.encoder)
|
|
112
57
|
throw new Error("Encoder not initialized");
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
throw new Error(`Frame size too large: ${
|
|
116
|
-
const
|
|
117
|
-
this.module.HEAPF32.set(t,
|
|
118
|
-
const
|
|
58
|
+
const e = t.length / this.channels;
|
|
59
|
+
if (e > n)
|
|
60
|
+
throw new Error(`Frame size too large: ${e} > ${n} samples`);
|
|
61
|
+
const i = this.inputPtr / 4;
|
|
62
|
+
this.module.HEAPF32.set(t, i);
|
|
63
|
+
const r = this.module._opus_encode_float(
|
|
119
64
|
this.encoder,
|
|
120
65
|
this.inputPtr,
|
|
121
|
-
|
|
66
|
+
e,
|
|
122
67
|
this.outputPtr,
|
|
123
|
-
|
|
68
|
+
h
|
|
124
69
|
);
|
|
125
|
-
if (
|
|
126
|
-
throw new Error(`opus_encode_float failed with error code ${
|
|
127
|
-
return new Uint8Array(this.module.HEAPU8.buffer, this.outputPtr,
|
|
70
|
+
if (r < 0)
|
|
71
|
+
throw new Error(`opus_encode_float failed with error code ${r}`);
|
|
72
|
+
return new Uint8Array(this.module.HEAPU8.buffer, this.outputPtr, r);
|
|
128
73
|
}
|
|
129
74
|
/**
|
|
130
75
|
* Encode and copy the result (when caller needs ownership).
|
|
@@ -138,21 +83,21 @@ class P {
|
|
|
138
83
|
* Call this when there's a discontinuity in the audio stream.
|
|
139
84
|
*/
|
|
140
85
|
reset() {
|
|
141
|
-
this.module && this.encoder && this.module._opus_encoder_ctl(this.encoder,
|
|
86
|
+
this.module && this.encoder && this.module._opus_encoder_ctl(this.encoder, m);
|
|
142
87
|
}
|
|
143
88
|
/**
|
|
144
89
|
* Set the encoder bitrate.
|
|
145
90
|
* @param bitrate - Target bitrate in bits per second
|
|
146
91
|
*/
|
|
147
92
|
setBitrate(t) {
|
|
148
|
-
this.setEncoderCtl(
|
|
93
|
+
this.setEncoderCtl(l, t);
|
|
149
94
|
}
|
|
150
95
|
/**
|
|
151
96
|
* Set the encoder complexity (0-10, higher = better quality but more CPU).
|
|
152
97
|
* @param complexity - Complexity value (0-10)
|
|
153
98
|
*/
|
|
154
99
|
setComplexity(t) {
|
|
155
|
-
this.setEncoderCtl(
|
|
100
|
+
this.setEncoderCtl(u, t);
|
|
156
101
|
}
|
|
157
102
|
/**
|
|
158
103
|
* Get the number of channels this encoder was created with.
|
|
@@ -175,12 +120,11 @@ class P {
|
|
|
175
120
|
}
|
|
176
121
|
}
|
|
177
122
|
export {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
f as isSimdSupported
|
|
123
|
+
h as MAX_PACKET_SIZE,
|
|
124
|
+
d as OPUS_APPLICATION_VOIP,
|
|
125
|
+
m as OPUS_RESET_STATE,
|
|
126
|
+
l as OPUS_SET_BITRATE_REQUEST,
|
|
127
|
+
u as OPUS_SET_COMPLEXITY_REQUEST,
|
|
128
|
+
_ as OpusEncoder,
|
|
129
|
+
a as getOpusModule
|
|
186
130
|
};
|