@ikonai/sdk 1.0.13 → 1.0.15
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-Ca53cEkv.js → audio-capture-worker-DuKZS6HJ.js} +386 -266
- package/assets/{audio-playback-worker-D0LDYB5W.js → audio-playback-worker-Bhbw6iLB.js} +13 -13
- package/assets/{protocol-worker-CH5R2dxZ.js → protocol-worker-BBmGiA1Z.js} +28 -28
- package/assets/video-capture-worker-Dbh2k3pJ.js +1117 -0
- package/assets/video-playback-worker-CoAD7jCH.js +995 -0
- package/client/ikon-client.d.ts +15 -0
- package/functions/browser-functions.d.ts +27 -0
- package/functions/media-capture-functions.d.ts +1 -0
- package/index.d.ts +1 -1
- package/index.js +2551 -1688
- package/media/capabilities.d.ts +9 -0
- package/media/ikon-audio-capture.d.ts +201 -1
- package/media/ikon-video-capture.d.ts +3 -0
- package/media/index.d.ts +2 -2
- package/media/ring-buffer.d.ts +1 -1
- package/package.json +1 -1
- package/utils/debug-mode.d.ts +1 -0
- package/worker/video-playback-worker.d.ts +3 -0
- package/assets/video-capture-worker-Odc_mLEl.js +0 -967
- package/assets/video-playback-worker-OwSrJCnC.js +0 -943
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
function
|
|
2
|
-
const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0,
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
for (let
|
|
6
|
-
|
|
7
|
-
return
|
|
1
|
+
function L(t, e, r, n, i) {
|
|
2
|
+
const s = i?.trackId ?? 0, a = i?.sequenceId ?? 0, c = i?.flags ?? 0, l = i?.targetIds ?? [], o = i?.payloadType ?? 8, d = 27 + l.length * 4, y = d + e.length, p = new Uint8Array(y), h = new DataView(p.buffer);
|
|
3
|
+
h.setUint32(0, y, !0), h.setUint32(4, t >>> 0, !0), h.setUint32(8, n >>> 0, !0), h.setUint32(12, s >>> 0, !0), h.setUint32(16, a >>> 0, !0), h.setUint32(20, l.length >>> 0, !0), h.setUint8(24, r & 255), h.setUint8(25, o & 255), h.setUint8(26, c & 255);
|
|
4
|
+
let N = 27;
|
|
5
|
+
for (let V = 0; V < l.length; V++)
|
|
6
|
+
h.setUint32(N, l[V] >>> 0, !0), N += 4;
|
|
7
|
+
return p.set(e, d), p;
|
|
8
8
|
}
|
|
9
|
-
var
|
|
10
|
-
const
|
|
9
|
+
var w = /* @__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))(w || {});
|
|
10
|
+
const q = 161, G = 162, U = new TextEncoder();
|
|
11
11
|
new TextDecoder("utf-8", { fatal: !0 });
|
|
12
|
-
class
|
|
12
|
+
class S {
|
|
13
13
|
constructor(e = 1) {
|
|
14
|
-
this.version = e, this.buffer.writeByte(
|
|
14
|
+
this.version = e, this.buffer.writeByte(q), this.buffer.writeVarUInt(e >>> 0);
|
|
15
15
|
}
|
|
16
|
-
buffer = new
|
|
16
|
+
buffer = new g();
|
|
17
17
|
closed = !1;
|
|
18
18
|
cached;
|
|
19
19
|
writeInt32Field(e, r) {
|
|
@@ -38,38 +38,38 @@ class E {
|
|
|
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 u ? 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 = U.encode(r ?? "");
|
|
48
48
|
this.writeVariableField(e, 12, n);
|
|
49
49
|
}
|
|
50
50
|
writeBinaryField(e, r) {
|
|
51
51
|
this.writeVariableField(e, 13, r);
|
|
52
52
|
}
|
|
53
53
|
writeObjectField(e, r, n) {
|
|
54
|
-
const i = new
|
|
54
|
+
const i = new S(r);
|
|
55
55
|
n(i);
|
|
56
56
|
const s = i.finish();
|
|
57
57
|
this.writeVariableField(e, 11, s);
|
|
58
58
|
}
|
|
59
59
|
writeArrayField(e, r, n) {
|
|
60
|
-
const i = new
|
|
60
|
+
const i = new R(r);
|
|
61
61
|
n(i);
|
|
62
62
|
const s = i.finish();
|
|
63
63
|
this.writeVariableField(e, 9, s);
|
|
64
64
|
}
|
|
65
65
|
writeDictionaryField(e, r, n, i) {
|
|
66
|
-
const s = new
|
|
66
|
+
const s = new P(r, n);
|
|
67
67
|
i(s);
|
|
68
68
|
const a = s.finish();
|
|
69
69
|
this.writeVariableField(e, 10, a);
|
|
70
70
|
}
|
|
71
71
|
finish() {
|
|
72
|
-
return this.closed || (this.buffer.writeByte(
|
|
72
|
+
return this.closed || (this.buffer.writeByte(G), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
|
|
73
73
|
}
|
|
74
74
|
writeFixedField(e, r, n) {
|
|
75
75
|
this.writeFieldHeader(e, r, 0), n();
|
|
@@ -78,14 +78,14 @@ class E {
|
|
|
78
78
|
this.writeFieldHeader(e, r, n.length), this.buffer.writeBytes(n);
|
|
79
79
|
}
|
|
80
80
|
writeFieldHeader(e, r, n) {
|
|
81
|
-
this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(
|
|
81
|
+
this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(D(r)), J(r) && this.buffer.writeVarUInt(n >>> 0);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
class
|
|
84
|
+
class R {
|
|
85
85
|
constructor(e) {
|
|
86
86
|
this.elementType = e;
|
|
87
87
|
}
|
|
88
|
-
payload = new
|
|
88
|
+
payload = new g();
|
|
89
89
|
count = 0;
|
|
90
90
|
writeInt32(e) {
|
|
91
91
|
this.ensureElementType(
|
|
@@ -134,7 +134,7 @@ class U {
|
|
|
134
134
|
14
|
|
135
135
|
/* Guid */
|
|
136
136
|
), this.count++;
|
|
137
|
-
const r = e instanceof
|
|
137
|
+
const r = e instanceof u ? 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 U {
|
|
|
144
144
|
12
|
|
145
145
|
/* String */
|
|
146
146
|
), this.count++;
|
|
147
|
-
const r =
|
|
147
|
+
const r = U.encode(e ?? "");
|
|
148
148
|
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
|
|
149
149
|
}
|
|
150
150
|
writeBinary(e) {
|
|
@@ -158,7 +158,7 @@ class U {
|
|
|
158
158
|
11
|
|
159
159
|
/* Object */
|
|
160
160
|
), this.count++;
|
|
161
|
-
const n = new
|
|
161
|
+
const n = new S(e);
|
|
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 U {
|
|
|
168
168
|
9
|
|
169
169
|
/* Array */
|
|
170
170
|
), this.count++;
|
|
171
|
-
const n = new
|
|
171
|
+
const n = new R(e);
|
|
172
172
|
r(n);
|
|
173
173
|
const i = n.finish();
|
|
174
174
|
this.payload.writeBytes(i);
|
|
@@ -178,42 +178,42 @@ class U {
|
|
|
178
178
|
10
|
|
179
179
|
/* Dict */
|
|
180
180
|
), this.count++;
|
|
181
|
-
const i = new
|
|
181
|
+
const i = new P(e, r);
|
|
182
182
|
n(i);
|
|
183
183
|
const s = i.finish();
|
|
184
184
|
this.payload.writeBytes(s);
|
|
185
185
|
}
|
|
186
186
|
finish() {
|
|
187
|
-
const e = new
|
|
188
|
-
return e.writeByte(
|
|
187
|
+
const e = new g();
|
|
188
|
+
return e.writeByte(D(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
|
|
189
189
|
}
|
|
190
190
|
ensureElementType(e) {
|
|
191
191
|
if (this.elementType !== e)
|
|
192
|
-
throw new Error(`Array element type is ${
|
|
192
|
+
throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[e]}`);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
class
|
|
195
|
+
class P {
|
|
196
196
|
constructor(e, r) {
|
|
197
|
-
this.keyType = e, this.valueType = r,
|
|
197
|
+
this.keyType = e, this.valueType = r, X(e);
|
|
198
198
|
}
|
|
199
|
-
payload = new
|
|
199
|
+
payload = new g();
|
|
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
|
|
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 e = new
|
|
213
|
-
return e.writeByte(
|
|
212
|
+
const e = new g();
|
|
213
|
+
return e.writeByte(D(this.keyType)), e.writeByte(D(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
-
class
|
|
216
|
+
class Y {
|
|
217
217
|
constructor(e, r, n, i) {
|
|
218
218
|
this.keyType = e, this.valueType = r, this.payload = n, this.onComplete = i;
|
|
219
219
|
}
|
|
@@ -267,7 +267,7 @@ class j {
|
|
|
267
267
|
14
|
|
268
268
|
/* Guid */
|
|
269
269
|
);
|
|
270
|
-
const r = e instanceof
|
|
270
|
+
const r = e instanceof u ? 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 j {
|
|
|
277
277
|
12
|
|
278
278
|
/* String */
|
|
279
279
|
);
|
|
280
|
-
const r =
|
|
280
|
+
const r = U.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 j {
|
|
|
333
333
|
14
|
|
334
334
|
/* Guid */
|
|
335
335
|
);
|
|
336
|
-
const r = e instanceof
|
|
336
|
+
const r = e instanceof u ? 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 j {
|
|
|
355
355
|
12
|
|
356
356
|
/* String */
|
|
357
357
|
);
|
|
358
|
-
const r =
|
|
358
|
+
const r = U.encode(e ?? "");
|
|
359
359
|
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
|
|
360
360
|
}
|
|
361
361
|
writeValueObject(e, r) {
|
|
@@ -363,7 +363,7 @@ class j {
|
|
|
363
363
|
11
|
|
364
364
|
/* Object */
|
|
365
365
|
);
|
|
366
|
-
const n = new
|
|
366
|
+
const n = new S(e);
|
|
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 j {
|
|
|
373
373
|
9
|
|
374
374
|
/* Array */
|
|
375
375
|
);
|
|
376
|
-
const n = new
|
|
376
|
+
const n = new R(e);
|
|
377
377
|
r(n);
|
|
378
378
|
const i = n.finish();
|
|
379
379
|
this.payload.writeBytes(i), this.valueWritten = !0;
|
|
@@ -383,7 +383,7 @@ class j {
|
|
|
383
383
|
10
|
|
384
384
|
/* Dict */
|
|
385
385
|
);
|
|
386
|
-
const i = new
|
|
386
|
+
const i = new P(e, 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 j {
|
|
|
397
397
|
}
|
|
398
398
|
ensureKeyType(e) {
|
|
399
399
|
if (this.keyType !== e)
|
|
400
|
-
throw new Error(`Dictionary key type is ${
|
|
400
|
+
throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[e]}`);
|
|
401
401
|
}
|
|
402
402
|
ensureValueType(e) {
|
|
403
403
|
if (this.valueType !== e)
|
|
404
|
-
throw new Error(`Dictionary value type is ${
|
|
404
|
+
throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[e]}`);
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
-
class
|
|
407
|
+
class u {
|
|
408
408
|
constructor(e) {
|
|
409
409
|
this.bytes = e;
|
|
410
410
|
}
|
|
@@ -414,19 +414,19 @@ class o {
|
|
|
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
|
-
|
|
419
|
-
for (let
|
|
420
|
-
n[8 +
|
|
421
|
-
return new
|
|
417
|
+
const n = new Uint8Array(16), i = u.parseHexSlice(r, 0, 8), s = u.parseHexSlice(r, 8, 4), a = u.parseHexSlice(r, 12, 4);
|
|
418
|
+
u.writeUInt32LE(n, 0, i), u.writeUInt16LE(n, 4, s), u.writeUInt16LE(n, 6, a);
|
|
419
|
+
for (let c = 0; c < 8; c++)
|
|
420
|
+
n[8 + c] = u.parseHexSlice(r, 16 + c * 2, 2);
|
|
421
|
+
return new u(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 u(Uint8Array.from(e));
|
|
427
427
|
}
|
|
428
428
|
static createZero() {
|
|
429
|
-
return new
|
|
429
|
+
return new u(new Uint8Array(16));
|
|
430
430
|
}
|
|
431
431
|
static createRandom() {
|
|
432
432
|
const e = new Uint8Array(16), r = globalThis.crypto;
|
|
@@ -435,16 +435,16 @@ class o {
|
|
|
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 u(e);
|
|
439
439
|
}
|
|
440
440
|
toString() {
|
|
441
441
|
const e = this.bytes;
|
|
442
442
|
return [
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
443
|
+
u.toHex(u.readUInt32LE(e, 0), 8),
|
|
444
|
+
u.toHex(u.readUInt16LE(e, 4), 4),
|
|
445
|
+
u.toHex(u.readUInt16LE(e, 6), 4),
|
|
446
|
+
k(e.subarray(8, 10)),
|
|
447
|
+
k(e.subarray(10, 16))
|
|
448
448
|
].join("-");
|
|
449
449
|
}
|
|
450
450
|
asBytes() {
|
|
@@ -474,13 +474,13 @@ class o {
|
|
|
474
474
|
return (e >>> 0).toString(16).padStart(r, "0");
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
class
|
|
477
|
+
class g {
|
|
478
478
|
static INITIAL_CAPACITY = 256;
|
|
479
479
|
buffer;
|
|
480
480
|
dataView;
|
|
481
481
|
length = 0;
|
|
482
482
|
constructor() {
|
|
483
|
-
this.buffer = new Uint8Array(
|
|
483
|
+
this.buffer = new Uint8Array(g.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
|
|
484
484
|
}
|
|
485
485
|
ensureCapacity(e) {
|
|
486
486
|
const r = this.length + e;
|
|
@@ -526,101 +526,101 @@ class m {
|
|
|
526
526
|
return this.buffer.slice(0, this.length);
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
|
-
function
|
|
529
|
+
function D(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;
|
|
533
533
|
}
|
|
534
|
-
function
|
|
534
|
+
function J(t) {
|
|
535
535
|
return t === 12 || t === 13 || t === 9 || t === 11 || t === 10;
|
|
536
536
|
}
|
|
537
|
-
function
|
|
537
|
+
function X(t) {
|
|
538
538
|
if (t === 9 || t === 11 || t === 10 || t === 1)
|
|
539
539
|
throw new Error("Dictionary keys must be primitive Teleport types");
|
|
540
540
|
}
|
|
541
|
-
function
|
|
541
|
+
function k(t) {
|
|
542
542
|
return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
543
543
|
}
|
|
544
|
-
var
|
|
545
|
-
const
|
|
546
|
-
function
|
|
544
|
+
var W = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.Opus = 1] = "Opus", t[t.Mp3 = 2] = "Mp3", t[t.RawPcm16 = 3] = "RawPcm16", t))(W || {});
|
|
545
|
+
const z = 1, Z = 4194309, Q = 205938238, ee = 717315017, te = 1594075008, re = 2026534360, ne = 3409001585, ie = 3466650495, se = 4007456593, ae = 4017217601, oe = 4065417427, ce = 4086360332;
|
|
546
|
+
function ue(t) {
|
|
547
547
|
const e = {};
|
|
548
|
-
return
|
|
548
|
+
return le(e), t && Object.assign(e, t), e;
|
|
549
549
|
}
|
|
550
|
-
function
|
|
550
|
+
function le(t) {
|
|
551
551
|
return t.Samples = new Uint8Array(0), t.Epoch = 0, t.Sequence = 0, t.FrameSizeInInterleavedSamples = 0, t.TimeStampInInterleavedSamples = 0n, t.IsFirst = !1, t.IsLast = !1, t.AverageVolume = 0, t.AudioEventEstimatedDuration = 0, t.ShapeSetValues = void 0, t;
|
|
552
552
|
}
|
|
553
|
-
function
|
|
554
|
-
const e = new
|
|
555
|
-
return
|
|
553
|
+
function de(t) {
|
|
554
|
+
const e = new S(z);
|
|
555
|
+
return he(t, e), e.finish();
|
|
556
556
|
}
|
|
557
|
-
function
|
|
558
|
-
e.writeFloat32Field(
|
|
557
|
+
function he(t, e) {
|
|
558
|
+
e.writeFloat32Field(Q, t.AverageVolume);
|
|
559
559
|
const r = t.ShapeSetValues;
|
|
560
|
-
r != null && e.writeArrayField(
|
|
560
|
+
r != null && e.writeArrayField(ee, w.Object, (n) => {
|
|
561
561
|
for (const i of r)
|
|
562
|
-
n.writeObject(
|
|
563
|
-
|
|
562
|
+
n.writeObject(pe, (s) => {
|
|
563
|
+
Ie(i, s);
|
|
564
564
|
});
|
|
565
|
-
}), e.writeBoolField(
|
|
565
|
+
}), e.writeBoolField(te, t.IsFirst), e.writeUInt64Field(re, t.TimeStampInInterleavedSamples), e.writeBinaryField(ne, t.Samples), e.writeFloat32Field(ie, t.AudioEventEstimatedDuration), e.writeUInt32Field(se, t.FrameSizeInInterleavedSamples >>> 0), e.writeBoolField(ae, t.IsLast), e.writeUInt32Field(oe, t.Sequence >>> 0), e.writeUInt32Field(ce, t.Epoch >>> 0);
|
|
566
566
|
}
|
|
567
|
-
function
|
|
568
|
-
const n =
|
|
569
|
-
return
|
|
567
|
+
function fe(t, e, r) {
|
|
568
|
+
const n = de(t);
|
|
569
|
+
return L(Z, n, z, e, r);
|
|
570
570
|
}
|
|
571
|
-
const
|
|
572
|
-
function
|
|
573
|
-
e.writeUInt32Field(
|
|
571
|
+
const pe = 1, ye = 1154362099, we = 3974819915;
|
|
572
|
+
function Ie(t, e) {
|
|
573
|
+
e.writeUInt32Field(ye, t.SetId >>> 0), e.writeArrayField(we, w.Float32, (r) => {
|
|
574
574
|
for (const n of t.Values)
|
|
575
575
|
r.writeFloat32(n);
|
|
576
576
|
});
|
|
577
577
|
}
|
|
578
|
-
const
|
|
579
|
-
function
|
|
578
|
+
const H = 5, me = 4194305, Ee = 161083277, ge = 265814330, Se = 1368629611, Ae = 2431514951, be = 2745379226, _e = 3282782683, Fe = 3284746250, Ue = 4101844078;
|
|
579
|
+
function De(t) {
|
|
580
580
|
const e = {};
|
|
581
|
-
return
|
|
581
|
+
return Oe(e), t && Object.assign(e, t), e;
|
|
582
582
|
}
|
|
583
|
-
function
|
|
584
|
-
return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec =
|
|
583
|
+
function Oe(t) {
|
|
584
|
+
return t.StreamId = "", t.Description = "", t.SourceType = "", t.Codec = W.Unknown, t.CodecDetails = "", t.SampleRate = 0, t.Channels = 0, t.ShapeSets = void 0, t;
|
|
585
585
|
}
|
|
586
|
-
function
|
|
587
|
-
const e = new
|
|
588
|
-
return
|
|
586
|
+
function Be(t) {
|
|
587
|
+
const e = new S(H);
|
|
588
|
+
return Re(t, e), e.finish();
|
|
589
589
|
}
|
|
590
|
-
function
|
|
591
|
-
e.writeStringField(
|
|
590
|
+
function Re(t, e) {
|
|
591
|
+
e.writeStringField(Ee, t.StreamId);
|
|
592
592
|
const r = t.ShapeSets;
|
|
593
|
-
r != null && e.writeArrayField(
|
|
593
|
+
r != null && e.writeArrayField(ge, w.Object, (n) => {
|
|
594
594
|
for (const i of r)
|
|
595
|
-
n.writeObject(
|
|
596
|
-
|
|
595
|
+
n.writeObject(Te, (s) => {
|
|
596
|
+
We(i, s);
|
|
597
597
|
});
|
|
598
|
-
}), e.writeStringField(
|
|
598
|
+
}), e.writeStringField(Se, t.Description), e.writeInt32Field(Ae, t.Channels | 0), e.writeStringField(be, t.CodecDetails), e.writeStringField(_e, t.SourceType), e.writeInt32Field(Fe, t.Codec), e.writeInt32Field(Ue, t.SampleRate | 0);
|
|
599
599
|
}
|
|
600
|
-
function
|
|
601
|
-
const n =
|
|
602
|
-
return
|
|
600
|
+
function Me(t, e, r) {
|
|
601
|
+
const n = Be(t);
|
|
602
|
+
return L(me, n, H, e, r);
|
|
603
603
|
}
|
|
604
|
-
const
|
|
605
|
-
function
|
|
606
|
-
e.writeStringField(
|
|
604
|
+
const Te = 5, Ve = 1107713536, Le = 1154362099, Pe = 1185721362;
|
|
605
|
+
function We(t, e) {
|
|
606
|
+
e.writeStringField(Ve, t.Name), e.writeUInt32Field(Le, t.SetId >>> 0), e.writeArrayField(Pe, w.String, (r) => {
|
|
607
607
|
for (const n of t.ShapeNames)
|
|
608
608
|
r.writeString(n);
|
|
609
609
|
});
|
|
610
610
|
}
|
|
611
|
-
const
|
|
612
|
-
function
|
|
611
|
+
const K = 1, Ce = 4194306;
|
|
612
|
+
function ve(t) {
|
|
613
613
|
const e = {};
|
|
614
614
|
return t && Object.assign(e, t), e;
|
|
615
615
|
}
|
|
616
|
-
function
|
|
617
|
-
return new
|
|
616
|
+
function Ne(t) {
|
|
617
|
+
return new S(K).finish();
|
|
618
618
|
}
|
|
619
|
-
function
|
|
620
|
-
const n =
|
|
621
|
-
return
|
|
619
|
+
function ke(t, e, r) {
|
|
620
|
+
const n = Ne();
|
|
621
|
+
return L(Ce, n, K, e, r);
|
|
622
622
|
}
|
|
623
|
-
class
|
|
623
|
+
class xe {
|
|
624
624
|
static getStorageForCapacity(e, r) {
|
|
625
625
|
const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * e;
|
|
626
626
|
return new SharedArrayBuffer(n + i);
|
|
@@ -674,19 +674,19 @@ class ve {
|
|
|
674
674
|
return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
|
-
let
|
|
678
|
-
const
|
|
677
|
+
let ze = 1;
|
|
678
|
+
const He = /* @__PURE__ */ new Map(), Ke = {
|
|
679
679
|
0: "DEBUG",
|
|
680
680
|
1: "INFO",
|
|
681
681
|
2: "WARN",
|
|
682
682
|
3: "ERROR",
|
|
683
683
|
4: "NONE"
|
|
684
684
|
};
|
|
685
|
-
function
|
|
685
|
+
function $e(t, e) {
|
|
686
686
|
return `[${t}] ${e}`;
|
|
687
687
|
}
|
|
688
|
-
function
|
|
689
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(), s =
|
|
688
|
+
function _(t, e, r, n) {
|
|
689
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), s = Ke[t], a = {
|
|
690
690
|
timestamp: i,
|
|
691
691
|
level: t,
|
|
692
692
|
levelName: s,
|
|
@@ -694,50 +694,50 @@ function A(t, e, r, n) {
|
|
|
694
694
|
message: r,
|
|
695
695
|
args: n
|
|
696
696
|
};
|
|
697
|
-
for (const [
|
|
698
|
-
const
|
|
699
|
-
if (t >=
|
|
697
|
+
for (const [c, l] of He) {
|
|
698
|
+
const o = l?.minLevel ?? 2;
|
|
699
|
+
if (t >= o)
|
|
700
700
|
try {
|
|
701
|
-
|
|
701
|
+
c(a);
|
|
702
702
|
} catch {
|
|
703
703
|
}
|
|
704
704
|
}
|
|
705
|
-
if (
|
|
706
|
-
const
|
|
705
|
+
if (ze <= t) {
|
|
706
|
+
const c = $e(e, r);
|
|
707
707
|
switch (t) {
|
|
708
708
|
case 0:
|
|
709
|
-
console.debug(
|
|
709
|
+
console.debug(c, ...n);
|
|
710
710
|
break;
|
|
711
711
|
case 1:
|
|
712
|
-
console.info(
|
|
712
|
+
console.info(c, ...n);
|
|
713
713
|
break;
|
|
714
714
|
case 2:
|
|
715
|
-
console.warn(
|
|
715
|
+
console.warn(c, ...n);
|
|
716
716
|
break;
|
|
717
717
|
case 3:
|
|
718
|
-
console.error(
|
|
718
|
+
console.error(c, ...n);
|
|
719
719
|
break;
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
function
|
|
723
|
+
function je(t) {
|
|
724
724
|
return {
|
|
725
725
|
debug(e, ...r) {
|
|
726
|
-
|
|
726
|
+
_(0, t, e, r);
|
|
727
727
|
},
|
|
728
728
|
info(e, ...r) {
|
|
729
|
-
|
|
729
|
+
_(1, t, e, r);
|
|
730
730
|
},
|
|
731
731
|
warn(e, ...r) {
|
|
732
|
-
|
|
732
|
+
_(2, t, e, r);
|
|
733
733
|
},
|
|
734
734
|
error(e, ...r) {
|
|
735
|
-
|
|
735
|
+
_(3, t, e, r);
|
|
736
736
|
}
|
|
737
737
|
};
|
|
738
738
|
}
|
|
739
|
-
const
|
|
740
|
-
class
|
|
739
|
+
const qe = 20, b = 32e3, Ge = 5, M = 8e3, E = je("AudioCaptureWorker");
|
|
740
|
+
class $ {
|
|
741
741
|
encoder = null;
|
|
742
742
|
isReady = !1;
|
|
743
743
|
sampleRate;
|
|
@@ -759,7 +759,7 @@ class je {
|
|
|
759
759
|
channels: this.channels,
|
|
760
760
|
bitrate: this.bitrate,
|
|
761
761
|
application: r,
|
|
762
|
-
complexity:
|
|
762
|
+
complexity: Ge
|
|
763
763
|
}), await this.encoder.ready, this.isReady = !0;
|
|
764
764
|
} catch (e) {
|
|
765
765
|
this.onError(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -794,24 +794,24 @@ class je {
|
|
|
794
794
|
return this.bitrate;
|
|
795
795
|
}
|
|
796
796
|
}
|
|
797
|
-
const
|
|
798
|
-
let
|
|
799
|
-
function
|
|
797
|
+
const O = (t) => self.postMessage(t);
|
|
798
|
+
let m = null;
|
|
799
|
+
function I(t, e) {
|
|
800
800
|
const r = t instanceof Error ? t : new Error(String(t));
|
|
801
|
-
|
|
801
|
+
O({ type: "error", captureId: e, error: { name: r.name, message: r.message, stack: r.stack } });
|
|
802
802
|
}
|
|
803
|
-
function
|
|
803
|
+
function Ye(t) {
|
|
804
804
|
return t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.slice().buffer;
|
|
805
805
|
}
|
|
806
|
-
function
|
|
807
|
-
if (!
|
|
808
|
-
|
|
806
|
+
function C(t) {
|
|
807
|
+
if (!m) {
|
|
808
|
+
E.warn("Audio capture message dropped: sendPort not available");
|
|
809
809
|
return;
|
|
810
810
|
}
|
|
811
|
-
const e =
|
|
812
|
-
|
|
811
|
+
const e = Ye(t);
|
|
812
|
+
m.postMessage({ type: "send", message: e }, [e]);
|
|
813
813
|
}
|
|
814
|
-
function
|
|
814
|
+
function Je(t) {
|
|
815
815
|
if (t.length === 0)
|
|
816
816
|
return 0;
|
|
817
817
|
let e = 0;
|
|
@@ -819,41 +819,71 @@ function Ge(t) {
|
|
|
819
819
|
e += Math.abs(t[r] ?? 0);
|
|
820
820
|
return e / t.length;
|
|
821
821
|
}
|
|
822
|
-
const
|
|
823
|
-
let
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
|
|
828
|
-
try {
|
|
829
|
-
const e = t.ringBuffer.pop(t.ringTemp);
|
|
830
|
-
if (e <= 0)
|
|
831
|
-
continue;
|
|
832
|
-
W(t, t.ringTemp.subarray(0, e));
|
|
833
|
-
} catch (e) {
|
|
834
|
-
g(e, t.captureId);
|
|
835
|
-
}
|
|
836
|
-
}, 10));
|
|
822
|
+
const f = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
|
|
823
|
+
let A = null;
|
|
824
|
+
const x = 1;
|
|
825
|
+
function Xe() {
|
|
826
|
+
return typeof Atomics < "u" && typeof Atomics.waitAsync == "function";
|
|
837
827
|
}
|
|
838
|
-
function
|
|
839
|
-
if (
|
|
828
|
+
async function Ze(t) {
|
|
829
|
+
if (!t.ringBuffer || !t.ringTemp)
|
|
840
830
|
return;
|
|
841
|
-
|
|
842
|
-
for (
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
831
|
+
const e = t.ringBuffer, r = t.ringTemp;
|
|
832
|
+
for (; !t.stopped && t.transport === "sab"; ) {
|
|
833
|
+
try {
|
|
834
|
+
const n = e.pop(r);
|
|
835
|
+
n > 0 && T(t, r.subarray(0, n));
|
|
836
|
+
} catch (n) {
|
|
837
|
+
I(n, t.captureId);
|
|
846
838
|
}
|
|
847
|
-
if (!t) {
|
|
848
839
|
try {
|
|
849
|
-
|
|
840
|
+
const n = Atomics.load(e.readWrite, x), i = Atomics.waitAsync(e.readWrite, x, n, 100);
|
|
841
|
+
i.async && await i.value;
|
|
850
842
|
} catch {
|
|
843
|
+
await new Promise((n) => setTimeout(n, 10));
|
|
851
844
|
}
|
|
852
|
-
S = null;
|
|
853
845
|
}
|
|
854
846
|
}
|
|
855
|
-
function
|
|
856
|
-
|
|
847
|
+
function Qe() {
|
|
848
|
+
for (const t of f.values())
|
|
849
|
+
if (!(t.transport !== "sab" || !t.ringBuffer || !t.ringTemp || t.stopped))
|
|
850
|
+
try {
|
|
851
|
+
const e = t.ringBuffer.pop(t.ringTemp);
|
|
852
|
+
e > 0 && T(t, t.ringTemp.subarray(0, e));
|
|
853
|
+
} catch (e) {
|
|
854
|
+
I(e, t.captureId);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function et(t) {
|
|
858
|
+
if (Xe()) {
|
|
859
|
+
if (!F.has(t.captureId)) {
|
|
860
|
+
const e = Ze(t);
|
|
861
|
+
F.set(t.captureId, e), e.finally(() => {
|
|
862
|
+
F.delete(t.captureId);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
} else
|
|
866
|
+
A === null && (A = self.setInterval(Qe, 50));
|
|
867
|
+
}
|
|
868
|
+
function tt(t) {
|
|
869
|
+
if (F.delete(t), A !== null) {
|
|
870
|
+
let e = !1;
|
|
871
|
+
for (const r of f.values())
|
|
872
|
+
if (r.transport === "sab" && !r.stopped) {
|
|
873
|
+
e = !0;
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
if (!e) {
|
|
877
|
+
try {
|
|
878
|
+
self.clearInterval(A);
|
|
879
|
+
} catch {
|
|
880
|
+
}
|
|
881
|
+
A = null;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
function v(t) {
|
|
886
|
+
if (t.stopped || t.isReconfiguring)
|
|
857
887
|
return;
|
|
858
888
|
if (!t.inSegment) {
|
|
859
889
|
t.pendingReadOffset = 0, t.pendingWriteOffset = 0, t.pendingSamples = 0;
|
|
@@ -869,7 +899,7 @@ function P(t) {
|
|
|
869
899
|
r.set(t.pendingBuffer.subarray(i, n)), r.set(t.pendingBuffer.subarray(0, e - a), a);
|
|
870
900
|
}
|
|
871
901
|
t.pendingReadOffset = (i + e) % n, t.pendingSamples -= e;
|
|
872
|
-
const s =
|
|
902
|
+
const s = Je(r);
|
|
873
903
|
t.lastVolume = s;
|
|
874
904
|
try {
|
|
875
905
|
if (t.useWasmEncoder)
|
|
@@ -886,12 +916,12 @@ function P(t) {
|
|
|
886
916
|
t.encoder.encode(a), a.close();
|
|
887
917
|
}
|
|
888
918
|
} catch (a) {
|
|
889
|
-
|
|
919
|
+
I(a, t.captureId);
|
|
890
920
|
}
|
|
891
921
|
t.timestampUs += t.frameDurationUs;
|
|
892
922
|
}
|
|
893
923
|
}
|
|
894
|
-
function
|
|
924
|
+
function T(t, e) {
|
|
895
925
|
if (t.stopped)
|
|
896
926
|
return;
|
|
897
927
|
const r = e.length;
|
|
@@ -899,42 +929,42 @@ function W(t, e) {
|
|
|
899
929
|
return;
|
|
900
930
|
const n = t.pendingSamples + r;
|
|
901
931
|
if (n > t.pendingBuffer.length) {
|
|
902
|
-
const a = Math.max(n, t.pendingBuffer.length * 2),
|
|
932
|
+
const a = Math.max(n, t.pendingBuffer.length * 2), c = new Float32Array(a);
|
|
903
933
|
if (t.pendingSamples > 0) {
|
|
904
|
-
const
|
|
905
|
-
if (t.pendingReadOffset + t.pendingSamples <=
|
|
906
|
-
|
|
934
|
+
const l = t.pendingBuffer.length;
|
|
935
|
+
if (t.pendingReadOffset + t.pendingSamples <= l)
|
|
936
|
+
c.set(t.pendingBuffer.subarray(t.pendingReadOffset, t.pendingReadOffset + t.pendingSamples));
|
|
907
937
|
else {
|
|
908
|
-
const
|
|
909
|
-
|
|
938
|
+
const o = l - t.pendingReadOffset;
|
|
939
|
+
c.set(t.pendingBuffer.subarray(t.pendingReadOffset, l)), c.set(t.pendingBuffer.subarray(0, t.pendingSamples - o), o);
|
|
910
940
|
}
|
|
911
941
|
}
|
|
912
|
-
t.pendingBuffer =
|
|
942
|
+
t.pendingBuffer = c, t.pendingReadOffset = 0, t.pendingWriteOffset = t.pendingSamples;
|
|
913
943
|
}
|
|
914
944
|
const i = t.pendingBuffer.length, s = Math.min(r, i - t.pendingWriteOffset);
|
|
915
|
-
t.pendingBuffer.set(e.subarray(0, s), t.pendingWriteOffset), s < r && t.pendingBuffer.set(e.subarray(s), 0), t.pendingWriteOffset = (t.pendingWriteOffset + r) % i, t.pendingSamples += r,
|
|
945
|
+
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);
|
|
916
946
|
}
|
|
917
|
-
function
|
|
918
|
-
const s =
|
|
947
|
+
function B(t, e, r, n, i = !0) {
|
|
948
|
+
const s = f.get(t.captureId);
|
|
919
949
|
if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
|
|
920
950
|
return;
|
|
921
951
|
const a = e.byteLength;
|
|
922
952
|
s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(e);
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
Samples:
|
|
953
|
+
const c = s.encoderOutputBuffer.subarray(0, a), l = s.segmentStartPending;
|
|
954
|
+
l && (s.segmentStartPending = !1, s.epoch++, s.sequence = 0);
|
|
955
|
+
const o = s.segmentEndPending;
|
|
956
|
+
o && (s.segmentEndPending = !1, s.inSegment = !1);
|
|
957
|
+
const d = s.frameSize * s.channels, y = BigInt(Math.floor(r / 1e6 * s.sampleRate * s.channels));
|
|
958
|
+
C(
|
|
959
|
+
fe(
|
|
960
|
+
ue({
|
|
961
|
+
Samples: c,
|
|
932
962
|
Epoch: s.epoch,
|
|
933
963
|
Sequence: s.sequence,
|
|
934
|
-
FrameSizeInInterleavedSamples:
|
|
935
|
-
TimeStampInInterleavedSamples:
|
|
936
|
-
IsFirst:
|
|
937
|
-
IsLast:
|
|
964
|
+
FrameSizeInInterleavedSamples: d,
|
|
965
|
+
TimeStampInInterleavedSamples: y,
|
|
966
|
+
IsFirst: l,
|
|
967
|
+
IsLast: o,
|
|
938
968
|
AverageVolume: s.lastVolume,
|
|
939
969
|
AudioEventEstimatedDuration: 0
|
|
940
970
|
}),
|
|
@@ -943,14 +973,14 @@ function H(t, e, r, n, i = !0) {
|
|
|
943
973
|
)
|
|
944
974
|
), s.sequence++;
|
|
945
975
|
}
|
|
946
|
-
function
|
|
947
|
-
const e = Math.max(
|
|
976
|
+
function rt(t) {
|
|
977
|
+
const e = Math.max(M, Math.floor(t.options?.bitrate ?? b)), r = new AudioEncoder({
|
|
948
978
|
output: (n) => {
|
|
949
|
-
const i =
|
|
979
|
+
const i = f.get(t.captureId);
|
|
950
980
|
if (!i)
|
|
951
981
|
return;
|
|
952
982
|
const s = n.byteLength;
|
|
953
|
-
i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer),
|
|
983
|
+
i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer), B(
|
|
954
984
|
i,
|
|
955
985
|
i.encoderOutputBuffer.subarray(0, s),
|
|
956
986
|
n.timestamp ?? i.timestampUs,
|
|
@@ -959,7 +989,7 @@ function Ze(t) {
|
|
|
959
989
|
);
|
|
960
990
|
},
|
|
961
991
|
error: (n) => {
|
|
962
|
-
|
|
992
|
+
I(n, t.captureId);
|
|
963
993
|
}
|
|
964
994
|
});
|
|
965
995
|
return r.configure({
|
|
@@ -975,23 +1005,23 @@ function Ze(t) {
|
|
|
975
1005
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
976
1006
|
}), r;
|
|
977
1007
|
}
|
|
978
|
-
function
|
|
979
|
-
const e = Math.max(
|
|
980
|
-
return new
|
|
1008
|
+
function nt(t) {
|
|
1009
|
+
const e = Math.max(M, Math.floor(t.options?.bitrate ?? b));
|
|
1010
|
+
return new $({
|
|
981
1011
|
sampleRate: t.sampleRate,
|
|
982
1012
|
channels: t.channels,
|
|
983
1013
|
bitrate: e,
|
|
984
1014
|
frameSize: t.frameSize,
|
|
985
1015
|
onOutput: (r, n, i) => {
|
|
986
|
-
const s =
|
|
987
|
-
s &&
|
|
1016
|
+
const s = f.get(t.captureId);
|
|
1017
|
+
s && B(s, r, n, i, !0);
|
|
988
1018
|
},
|
|
989
1019
|
onError: (r) => {
|
|
990
|
-
|
|
1020
|
+
I(r, t.captureId);
|
|
991
1021
|
}
|
|
992
1022
|
});
|
|
993
1023
|
}
|
|
994
|
-
async function
|
|
1024
|
+
async function it() {
|
|
995
1025
|
if (typeof AudioEncoder > "u")
|
|
996
1026
|
return !1;
|
|
997
1027
|
try {
|
|
@@ -1004,12 +1034,15 @@ async function Xe() {
|
|
|
1004
1034
|
return !1;
|
|
1005
1035
|
}
|
|
1006
1036
|
}
|
|
1007
|
-
async function
|
|
1008
|
-
if (!
|
|
1037
|
+
async function st(t) {
|
|
1038
|
+
if (!m)
|
|
1009
1039
|
throw new Error("Audio capture worker missing send port");
|
|
1010
|
-
if (
|
|
1040
|
+
if (f.has(t.captureId)) {
|
|
1041
|
+
const h = f.get(t.captureId);
|
|
1042
|
+
O({ type: "started", captureId: t.captureId, sampleRate: h.sampleRate, channels: h.channels });
|
|
1011
1043
|
return;
|
|
1012
|
-
|
|
1044
|
+
}
|
|
1045
|
+
const e = Math.max(8e3, Math.floor(t.sampleRate)), r = Math.max(1, Math.floor(t.channels)), n = Math.max(1, Math.floor(e * qe / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / e)), s = n * 4, a = {
|
|
1013
1046
|
captureId: t.captureId,
|
|
1014
1047
|
streamId: t.streamId,
|
|
1015
1048
|
sourceType: t.sourceType,
|
|
@@ -1039,52 +1072,53 @@ async function et(t) {
|
|
|
1039
1072
|
lastVolume: 0,
|
|
1040
1073
|
targetIds: t.options?.targetIds,
|
|
1041
1074
|
options: t.options
|
|
1042
|
-
},
|
|
1043
|
-
let
|
|
1044
|
-
const
|
|
1045
|
-
if (
|
|
1046
|
-
|
|
1047
|
-
`Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${
|
|
1075
|
+
}, l = (t.options?.preferWebCodecs ?? !0) && await it();
|
|
1076
|
+
let o, d = !1;
|
|
1077
|
+
const y = Math.max(M, Math.floor(t.options?.bitrate ?? b));
|
|
1078
|
+
if (l)
|
|
1079
|
+
o = rt(a), E.debug(
|
|
1080
|
+
`Audio capture started: encoder=WebCodecs, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
|
|
1048
1081
|
);
|
|
1049
1082
|
else {
|
|
1050
|
-
const
|
|
1051
|
-
await
|
|
1052
|
-
`Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${
|
|
1083
|
+
const h = nt(a);
|
|
1084
|
+
await h.initialize(), o = h, d = !0, E.debug(
|
|
1085
|
+
`Audio capture started: encoder=WASM Opus, sampleRate=${e}Hz, channels=${r}, bitrate=${y}bps`
|
|
1053
1086
|
);
|
|
1054
1087
|
}
|
|
1055
|
-
const
|
|
1088
|
+
const p = {
|
|
1056
1089
|
...a,
|
|
1057
|
-
encoder:
|
|
1058
|
-
useWasmEncoder:
|
|
1090
|
+
encoder: o,
|
|
1091
|
+
useWasmEncoder: d,
|
|
1092
|
+
isReconfiguring: !1
|
|
1059
1093
|
};
|
|
1060
1094
|
if (t.transport === "sab") {
|
|
1061
1095
|
if (!t.sharedArrayBuffer)
|
|
1062
1096
|
throw new Error("Missing SharedArrayBuffer for sab transport");
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1097
|
+
const h = new xe(t.sharedArrayBuffer, Float32Array);
|
|
1098
|
+
p.ringBuffer = h, p.ringTemp = new Float32Array(Math.max(p.frameSize * 4, 4096)), et(p);
|
|
1065
1099
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1100
|
+
f.set(t.captureId, p), C(
|
|
1101
|
+
Me(
|
|
1102
|
+
De({
|
|
1069
1103
|
StreamId: t.streamId,
|
|
1070
1104
|
Description: `mic:${t.streamId}`,
|
|
1071
1105
|
SourceType: t.sourceType,
|
|
1072
|
-
Codec:
|
|
1106
|
+
Codec: W.Opus,
|
|
1073
1107
|
CodecDetails: "",
|
|
1074
1108
|
SampleRate: e,
|
|
1075
1109
|
Channels: r
|
|
1076
1110
|
}),
|
|
1077
1111
|
t.senderId,
|
|
1078
|
-
{ trackId: t.trackId, targetIds:
|
|
1112
|
+
{ trackId: t.trackId, targetIds: p.targetIds }
|
|
1079
1113
|
)
|
|
1080
|
-
),
|
|
1114
|
+
), O({ type: "started", captureId: t.captureId, sampleRate: e, channels: r });
|
|
1081
1115
|
}
|
|
1082
|
-
async function
|
|
1083
|
-
const e =
|
|
1116
|
+
async function j(t) {
|
|
1117
|
+
const e = f.get(t);
|
|
1084
1118
|
if (e) {
|
|
1085
|
-
e.stopped = !0,
|
|
1119
|
+
e.stopped = !0, f.delete(t);
|
|
1086
1120
|
try {
|
|
1087
|
-
|
|
1121
|
+
v(e);
|
|
1088
1122
|
} catch {
|
|
1089
1123
|
}
|
|
1090
1124
|
try {
|
|
@@ -1095,75 +1129,161 @@ async function z(t) {
|
|
|
1095
1129
|
e.encoder.close();
|
|
1096
1130
|
} catch {
|
|
1097
1131
|
}
|
|
1098
|
-
|
|
1132
|
+
C(ke(ve({}), e.senderId, { trackId: e.trackId, targetIds: e.targetIds })), O({ type: "stopped", captureId: e.captureId }), tt(t);
|
|
1099
1133
|
}
|
|
1100
1134
|
}
|
|
1101
|
-
function
|
|
1102
|
-
const e =
|
|
1135
|
+
function at(t) {
|
|
1136
|
+
const e = f.get(t);
|
|
1103
1137
|
!e || e.stopped || (e.inSegment = !0, e.segmentStartPending = !0);
|
|
1104
1138
|
}
|
|
1105
|
-
function
|
|
1106
|
-
const e =
|
|
1107
|
-
if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0,
|
|
1139
|
+
function ot(t) {
|
|
1140
|
+
const e = f.get(t);
|
|
1141
|
+
if (!(!e || e.stopped || !e.inSegment) && (e.segmentEndPending = !0, v(e), e.segmentEndPending && !e.stopped)) {
|
|
1108
1142
|
const r = e.frameSize - e.pendingSamples;
|
|
1109
1143
|
if (r > 0) {
|
|
1110
1144
|
const n = new Float32Array(r);
|
|
1111
|
-
|
|
1145
|
+
T(e, n);
|
|
1112
1146
|
}
|
|
1113
1147
|
}
|
|
1114
1148
|
}
|
|
1115
|
-
function
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1149
|
+
async function ct(t, e) {
|
|
1150
|
+
const r = f.get(t);
|
|
1151
|
+
if (!r || r.stopped)
|
|
1152
|
+
return;
|
|
1153
|
+
const n = r.options?.bitrate ?? b, i = e.bitrate ?? b;
|
|
1154
|
+
if (n === i) {
|
|
1155
|
+
r.options = e;
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
r.isReconfiguring = !0, r.options = e;
|
|
1159
|
+
const s = Math.max(M, Math.floor(i));
|
|
1160
|
+
let a;
|
|
1161
|
+
if (r.useWasmEncoder) {
|
|
1162
|
+
const l = new $({
|
|
1163
|
+
sampleRate: r.sampleRate,
|
|
1164
|
+
channels: r.channels,
|
|
1165
|
+
bitrate: s,
|
|
1166
|
+
frameSize: r.frameSize,
|
|
1167
|
+
onOutput: (o, d, y) => {
|
|
1168
|
+
const p = f.get(r.captureId);
|
|
1169
|
+
!p || p.isReconfiguring || B(p, o, d, y, !0);
|
|
1170
|
+
},
|
|
1171
|
+
onError: (o) => {
|
|
1172
|
+
I(o, r.captureId);
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1119
1175
|
try {
|
|
1120
|
-
|
|
1176
|
+
await l.initialize();
|
|
1177
|
+
} catch (o) {
|
|
1178
|
+
r.isReconfiguring = !1, I(o, t);
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
a = l;
|
|
1182
|
+
} else {
|
|
1183
|
+
const l = new AudioEncoder({
|
|
1184
|
+
output: (o) => {
|
|
1185
|
+
const d = f.get(r.captureId);
|
|
1186
|
+
if (!d || d.isReconfiguring)
|
|
1187
|
+
return;
|
|
1188
|
+
const y = o.byteLength;
|
|
1189
|
+
d.encoderOutputBuffer.length < y && (d.encoderOutputBuffer = new Uint8Array(Math.max(y, d.encoderOutputBuffer.length * 2))), o.copyTo(d.encoderOutputBuffer), B(
|
|
1190
|
+
d,
|
|
1191
|
+
d.encoderOutputBuffer.subarray(0, y),
|
|
1192
|
+
o.timestamp ?? d.timestampUs,
|
|
1193
|
+
o.duration ?? d.frameDurationUs,
|
|
1194
|
+
o.type === "key"
|
|
1195
|
+
);
|
|
1196
|
+
},
|
|
1197
|
+
error: (o) => {
|
|
1198
|
+
I(o, r.captureId);
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
l.configure({
|
|
1202
|
+
codec: "opus",
|
|
1203
|
+
numberOfChannels: r.channels,
|
|
1204
|
+
sampleRate: r.sampleRate,
|
|
1205
|
+
bitrate: s,
|
|
1206
|
+
bitrateMode: "constant",
|
|
1207
|
+
opus: {
|
|
1208
|
+
application: "lowdelay",
|
|
1209
|
+
signal: "voice"
|
|
1210
|
+
}
|
|
1211
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1212
|
+
}), a = l;
|
|
1213
|
+
}
|
|
1214
|
+
const c = r.encoder;
|
|
1215
|
+
try {
|
|
1216
|
+
await c.flush();
|
|
1217
|
+
} catch {
|
|
1218
|
+
}
|
|
1219
|
+
try {
|
|
1220
|
+
c.close();
|
|
1221
|
+
} catch {
|
|
1222
|
+
}
|
|
1223
|
+
r.encoder = a, r.isReconfiguring = !1, E.debug(`Audio capture bitrate updated: ${s}bps`);
|
|
1224
|
+
}
|
|
1225
|
+
async function ut() {
|
|
1226
|
+
const t = Array.from(f.keys()).map(
|
|
1227
|
+
(e) => j(e).catch(() => {
|
|
1228
|
+
})
|
|
1229
|
+
);
|
|
1230
|
+
if (await Promise.all(t), m) {
|
|
1231
|
+
try {
|
|
1232
|
+
m.close();
|
|
1121
1233
|
} catch {
|
|
1122
1234
|
}
|
|
1123
|
-
|
|
1235
|
+
m = null;
|
|
1124
1236
|
}
|
|
1125
1237
|
}
|
|
1126
1238
|
self.addEventListener("message", (t) => {
|
|
1127
1239
|
const e = t.data;
|
|
1128
1240
|
if (e.type === "attachSendPort") {
|
|
1129
|
-
if (
|
|
1241
|
+
if (m)
|
|
1130
1242
|
try {
|
|
1131
|
-
|
|
1243
|
+
m.close();
|
|
1132
1244
|
} catch {
|
|
1133
1245
|
}
|
|
1134
|
-
|
|
1246
|
+
m = e.port;
|
|
1135
1247
|
try {
|
|
1136
|
-
|
|
1248
|
+
m.start?.();
|
|
1137
1249
|
} catch {
|
|
1138
1250
|
}
|
|
1139
1251
|
return;
|
|
1140
1252
|
}
|
|
1141
1253
|
if (e.type === "start") {
|
|
1142
|
-
|
|
1143
|
-
|
|
1254
|
+
st(e).catch((r) => {
|
|
1255
|
+
I(r, e.captureId);
|
|
1144
1256
|
});
|
|
1145
1257
|
return;
|
|
1146
1258
|
}
|
|
1147
1259
|
if (e.type === "pcm") {
|
|
1148
|
-
const r =
|
|
1260
|
+
const r = f.get(e.captureId);
|
|
1149
1261
|
if (!r || r.stopped)
|
|
1150
1262
|
return;
|
|
1151
|
-
|
|
1263
|
+
T(r, e.pcm);
|
|
1152
1264
|
return;
|
|
1153
1265
|
}
|
|
1154
1266
|
if (e.type === "stop") {
|
|
1155
|
-
|
|
1156
|
-
|
|
1267
|
+
j(e.captureId).catch((r) => {
|
|
1268
|
+
E.warn(`Failed to stop audio capture: ${r}`), I(r, e.captureId);
|
|
1157
1269
|
});
|
|
1158
1270
|
return;
|
|
1159
1271
|
}
|
|
1160
1272
|
if (e.type === "startSegment") {
|
|
1161
|
-
|
|
1273
|
+
at(e.captureId);
|
|
1162
1274
|
return;
|
|
1163
1275
|
}
|
|
1164
1276
|
if (e.type === "endSegment") {
|
|
1165
|
-
|
|
1277
|
+
ot(e.captureId);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (e.type === "updateOptions") {
|
|
1281
|
+
ct(e.captureId, e.options).catch((r) => {
|
|
1282
|
+
E.warn(`Failed to update audio capture options: ${r}`), I(r, e.captureId);
|
|
1283
|
+
});
|
|
1166
1284
|
return;
|
|
1167
1285
|
}
|
|
1168
|
-
e.type === "dispose" &&
|
|
1286
|
+
e.type === "dispose" && ut().catch((r) => {
|
|
1287
|
+
E.warn(`Failed to dispose audio capture worker: ${r}`);
|
|
1288
|
+
});
|
|
1169
1289
|
});
|