@ikonai/sdk 0.0.42 → 0.0.43
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-kpORDYGU.js +1138 -0
- package/assets/{audio-playback-worker-CYoIqiGJ.js → audio-playback-worker-Cwm3GaAx.js} +321 -212
- package/assets/{protocol-worker-E7o-6_bZ.js → protocol-worker-DKSTqFKg.js} +228 -207
- package/assets/video-capture-worker-BBs_62Fq.js +963 -0
- package/assets/video-playback-worker-Bfm3r5xW.js +924 -0
- package/client/ikon-client-config.d.ts +6 -10
- package/client/ikon-client.d.ts +4 -5
- package/index.js +1532 -1311
- package/media/audio-constants.d.ts +5 -0
- package/media/ikon-audio-playback.d.ts +53 -0
- package/media/ikon-video-capture.d.ts +0 -1
- package/media/ikon-video-playback.d.ts +0 -2
- package/media/video-constants.d.ts +42 -0
- package/package.json +1 -1
- package/worker/audio-playback-worker.d.ts +3 -0
- package/worker/video-capture-worker.d.ts +3 -1
- package/worker/video-playback-worker.d.ts +3 -0
- package/assets/audio-capture-worker-zx_Os6ad.js +0 -1112
- package/assets/video-capture-worker-CTRX9PKp.js +0 -843
- package/assets/video-playback-worker-CIuL9Crw.js +0 -875
|
@@ -1,1112 +0,0 @@
|
|
|
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 k = 27;
|
|
5
|
-
for (let D = 0; D < l.length; D++)
|
|
6
|
-
u.setUint32(k, l[D] >>> 0, !0), k += 4;
|
|
7
|
-
return y.set(t, I), y;
|
|
8
|
-
}
|
|
9
|
-
var w = /* @__PURE__ */ ((e) => (e[e.Null = 1] = "Null", e[e.Bool = 2] = "Bool", e[e.Int32 = 3] = "Int32", e[e.Int64 = 4] = "Int64", e[e.UInt32 = 5] = "UInt32", e[e.UInt64 = 6] = "UInt64", e[e.Float32 = 7] = "Float32", e[e.Float64 = 8] = "Float64", e[e.Array = 9] = "Array", e[e.Dict = 10] = "Dict", e[e.Object = 11] = "Object", e[e.String = 12] = "String", e[e.Binary = 13] = "Binary", e[e.Guid = 14] = "Guid", e))(w || {});
|
|
10
|
-
const $ = 161, j = 162, A = new TextEncoder();
|
|
11
|
-
new TextDecoder("utf-8", { fatal: !0 });
|
|
12
|
-
class p {
|
|
13
|
-
constructor(t = 1) {
|
|
14
|
-
this.version = t, this.buffer.writeByte($), this.buffer.writeVarUInt(t >>> 0);
|
|
15
|
-
}
|
|
16
|
-
buffer = new b();
|
|
17
|
-
closed = !1;
|
|
18
|
-
cached;
|
|
19
|
-
writeInt32Field(t, r) {
|
|
20
|
-
this.writeFixedField(t, 3, () => this.buffer.writeInt32(r | 0));
|
|
21
|
-
}
|
|
22
|
-
writeUInt32Field(t, r) {
|
|
23
|
-
this.writeFixedField(t, 5, () => this.buffer.writeUInt32(r >>> 0));
|
|
24
|
-
}
|
|
25
|
-
writeInt64Field(t, r) {
|
|
26
|
-
this.writeFixedField(t, 4, () => this.buffer.writeBigInt64(r));
|
|
27
|
-
}
|
|
28
|
-
writeUInt64Field(t, r) {
|
|
29
|
-
this.writeFixedField(t, 6, () => this.buffer.writeBigUInt64(r));
|
|
30
|
-
}
|
|
31
|
-
writeFloat32Field(t, r) {
|
|
32
|
-
this.writeFixedField(t, 7, () => this.buffer.writeFloat32(r));
|
|
33
|
-
}
|
|
34
|
-
writeFloat64Field(t, r) {
|
|
35
|
-
this.writeFixedField(t, 8, () => this.buffer.writeFloat64(r));
|
|
36
|
-
}
|
|
37
|
-
writeBoolField(t, r) {
|
|
38
|
-
this.writeFixedField(t, 2, () => this.buffer.writeByte(r ? 1 : 0));
|
|
39
|
-
}
|
|
40
|
-
writeGuidField(t, r) {
|
|
41
|
-
const n = r instanceof o ? r.asBytes() : r;
|
|
42
|
-
if (n.length !== 16)
|
|
43
|
-
throw new Error("Guid payload must be 16 bytes");
|
|
44
|
-
this.writeFixedField(t, 14, () => this.buffer.writeBytes(n));
|
|
45
|
-
}
|
|
46
|
-
writeStringField(t, r) {
|
|
47
|
-
const n = A.encode(r ?? "");
|
|
48
|
-
this.writeVariableField(t, 12, n);
|
|
49
|
-
}
|
|
50
|
-
writeBinaryField(t, r) {
|
|
51
|
-
this.writeVariableField(t, 13, r);
|
|
52
|
-
}
|
|
53
|
-
writeObjectField(t, r, n) {
|
|
54
|
-
const i = new p(r);
|
|
55
|
-
n(i);
|
|
56
|
-
const s = i.finish();
|
|
57
|
-
this.writeVariableField(t, 11, s);
|
|
58
|
-
}
|
|
59
|
-
writeArrayField(t, r, n) {
|
|
60
|
-
const i = new O(r);
|
|
61
|
-
n(i);
|
|
62
|
-
const s = i.finish();
|
|
63
|
-
this.writeVariableField(t, 9, s);
|
|
64
|
-
}
|
|
65
|
-
writeDictionaryField(t, r, n, i) {
|
|
66
|
-
const s = new M(r, n);
|
|
67
|
-
i(s);
|
|
68
|
-
const a = s.finish();
|
|
69
|
-
this.writeVariableField(t, 10, a);
|
|
70
|
-
}
|
|
71
|
-
finish() {
|
|
72
|
-
return this.closed || (this.buffer.writeByte(j), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
|
|
73
|
-
}
|
|
74
|
-
writeFixedField(t, r, n) {
|
|
75
|
-
this.writeFieldHeader(t, r, 0), n();
|
|
76
|
-
}
|
|
77
|
-
writeVariableField(t, r, n) {
|
|
78
|
-
this.writeFieldHeader(t, r, n.length), this.buffer.writeBytes(n);
|
|
79
|
-
}
|
|
80
|
-
writeFieldHeader(t, r, n) {
|
|
81
|
-
this.buffer.writeUInt32(t >>> 0), this.buffer.writeByte(F(r)), q(r) && this.buffer.writeVarUInt(n >>> 0);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class O {
|
|
85
|
-
constructor(t) {
|
|
86
|
-
this.elementType = t;
|
|
87
|
-
}
|
|
88
|
-
payload = new b();
|
|
89
|
-
count = 0;
|
|
90
|
-
writeInt32(t) {
|
|
91
|
-
this.ensureElementType(
|
|
92
|
-
3
|
|
93
|
-
/* Int32 */
|
|
94
|
-
), this.count++, this.payload.writeInt32(t | 0);
|
|
95
|
-
}
|
|
96
|
-
writeUInt32(t) {
|
|
97
|
-
this.ensureElementType(
|
|
98
|
-
5
|
|
99
|
-
/* UInt32 */
|
|
100
|
-
), this.count++, this.payload.writeUInt32(t >>> 0);
|
|
101
|
-
}
|
|
102
|
-
writeInt64(t) {
|
|
103
|
-
this.ensureElementType(
|
|
104
|
-
4
|
|
105
|
-
/* Int64 */
|
|
106
|
-
), this.count++, this.payload.writeBigInt64(t);
|
|
107
|
-
}
|
|
108
|
-
writeUInt64(t) {
|
|
109
|
-
this.ensureElementType(
|
|
110
|
-
6
|
|
111
|
-
/* UInt64 */
|
|
112
|
-
), this.count++, this.payload.writeBigUInt64(t);
|
|
113
|
-
}
|
|
114
|
-
writeFloat32(t) {
|
|
115
|
-
this.ensureElementType(
|
|
116
|
-
7
|
|
117
|
-
/* Float32 */
|
|
118
|
-
), this.count++, this.payload.writeFloat32(t);
|
|
119
|
-
}
|
|
120
|
-
writeFloat64(t) {
|
|
121
|
-
this.ensureElementType(
|
|
122
|
-
8
|
|
123
|
-
/* Float64 */
|
|
124
|
-
), this.count++, this.payload.writeFloat64(t);
|
|
125
|
-
}
|
|
126
|
-
writeBool(t) {
|
|
127
|
-
this.ensureElementType(
|
|
128
|
-
2
|
|
129
|
-
/* Bool */
|
|
130
|
-
), this.count++, this.payload.writeByte(t ? 1 : 0);
|
|
131
|
-
}
|
|
132
|
-
writeGuid(t) {
|
|
133
|
-
this.ensureElementType(
|
|
134
|
-
14
|
|
135
|
-
/* Guid */
|
|
136
|
-
), this.count++;
|
|
137
|
-
const r = t instanceof o ? t.asBytes() : t;
|
|
138
|
-
if (r.length !== 16)
|
|
139
|
-
throw new Error("Guid payload must be 16 bytes");
|
|
140
|
-
this.payload.writeBytes(r);
|
|
141
|
-
}
|
|
142
|
-
writeString(t) {
|
|
143
|
-
this.ensureElementType(
|
|
144
|
-
12
|
|
145
|
-
/* String */
|
|
146
|
-
), this.count++;
|
|
147
|
-
const r = A.encode(t ?? "");
|
|
148
|
-
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
|
|
149
|
-
}
|
|
150
|
-
writeBinary(t) {
|
|
151
|
-
this.ensureElementType(
|
|
152
|
-
13
|
|
153
|
-
/* Binary */
|
|
154
|
-
), this.count++, this.payload.writeVarUInt(t.length), this.payload.writeBytes(t);
|
|
155
|
-
}
|
|
156
|
-
writeObject(t, r) {
|
|
157
|
-
this.ensureElementType(
|
|
158
|
-
11
|
|
159
|
-
/* Object */
|
|
160
|
-
), this.count++;
|
|
161
|
-
const n = new p(t);
|
|
162
|
-
r(n);
|
|
163
|
-
const i = n.finish();
|
|
164
|
-
this.payload.writeVarUInt(i.length), this.payload.writeBytes(i);
|
|
165
|
-
}
|
|
166
|
-
writeArray(t, r) {
|
|
167
|
-
this.ensureElementType(
|
|
168
|
-
9
|
|
169
|
-
/* Array */
|
|
170
|
-
), this.count++;
|
|
171
|
-
const n = new O(t);
|
|
172
|
-
r(n);
|
|
173
|
-
const i = n.finish();
|
|
174
|
-
this.payload.writeBytes(i);
|
|
175
|
-
}
|
|
176
|
-
writeDictionary(t, r, n) {
|
|
177
|
-
this.ensureElementType(
|
|
178
|
-
10
|
|
179
|
-
/* Dict */
|
|
180
|
-
), this.count++;
|
|
181
|
-
const i = new M(t, r);
|
|
182
|
-
n(i);
|
|
183
|
-
const s = i.finish();
|
|
184
|
-
this.payload.writeBytes(s);
|
|
185
|
-
}
|
|
186
|
-
finish() {
|
|
187
|
-
const t = new b();
|
|
188
|
-
return t.writeByte(F(this.elementType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
|
|
189
|
-
}
|
|
190
|
-
ensureElementType(t) {
|
|
191
|
-
if (this.elementType !== t)
|
|
192
|
-
throw new Error(`Array element type is ${w[this.elementType]}, expected ${w[t]}`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
class M {
|
|
196
|
-
constructor(t, r) {
|
|
197
|
-
this.keyType = t, this.valueType = r, G(t);
|
|
198
|
-
}
|
|
199
|
-
payload = new b();
|
|
200
|
-
count = 0;
|
|
201
|
-
entryOpen = !1;
|
|
202
|
-
beginEntry() {
|
|
203
|
-
if (this.entryOpen)
|
|
204
|
-
throw new Error("Previous dictionary entry not completed");
|
|
205
|
-
return this.count++, this.entryOpen = !0, new Y(this.keyType, this.valueType, this.payload, () => {
|
|
206
|
-
this.entryOpen = !1;
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
finish() {
|
|
210
|
-
if (this.entryOpen)
|
|
211
|
-
throw new Error("Dictionary entry not completed");
|
|
212
|
-
const t = new b();
|
|
213
|
-
return t.writeByte(F(this.keyType)), t.writeByte(F(this.valueType)), t.writeVarUInt(this.count), t.writeBytes(this.payload.toUint8Array()), t.toUint8Array();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
class Y {
|
|
217
|
-
constructor(t, r, n, i) {
|
|
218
|
-
this.keyType = t, this.valueType = r, this.payload = n, this.onComplete = i;
|
|
219
|
-
}
|
|
220
|
-
keyWritten = !1;
|
|
221
|
-
valueWritten = !1;
|
|
222
|
-
completed = !1;
|
|
223
|
-
writeKeyInt32(t) {
|
|
224
|
-
this.ensureKeyType(
|
|
225
|
-
3
|
|
226
|
-
/* Int32 */
|
|
227
|
-
), this.payload.writeInt32(t | 0), this.keyWritten = !0;
|
|
228
|
-
}
|
|
229
|
-
writeKeyUInt32(t) {
|
|
230
|
-
this.ensureKeyType(
|
|
231
|
-
5
|
|
232
|
-
/* UInt32 */
|
|
233
|
-
), this.payload.writeUInt32(t >>> 0), this.keyWritten = !0;
|
|
234
|
-
}
|
|
235
|
-
writeKeyInt64(t) {
|
|
236
|
-
this.ensureKeyType(
|
|
237
|
-
4
|
|
238
|
-
/* Int64 */
|
|
239
|
-
), this.payload.writeBigInt64(t), this.keyWritten = !0;
|
|
240
|
-
}
|
|
241
|
-
writeKeyUInt64(t) {
|
|
242
|
-
this.ensureKeyType(
|
|
243
|
-
6
|
|
244
|
-
/* UInt64 */
|
|
245
|
-
), this.payload.writeBigUInt64(t), this.keyWritten = !0;
|
|
246
|
-
}
|
|
247
|
-
writeKeyFloat32(t) {
|
|
248
|
-
this.ensureKeyType(
|
|
249
|
-
7
|
|
250
|
-
/* Float32 */
|
|
251
|
-
), this.payload.writeFloat32(t), this.keyWritten = !0;
|
|
252
|
-
}
|
|
253
|
-
writeKeyFloat64(t) {
|
|
254
|
-
this.ensureKeyType(
|
|
255
|
-
8
|
|
256
|
-
/* Float64 */
|
|
257
|
-
), this.payload.writeFloat64(t), this.keyWritten = !0;
|
|
258
|
-
}
|
|
259
|
-
writeKeyBool(t) {
|
|
260
|
-
this.ensureKeyType(
|
|
261
|
-
2
|
|
262
|
-
/* Bool */
|
|
263
|
-
), this.payload.writeByte(t ? 1 : 0), this.keyWritten = !0;
|
|
264
|
-
}
|
|
265
|
-
writeKeyGuid(t) {
|
|
266
|
-
this.ensureKeyType(
|
|
267
|
-
14
|
|
268
|
-
/* Guid */
|
|
269
|
-
);
|
|
270
|
-
const r = t instanceof o ? t.asBytes() : t;
|
|
271
|
-
if (r.length !== 16)
|
|
272
|
-
throw new Error("Guid payload must be 16 bytes");
|
|
273
|
-
this.payload.writeBytes(r), this.keyWritten = !0;
|
|
274
|
-
}
|
|
275
|
-
writeKeyString(t) {
|
|
276
|
-
this.ensureKeyType(
|
|
277
|
-
12
|
|
278
|
-
/* String */
|
|
279
|
-
);
|
|
280
|
-
const r = A.encode(t ?? "");
|
|
281
|
-
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
|
|
282
|
-
}
|
|
283
|
-
writeKeyBinary(t) {
|
|
284
|
-
this.ensureKeyType(
|
|
285
|
-
13
|
|
286
|
-
/* Binary */
|
|
287
|
-
), this.payload.writeVarUInt(t.length), this.payload.writeBytes(t), this.keyWritten = !0;
|
|
288
|
-
}
|
|
289
|
-
writeValueInt32(t) {
|
|
290
|
-
this.ensureValueType(
|
|
291
|
-
3
|
|
292
|
-
/* Int32 */
|
|
293
|
-
), this.payload.writeInt32(t | 0), this.valueWritten = !0;
|
|
294
|
-
}
|
|
295
|
-
writeValueUInt32(t) {
|
|
296
|
-
this.ensureValueType(
|
|
297
|
-
5
|
|
298
|
-
/* UInt32 */
|
|
299
|
-
), this.payload.writeUInt32(t >>> 0), this.valueWritten = !0;
|
|
300
|
-
}
|
|
301
|
-
writeValueInt64(t) {
|
|
302
|
-
this.ensureValueType(
|
|
303
|
-
4
|
|
304
|
-
/* Int64 */
|
|
305
|
-
), this.payload.writeBigInt64(t), this.valueWritten = !0;
|
|
306
|
-
}
|
|
307
|
-
writeValueUInt64(t) {
|
|
308
|
-
this.ensureValueType(
|
|
309
|
-
6
|
|
310
|
-
/* UInt64 */
|
|
311
|
-
), this.payload.writeBigUInt64(t), this.valueWritten = !0;
|
|
312
|
-
}
|
|
313
|
-
writeValueFloat32(t) {
|
|
314
|
-
this.ensureValueType(
|
|
315
|
-
7
|
|
316
|
-
/* Float32 */
|
|
317
|
-
), this.payload.writeFloat32(t), this.valueWritten = !0;
|
|
318
|
-
}
|
|
319
|
-
writeValueFloat64(t) {
|
|
320
|
-
this.ensureValueType(
|
|
321
|
-
8
|
|
322
|
-
/* Float64 */
|
|
323
|
-
), this.payload.writeFloat64(t), this.valueWritten = !0;
|
|
324
|
-
}
|
|
325
|
-
writeValueBool(t) {
|
|
326
|
-
this.ensureValueType(
|
|
327
|
-
2
|
|
328
|
-
/* Bool */
|
|
329
|
-
), this.payload.writeByte(t ? 1 : 0), this.valueWritten = !0;
|
|
330
|
-
}
|
|
331
|
-
writeValueGuid(t) {
|
|
332
|
-
this.ensureValueType(
|
|
333
|
-
14
|
|
334
|
-
/* Guid */
|
|
335
|
-
);
|
|
336
|
-
const r = t instanceof o ? t.asBytes() : t;
|
|
337
|
-
if (r.length !== 16)
|
|
338
|
-
throw new Error("Guid payload must be 16 bytes");
|
|
339
|
-
this.payload.writeBytes(r), this.valueWritten = !0;
|
|
340
|
-
}
|
|
341
|
-
writeNullValue() {
|
|
342
|
-
this.ensureValueType(
|
|
343
|
-
1
|
|
344
|
-
/* Null */
|
|
345
|
-
), this.valueWritten = !0;
|
|
346
|
-
}
|
|
347
|
-
writeValueBinary(t) {
|
|
348
|
-
this.ensureValueType(
|
|
349
|
-
13
|
|
350
|
-
/* Binary */
|
|
351
|
-
), this.payload.writeVarUInt(t.length), this.payload.writeBytes(t), this.valueWritten = !0;
|
|
352
|
-
}
|
|
353
|
-
writeValueString(t) {
|
|
354
|
-
this.ensureValueType(
|
|
355
|
-
12
|
|
356
|
-
/* String */
|
|
357
|
-
);
|
|
358
|
-
const r = A.encode(t ?? "");
|
|
359
|
-
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
|
|
360
|
-
}
|
|
361
|
-
writeValueObject(t, r) {
|
|
362
|
-
this.ensureValueType(
|
|
363
|
-
11
|
|
364
|
-
/* Object */
|
|
365
|
-
);
|
|
366
|
-
const n = new p(t);
|
|
367
|
-
r(n);
|
|
368
|
-
const i = n.finish();
|
|
369
|
-
this.payload.writeVarUInt(i.length), this.payload.writeBytes(i), this.valueWritten = !0;
|
|
370
|
-
}
|
|
371
|
-
writeValueArray(t, r) {
|
|
372
|
-
this.ensureValueType(
|
|
373
|
-
9
|
|
374
|
-
/* Array */
|
|
375
|
-
);
|
|
376
|
-
const n = new O(t);
|
|
377
|
-
r(n);
|
|
378
|
-
const i = n.finish();
|
|
379
|
-
this.payload.writeBytes(i), this.valueWritten = !0;
|
|
380
|
-
}
|
|
381
|
-
writeValueDictionary(t, r, n) {
|
|
382
|
-
this.ensureValueType(
|
|
383
|
-
10
|
|
384
|
-
/* Dict */
|
|
385
|
-
);
|
|
386
|
-
const i = new M(t, r);
|
|
387
|
-
n(i);
|
|
388
|
-
const s = i.finish();
|
|
389
|
-
this.payload.writeBytes(s), this.valueWritten = !0;
|
|
390
|
-
}
|
|
391
|
-
complete() {
|
|
392
|
-
if (!this.completed) {
|
|
393
|
-
if (!this.keyWritten || !this.valueWritten)
|
|
394
|
-
throw new Error("Dictionary entry must write both key and value");
|
|
395
|
-
this.completed = !0, this.onComplete();
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
ensureKeyType(t) {
|
|
399
|
-
if (this.keyType !== t)
|
|
400
|
-
throw new Error(`Dictionary key type is ${w[this.keyType]}, expected ${w[t]}`);
|
|
401
|
-
}
|
|
402
|
-
ensureValueType(t) {
|
|
403
|
-
if (this.valueType !== t)
|
|
404
|
-
throw new Error(`Dictionary value type is ${w[this.valueType]}, expected ${w[t]}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
class o {
|
|
408
|
-
constructor(t) {
|
|
409
|
-
this.bytes = t;
|
|
410
|
-
}
|
|
411
|
-
static fromString(t) {
|
|
412
|
-
if (!t)
|
|
413
|
-
throw new Error("Guid string is empty");
|
|
414
|
-
const r = t.replace(/-/g, "");
|
|
415
|
-
if (r.length !== 32)
|
|
416
|
-
throw new Error("Guid string must be 32 hex characters");
|
|
417
|
-
const n = new Uint8Array(16), i = o.parseHexSlice(r, 0, 8), s = o.parseHexSlice(r, 8, 4), a = o.parseHexSlice(r, 12, 4);
|
|
418
|
-
o.writeUInt32LE(n, 0, i), o.writeUInt16LE(n, 4, s), o.writeUInt16LE(n, 6, a);
|
|
419
|
-
for (let c = 0; c < 8; c++)
|
|
420
|
-
n[8 + c] = o.parseHexSlice(r, 16 + c * 2, 2);
|
|
421
|
-
return new o(n);
|
|
422
|
-
}
|
|
423
|
-
static fromBytes(t) {
|
|
424
|
-
if (t.length !== 16)
|
|
425
|
-
throw new Error("Guid byte array must be 16 bytes");
|
|
426
|
-
return new o(Uint8Array.from(t));
|
|
427
|
-
}
|
|
428
|
-
static createZero() {
|
|
429
|
-
return new o(new Uint8Array(16));
|
|
430
|
-
}
|
|
431
|
-
static createRandom() {
|
|
432
|
-
const t = new Uint8Array(16), r = globalThis.crypto;
|
|
433
|
-
if (r?.getRandomValues)
|
|
434
|
-
r.getRandomValues(t);
|
|
435
|
-
else
|
|
436
|
-
for (let n = 0; n < t.length; n++)
|
|
437
|
-
t[n] = Math.floor(Math.random() * 256);
|
|
438
|
-
return t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128, new o(t);
|
|
439
|
-
}
|
|
440
|
-
toString() {
|
|
441
|
-
const t = this.bytes;
|
|
442
|
-
return [
|
|
443
|
-
o.toHex(o.readUInt32LE(t, 0), 8),
|
|
444
|
-
o.toHex(o.readUInt16LE(t, 4), 4),
|
|
445
|
-
o.toHex(o.readUInt16LE(t, 6), 4),
|
|
446
|
-
C(t.subarray(8, 10)),
|
|
447
|
-
C(t.subarray(10, 16))
|
|
448
|
-
].join("-");
|
|
449
|
-
}
|
|
450
|
-
asBytes() {
|
|
451
|
-
return this.bytes.slice();
|
|
452
|
-
}
|
|
453
|
-
static parseHexSlice(t, r, n) {
|
|
454
|
-
const i = t.substr(r, n), s = Number.parseInt(i, 16);
|
|
455
|
-
if (Number.isNaN(s))
|
|
456
|
-
throw new Error("Guid string contains invalid characters");
|
|
457
|
-
return s >>> 0;
|
|
458
|
-
}
|
|
459
|
-
static writeUInt32LE(t, r, n) {
|
|
460
|
-
const i = n >>> 0;
|
|
461
|
-
t[r] = i & 255, t[r + 1] = i >>> 8 & 255, t[r + 2] = i >>> 16 & 255, t[r + 3] = i >>> 24 & 255;
|
|
462
|
-
}
|
|
463
|
-
static writeUInt16LE(t, r, n) {
|
|
464
|
-
const i = n & 65535;
|
|
465
|
-
t[r] = i & 255, t[r + 1] = i >>> 8 & 255;
|
|
466
|
-
}
|
|
467
|
-
static readUInt32LE(t, r) {
|
|
468
|
-
return (t[r] | t[r + 1] << 8 | t[r + 2] << 16 | t[r + 3] << 24) >>> 0;
|
|
469
|
-
}
|
|
470
|
-
static readUInt16LE(t, r) {
|
|
471
|
-
return (t[r] | t[r + 1] << 8) & 65535;
|
|
472
|
-
}
|
|
473
|
-
static toHex(t, r) {
|
|
474
|
-
return (t >>> 0).toString(16).padStart(r, "0");
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
class b {
|
|
478
|
-
bytes = [];
|
|
479
|
-
writeByte(t) {
|
|
480
|
-
this.bytes.push(t & 255);
|
|
481
|
-
}
|
|
482
|
-
writeBytes(t) {
|
|
483
|
-
for (let r = 0; r < t.length; r++)
|
|
484
|
-
this.bytes.push(t[r]);
|
|
485
|
-
}
|
|
486
|
-
writeUInt32(t) {
|
|
487
|
-
this.bytes.push(t & 255), this.bytes.push(t >>> 8 & 255), this.bytes.push(t >>> 16 & 255), this.bytes.push(t >>> 24 & 255);
|
|
488
|
-
}
|
|
489
|
-
writeInt32(t) {
|
|
490
|
-
this.writeUInt32(t | 0);
|
|
491
|
-
}
|
|
492
|
-
writeFloat32(t) {
|
|
493
|
-
const r = new DataView(new ArrayBuffer(4));
|
|
494
|
-
r.setFloat32(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
|
|
495
|
-
}
|
|
496
|
-
writeFloat64(t) {
|
|
497
|
-
const r = new DataView(new ArrayBuffer(8));
|
|
498
|
-
r.setFloat64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
|
|
499
|
-
}
|
|
500
|
-
writeBigInt64(t) {
|
|
501
|
-
const r = new DataView(new ArrayBuffer(8));
|
|
502
|
-
r.setBigInt64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
|
|
503
|
-
}
|
|
504
|
-
writeBigUInt64(t) {
|
|
505
|
-
const r = new DataView(new ArrayBuffer(8));
|
|
506
|
-
r.setBigUint64(0, t, !0), this.writeBytes(new Uint8Array(r.buffer));
|
|
507
|
-
}
|
|
508
|
-
writeVarUInt(t) {
|
|
509
|
-
let r = t >>> 0;
|
|
510
|
-
for (; r >= 128; )
|
|
511
|
-
this.bytes.push(r & 127 | 128), r >>>= 7;
|
|
512
|
-
this.bytes.push(r & 127);
|
|
513
|
-
}
|
|
514
|
-
toUint8Array() {
|
|
515
|
-
return Uint8Array.from(this.bytes);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
function F(e, t = 0) {
|
|
519
|
-
if ((t & 240) !== 0)
|
|
520
|
-
throw new Error("Teleport flags must fit into 4 bits");
|
|
521
|
-
return (e & 15) << 4 | t & 15;
|
|
522
|
-
}
|
|
523
|
-
function q(e) {
|
|
524
|
-
return e === 12 || e === 13 || e === 9 || e === 11 || e === 10;
|
|
525
|
-
}
|
|
526
|
-
function G(e) {
|
|
527
|
-
if (e === 9 || e === 11 || e === 10 || e === 1)
|
|
528
|
-
throw new Error("Dictionary keys must be primitive Teleport types");
|
|
529
|
-
}
|
|
530
|
-
function C(e) {
|
|
531
|
-
return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
532
|
-
}
|
|
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
|
-
const x = 1, J = 4194307, X = 271275304, Z = 668699606, Q = 945580544, tt = 1594075008, et = 2079085407, rt = 2541432218, nt = 2986785889, it = 3105403172, st = 4017217601;
|
|
535
|
-
function at(e) {
|
|
536
|
-
const t = {};
|
|
537
|
-
return ot(t), e && Object.assign(t, e), t;
|
|
538
|
-
}
|
|
539
|
-
function ot(e) {
|
|
540
|
-
return e.Data = new Uint8Array(0), e.IsKey = !1, e.IsLast = !1, e.TimestampInUs = 0n, e.DurationInUs = 0, e.IsFirst = !1, e.TotalDurationInUs = 0, e.Volume = 0, e.VolumeSampleCount = 0, e;
|
|
541
|
-
}
|
|
542
|
-
function ut(e) {
|
|
543
|
-
const t = new p(x);
|
|
544
|
-
return ct(e, t), t.finish();
|
|
545
|
-
}
|
|
546
|
-
function ct(e, t) {
|
|
547
|
-
t.writeUInt64Field(X, e.TimestampInUs), t.writeUInt32Field(Z, e.TotalDurationInUs >>> 0), t.writeInt32Field(Q, e.VolumeSampleCount | 0), t.writeBoolField(tt, e.IsFirst), t.writeFloat32Field(et, e.Volume), t.writeUInt32Field(rt, e.DurationInUs >>> 0), t.writeBinaryField(nt, e.Data), t.writeBoolField(it, e.IsKey), t.writeBoolField(st, e.IsLast);
|
|
548
|
-
}
|
|
549
|
-
function lt(e, t, r) {
|
|
550
|
-
const n = ut(e);
|
|
551
|
-
return B(J, n, x, t, r);
|
|
552
|
-
}
|
|
553
|
-
const N = 1, dt = 4194308, ht = 2079085407, ft = 3485914759;
|
|
554
|
-
function yt(e) {
|
|
555
|
-
const t = {};
|
|
556
|
-
return pt(t), e && Object.assign(t, e), t;
|
|
557
|
-
}
|
|
558
|
-
function pt(e) {
|
|
559
|
-
return e.Volume = 0, e.Count = 0, e;
|
|
560
|
-
}
|
|
561
|
-
function wt(e) {
|
|
562
|
-
const t = new p(N);
|
|
563
|
-
return mt(e, t), t.finish();
|
|
564
|
-
}
|
|
565
|
-
function mt(e, t) {
|
|
566
|
-
t.writeFloat32Field(ht, e.Volume), t.writeInt32Field(ft, e.Count | 0);
|
|
567
|
-
}
|
|
568
|
-
function It(e, t, r) {
|
|
569
|
-
const n = wt(e);
|
|
570
|
-
return B(dt, n, N, t, r);
|
|
571
|
-
}
|
|
572
|
-
const v = 1, gt = 4194305, Et = 1368629611, bt = 2431514951, Ut = 2914494629, At = 3284746250, Ft = 4101844078;
|
|
573
|
-
function Bt(e) {
|
|
574
|
-
const t = {};
|
|
575
|
-
return Ot(t), e && Object.assign(t, e), t;
|
|
576
|
-
}
|
|
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 St(e) {
|
|
581
|
-
const t = new p(v);
|
|
582
|
-
return Dt(e, t), t.finish();
|
|
583
|
-
}
|
|
584
|
-
function Dt(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
|
-
}
|
|
587
|
-
function _t(e, t, r) {
|
|
588
|
-
const n = St(e);
|
|
589
|
-
return B(gt, n, v, t, r);
|
|
590
|
-
}
|
|
591
|
-
const K = 1, Mt = 4194306;
|
|
592
|
-
function Rt(e) {
|
|
593
|
-
const t = {};
|
|
594
|
-
return e && Object.assign(t, e), t;
|
|
595
|
-
}
|
|
596
|
-
function Vt(e) {
|
|
597
|
-
return new p(K).finish();
|
|
598
|
-
}
|
|
599
|
-
function Lt(e, t, r) {
|
|
600
|
-
const n = Vt();
|
|
601
|
-
return B(Mt, n, K, t, r);
|
|
602
|
-
}
|
|
603
|
-
class Tt {
|
|
604
|
-
static getStorageForCapacity(t, r) {
|
|
605
|
-
const n = Int32Array.BYTES_PER_ELEMENT * 2, i = r.BYTES_PER_ELEMENT * t;
|
|
606
|
-
return new SharedArrayBuffer(n + i);
|
|
607
|
-
}
|
|
608
|
-
readWrite;
|
|
609
|
-
storage;
|
|
610
|
-
buf;
|
|
611
|
-
constructor(t, r) {
|
|
612
|
-
this.buf = t, this.readWrite = new Int32Array(t, 0, 2);
|
|
613
|
-
const n = Int32Array.BYTES_PER_ELEMENT * 2, i = (t.byteLength - n) / Float32Array.BYTES_PER_ELEMENT;
|
|
614
|
-
this.storage = new r(t, n, i);
|
|
615
|
-
}
|
|
616
|
-
get capacity() {
|
|
617
|
-
return this.storage.length;
|
|
618
|
-
}
|
|
619
|
-
flush() {
|
|
620
|
-
Atomics.store(this.readWrite, 0, 0), Atomics.store(this.readWrite, 1, 0);
|
|
621
|
-
}
|
|
622
|
-
availableRead() {
|
|
623
|
-
const t = Atomics.load(this.readWrite, 0), r = Atomics.load(this.readWrite, 1);
|
|
624
|
-
return r >= t ? r - t : this.capacity - (t - r);
|
|
625
|
-
}
|
|
626
|
-
availableWrite() {
|
|
627
|
-
return this.capacity - this.availableRead() - 1;
|
|
628
|
-
}
|
|
629
|
-
push(t) {
|
|
630
|
-
const r = Math.min(this.availableWrite(), t.length);
|
|
631
|
-
if (r <= 0)
|
|
632
|
-
return 0;
|
|
633
|
-
let n = Atomics.load(this.readWrite, 1);
|
|
634
|
-
const i = Math.min(r, this.capacity - n);
|
|
635
|
-
this.storage.set(t.subarray(0, i), n);
|
|
636
|
-
const s = r - i;
|
|
637
|
-
return s > 0 && this.storage.set(t.subarray(i, i + s), 0), n = (n + r) % this.capacity, Atomics.store(this.readWrite, 1, n), Atomics.notify(this.readWrite, 1), r;
|
|
638
|
-
}
|
|
639
|
-
pop(t) {
|
|
640
|
-
const r = Math.min(this.availableRead(), t.length);
|
|
641
|
-
if (r <= 0)
|
|
642
|
-
return 0;
|
|
643
|
-
let n = Atomics.load(this.readWrite, 0);
|
|
644
|
-
const i = Math.min(r, this.capacity - n);
|
|
645
|
-
t.set(this.storage.subarray(n, n + i), 0);
|
|
646
|
-
const s = r - i;
|
|
647
|
-
return s > 0 && t.set(this.storage.subarray(0, s), i), n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
|
|
648
|
-
}
|
|
649
|
-
skip(t) {
|
|
650
|
-
const r = Math.min(this.availableRead(), t);
|
|
651
|
-
if (r <= 0)
|
|
652
|
-
return 0;
|
|
653
|
-
let n = Atomics.load(this.readWrite, 0);
|
|
654
|
-
return n = (n + r) % this.capacity, Atomics.store(this.readWrite, 0, n), r;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
let Wt = 1;
|
|
658
|
-
function Pt(e, t) {
|
|
659
|
-
return `[${e}] ${t}`;
|
|
660
|
-
}
|
|
661
|
-
function U(e, t, r, n) {
|
|
662
|
-
if ((/* @__PURE__ */ new Date()).toISOString(), Wt <= e) {
|
|
663
|
-
const i = Pt(t, r);
|
|
664
|
-
switch (e) {
|
|
665
|
-
case 0:
|
|
666
|
-
console.debug(i, ...n);
|
|
667
|
-
break;
|
|
668
|
-
case 1:
|
|
669
|
-
console.info(i, ...n);
|
|
670
|
-
break;
|
|
671
|
-
case 2:
|
|
672
|
-
console.warn(i, ...n);
|
|
673
|
-
break;
|
|
674
|
-
case 3:
|
|
675
|
-
console.error(i, ...n);
|
|
676
|
-
break;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
function kt(e) {
|
|
681
|
-
return {
|
|
682
|
-
debug(t, ...r) {
|
|
683
|
-
U(0, e, t, r);
|
|
684
|
-
},
|
|
685
|
-
info(t, ...r) {
|
|
686
|
-
U(1, e, t, r);
|
|
687
|
-
},
|
|
688
|
-
warn(t, ...r) {
|
|
689
|
-
U(2, e, t, r);
|
|
690
|
-
},
|
|
691
|
-
error(t, ...r) {
|
|
692
|
-
U(3, e, t, r);
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
const Ct = 20, V = 32e3, xt = 5, L = 8e3, _ = kt("AudioCaptureWorker");
|
|
697
|
-
class Nt {
|
|
698
|
-
encoder = null;
|
|
699
|
-
isReady = !1;
|
|
700
|
-
sampleRate;
|
|
701
|
-
channels;
|
|
702
|
-
bitrate;
|
|
703
|
-
frameSize;
|
|
704
|
-
onOutput;
|
|
705
|
-
onError;
|
|
706
|
-
timestampUs = 0;
|
|
707
|
-
frameDurationUs;
|
|
708
|
-
constructor(t) {
|
|
709
|
-
this.sampleRate = t.sampleRate, this.channels = t.channels, this.bitrate = t.bitrate, this.frameSize = t.frameSize, this.frameDurationUs = Math.floor(this.frameSize * 1e6 / this.sampleRate), this.onOutput = t.onOutput, this.onError = t.onError;
|
|
710
|
-
}
|
|
711
|
-
async initialize() {
|
|
712
|
-
try {
|
|
713
|
-
const { OpusEncoder: t, OPUS_APPLICATION_VOIP: r, getOpusModule: n } = await import("./index-D2GAzJKe.js");
|
|
714
|
-
await n(), this.encoder = new t({
|
|
715
|
-
sampleRate: this.sampleRate,
|
|
716
|
-
channels: this.channels,
|
|
717
|
-
bitrate: this.bitrate,
|
|
718
|
-
application: r,
|
|
719
|
-
complexity: xt
|
|
720
|
-
}), await this.encoder.ready, this.isReady = !0;
|
|
721
|
-
} catch (t) {
|
|
722
|
-
this.onError(t instanceof Error ? t : new Error(String(t)));
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
encode(t) {
|
|
726
|
-
if (!(!this.isReady || !this.encoder))
|
|
727
|
-
try {
|
|
728
|
-
let r;
|
|
729
|
-
if (t instanceof Float32Array)
|
|
730
|
-
r = t;
|
|
731
|
-
else {
|
|
732
|
-
const i = t.numberOfFrames, s = t.numberOfChannels;
|
|
733
|
-
r = new Float32Array(i * s), t.copyTo(r, { planeIndex: 0, format: "f32" }), t.close();
|
|
734
|
-
}
|
|
735
|
-
const n = this.encoder.encodeAndCopy(r);
|
|
736
|
-
this.onOutput(n, this.timestampUs, this.frameDurationUs), this.timestampUs += this.frameDurationUs;
|
|
737
|
-
} catch (r) {
|
|
738
|
-
this.onError(r instanceof Error ? r : new Error(String(r)));
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
async flush() {
|
|
742
|
-
}
|
|
743
|
-
close() {
|
|
744
|
-
try {
|
|
745
|
-
this.encoder?.destroy();
|
|
746
|
-
} catch {
|
|
747
|
-
}
|
|
748
|
-
this.encoder = null, this.isReady = !1;
|
|
749
|
-
}
|
|
750
|
-
getBitrate() {
|
|
751
|
-
return this.bitrate;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
const T = (e) => self.postMessage(e);
|
|
755
|
-
let f = null;
|
|
756
|
-
function m(e, t) {
|
|
757
|
-
const r = e instanceof Error ? e : new Error(String(e));
|
|
758
|
-
T({ type: "error", captureId: t, error: { name: r.name, message: r.message, stack: r.stack } });
|
|
759
|
-
}
|
|
760
|
-
function vt(e) {
|
|
761
|
-
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
762
|
-
}
|
|
763
|
-
function S(e) {
|
|
764
|
-
if (!f)
|
|
765
|
-
return;
|
|
766
|
-
const t = vt(e);
|
|
767
|
-
f.postMessage({ type: "send", message: t }, [t]);
|
|
768
|
-
}
|
|
769
|
-
function Kt(e) {
|
|
770
|
-
if (e.length === 0)
|
|
771
|
-
return 0;
|
|
772
|
-
let t = 0;
|
|
773
|
-
for (let r = 0; r < e.length; r++)
|
|
774
|
-
t += Math.abs(e[r] ?? 0);
|
|
775
|
-
return t / e.length;
|
|
776
|
-
}
|
|
777
|
-
const d = /* @__PURE__ */ new Map();
|
|
778
|
-
let E = null;
|
|
779
|
-
function zt() {
|
|
780
|
-
E === null && (E = self.setInterval(() => {
|
|
781
|
-
for (const e of d.values())
|
|
782
|
-
if (!(e.transport !== "sab" || !e.ringBuffer || !e.ringTemp || e.stopped))
|
|
783
|
-
try {
|
|
784
|
-
const t = e.ringBuffer.pop(e.ringTemp);
|
|
785
|
-
if (t <= 0)
|
|
786
|
-
continue;
|
|
787
|
-
P(e, e.ringTemp.subarray(0, t));
|
|
788
|
-
} catch (t) {
|
|
789
|
-
m(t, e.captureId);
|
|
790
|
-
}
|
|
791
|
-
}, 10));
|
|
792
|
-
}
|
|
793
|
-
function Ht() {
|
|
794
|
-
if (E === null)
|
|
795
|
-
return;
|
|
796
|
-
let e = !1;
|
|
797
|
-
for (const t of d.values())
|
|
798
|
-
if (t.transport === "sab" && !t.stopped) {
|
|
799
|
-
e = !0;
|
|
800
|
-
break;
|
|
801
|
-
}
|
|
802
|
-
if (!e) {
|
|
803
|
-
try {
|
|
804
|
-
self.clearInterval(E);
|
|
805
|
-
} catch {
|
|
806
|
-
}
|
|
807
|
-
E = null;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
function W(e) {
|
|
811
|
-
if (e.stopped)
|
|
812
|
-
return;
|
|
813
|
-
if (!e.inSegment) {
|
|
814
|
-
e.pendingReadOffset = 0, e.pendingWriteOffset = 0, e.pendingSamples = 0;
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
const t = e.frameSize, r = e.frameBuffer, n = e.pendingBuffer.length;
|
|
818
|
-
for (; e.pendingSamples >= t; ) {
|
|
819
|
-
const i = e.pendingReadOffset;
|
|
820
|
-
if (i + t <= n)
|
|
821
|
-
r.set(e.pendingBuffer.subarray(i, i + t));
|
|
822
|
-
else {
|
|
823
|
-
const a = n - i;
|
|
824
|
-
r.set(e.pendingBuffer.subarray(i, n)), r.set(e.pendingBuffer.subarray(0, t - a), a);
|
|
825
|
-
}
|
|
826
|
-
e.pendingReadOffset = (i + t) % n, e.pendingSamples -= t;
|
|
827
|
-
const s = Kt(r);
|
|
828
|
-
S(It(yt({ Volume: s, Count: t }), e.senderId, { trackId: e.trackId }));
|
|
829
|
-
try {
|
|
830
|
-
if (e.useWasmEncoder)
|
|
831
|
-
e.encoder.encode(r);
|
|
832
|
-
else {
|
|
833
|
-
const a = new AudioData({
|
|
834
|
-
format: "f32",
|
|
835
|
-
sampleRate: e.sampleRate,
|
|
836
|
-
numberOfFrames: t,
|
|
837
|
-
numberOfChannels: e.channels,
|
|
838
|
-
timestamp: e.timestampUs,
|
|
839
|
-
data: r.buffer
|
|
840
|
-
});
|
|
841
|
-
e.encoder.encode(a), a.close();
|
|
842
|
-
}
|
|
843
|
-
} catch (a) {
|
|
844
|
-
m(a, e.captureId);
|
|
845
|
-
}
|
|
846
|
-
e.timestampUs += e.frameDurationUs;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
function P(e, t) {
|
|
850
|
-
if (e.stopped)
|
|
851
|
-
return;
|
|
852
|
-
const r = t.length;
|
|
853
|
-
if (r === 0)
|
|
854
|
-
return;
|
|
855
|
-
const n = e.pendingSamples + r;
|
|
856
|
-
if (n > e.pendingBuffer.length) {
|
|
857
|
-
const a = Math.max(n, e.pendingBuffer.length * 2), c = new Float32Array(a);
|
|
858
|
-
if (e.pendingSamples > 0) {
|
|
859
|
-
const l = e.pendingBuffer.length;
|
|
860
|
-
if (e.pendingReadOffset + e.pendingSamples <= l)
|
|
861
|
-
c.set(e.pendingBuffer.subarray(e.pendingReadOffset, e.pendingReadOffset + e.pendingSamples));
|
|
862
|
-
else {
|
|
863
|
-
const h = l - e.pendingReadOffset;
|
|
864
|
-
c.set(e.pendingBuffer.subarray(e.pendingReadOffset, l)), c.set(e.pendingBuffer.subarray(0, e.pendingSamples - h), h);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
e.pendingBuffer = c, e.pendingReadOffset = 0, e.pendingWriteOffset = e.pendingSamples;
|
|
868
|
-
}
|
|
869
|
-
const i = e.pendingBuffer.length, s = Math.min(r, i - e.pendingWriteOffset);
|
|
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);
|
|
871
|
-
}
|
|
872
|
-
function z(e, t, r, n, i = !0) {
|
|
873
|
-
const s = d.get(e.captureId);
|
|
874
|
-
if (!s || s.stopped || !s.inSegment && !s.segmentEndPending)
|
|
875
|
-
return;
|
|
876
|
-
const a = t.byteLength;
|
|
877
|
-
s.encoderOutputBuffer.length < a && (s.encoderOutputBuffer = new Uint8Array(Math.max(a, s.encoderOutputBuffer.length * 2))), s.encoderOutputBuffer.set(t);
|
|
878
|
-
const c = s.encoderOutputBuffer.subarray(0, a), l = s.segmentStartPending;
|
|
879
|
-
l && (s.segmentStartPending = !1);
|
|
880
|
-
const h = s.segmentEndPending;
|
|
881
|
-
h && (s.segmentEndPending = !1, s.inSegment = !1), S(
|
|
882
|
-
lt(
|
|
883
|
-
at({
|
|
884
|
-
Data: c,
|
|
885
|
-
IsKey: i,
|
|
886
|
-
IsFirst: l,
|
|
887
|
-
IsLast: h,
|
|
888
|
-
TimestampInUs: BigInt(Math.max(0, Math.round(r))),
|
|
889
|
-
DurationInUs: Math.max(0, Math.round(n)),
|
|
890
|
-
TotalDurationInUs: 0
|
|
891
|
-
}),
|
|
892
|
-
s.senderId,
|
|
893
|
-
{ trackId: s.trackId }
|
|
894
|
-
)
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
function $t(e) {
|
|
898
|
-
const t = Math.max(L, Math.floor(e.options?.bitrate ?? V)), r = new AudioEncoder({
|
|
899
|
-
output: (n) => {
|
|
900
|
-
const i = d.get(e.captureId);
|
|
901
|
-
if (!i)
|
|
902
|
-
return;
|
|
903
|
-
const s = n.byteLength;
|
|
904
|
-
i.encoderOutputBuffer.length < s && (i.encoderOutputBuffer = new Uint8Array(Math.max(s, i.encoderOutputBuffer.length * 2))), n.copyTo(i.encoderOutputBuffer), z(
|
|
905
|
-
i,
|
|
906
|
-
i.encoderOutputBuffer.subarray(0, s),
|
|
907
|
-
n.timestamp ?? i.timestampUs,
|
|
908
|
-
n.duration ?? i.frameDurationUs,
|
|
909
|
-
n.type === "key"
|
|
910
|
-
);
|
|
911
|
-
},
|
|
912
|
-
error: (n) => {
|
|
913
|
-
m(n, e.captureId);
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
return r.configure({
|
|
917
|
-
codec: "opus",
|
|
918
|
-
numberOfChannels: e.channels,
|
|
919
|
-
sampleRate: e.sampleRate,
|
|
920
|
-
bitrate: t,
|
|
921
|
-
bitrateMode: "constant",
|
|
922
|
-
opus: {
|
|
923
|
-
application: "lowdelay",
|
|
924
|
-
signal: "voice"
|
|
925
|
-
}
|
|
926
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
927
|
-
}), r;
|
|
928
|
-
}
|
|
929
|
-
function jt(e) {
|
|
930
|
-
const t = Math.max(L, Math.floor(e.options?.bitrate ?? V));
|
|
931
|
-
return new Nt({
|
|
932
|
-
sampleRate: e.sampleRate,
|
|
933
|
-
channels: e.channels,
|
|
934
|
-
bitrate: t,
|
|
935
|
-
frameSize: e.frameSize,
|
|
936
|
-
onOutput: (r, n, i) => {
|
|
937
|
-
const s = d.get(e.captureId);
|
|
938
|
-
s && z(s, r, n, i, !0);
|
|
939
|
-
},
|
|
940
|
-
onError: (r) => {
|
|
941
|
-
m(r, e.captureId);
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
async function Yt() {
|
|
946
|
-
if (typeof AudioEncoder > "u")
|
|
947
|
-
return !1;
|
|
948
|
-
try {
|
|
949
|
-
return (await AudioEncoder.isConfigSupported({
|
|
950
|
-
codec: "opus",
|
|
951
|
-
numberOfChannels: 1,
|
|
952
|
-
sampleRate: 48e3
|
|
953
|
-
})).supported === !0;
|
|
954
|
-
} catch {
|
|
955
|
-
return !1;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
async function qt(e) {
|
|
959
|
-
if (!f)
|
|
960
|
-
throw new Error("Audio capture worker missing send port");
|
|
961
|
-
if (d.has(e.captureId))
|
|
962
|
-
return;
|
|
963
|
-
const t = Math.max(8e3, Math.floor(e.sampleRate)), r = Math.max(1, Math.floor(e.channels)), n = Math.max(1, Math.floor(t * Ct / 1e3)), i = Math.max(1, Math.floor(n * 1e6 / t)), s = n * 4, a = {
|
|
964
|
-
captureId: e.captureId,
|
|
965
|
-
senderId: e.senderId,
|
|
966
|
-
trackId: e.trackId,
|
|
967
|
-
sampleRate: t,
|
|
968
|
-
channels: r,
|
|
969
|
-
frameSize: n,
|
|
970
|
-
frameDurationUs: i,
|
|
971
|
-
timestampUs: 0,
|
|
972
|
-
sentFirst: !1,
|
|
973
|
-
stopped: !1,
|
|
974
|
-
transport: e.transport,
|
|
975
|
-
ringBuffer: null,
|
|
976
|
-
ringTemp: null,
|
|
977
|
-
pendingBuffer: new Float32Array(s),
|
|
978
|
-
pendingReadOffset: 0,
|
|
979
|
-
pendingWriteOffset: 0,
|
|
980
|
-
pendingSamples: 0,
|
|
981
|
-
frameBuffer: new Float32Array(n),
|
|
982
|
-
encoderOutputBuffer: new Uint8Array(1024),
|
|
983
|
-
inSegment: !1,
|
|
984
|
-
segmentStartPending: !1,
|
|
985
|
-
segmentEndPending: !1,
|
|
986
|
-
options: e.options
|
|
987
|
-
}, l = (e.options?.preferWebCodecs ?? !0) && await Yt();
|
|
988
|
-
let h, I = !1;
|
|
989
|
-
const g = Math.max(L, Math.floor(e.options?.bitrate ?? V));
|
|
990
|
-
if (l)
|
|
991
|
-
h = $t(a), _.info(
|
|
992
|
-
`Audio capture started: encoder=WebCodecs, sampleRate=${t}Hz, channels=${r}, bitrate=${g}bps`
|
|
993
|
-
);
|
|
994
|
-
else {
|
|
995
|
-
const u = jt(a);
|
|
996
|
-
await u.initialize(), h = u, I = !0, _.info(
|
|
997
|
-
`Audio capture started: encoder=WASM Opus, sampleRate=${t}Hz, channels=${r}, bitrate=${g}bps`
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
const y = {
|
|
1001
|
-
...a,
|
|
1002
|
-
encoder: h,
|
|
1003
|
-
useWasmEncoder: I
|
|
1004
|
-
};
|
|
1005
|
-
if (e.transport === "sab") {
|
|
1006
|
-
if (!e.sharedArrayBuffer)
|
|
1007
|
-
throw new Error("Missing SharedArrayBuffer for sab transport");
|
|
1008
|
-
const u = new Tt(e.sharedArrayBuffer, Float32Array);
|
|
1009
|
-
y.ringBuffer = u, y.ringTemp = new Float32Array(Math.max(y.frameSize * 4, 4096)), zt();
|
|
1010
|
-
}
|
|
1011
|
-
d.set(e.captureId, y), S(
|
|
1012
|
-
_t(
|
|
1013
|
-
Bt({
|
|
1014
|
-
Description: `mic:${e.captureId}`,
|
|
1015
|
-
Codec: R.Opus,
|
|
1016
|
-
SampleRate: t,
|
|
1017
|
-
Channels: r,
|
|
1018
|
-
BitDepth: 32
|
|
1019
|
-
}),
|
|
1020
|
-
e.senderId,
|
|
1021
|
-
{ trackId: e.trackId }
|
|
1022
|
-
)
|
|
1023
|
-
), T({ type: "started", captureId: e.captureId, sampleRate: t, channels: r });
|
|
1024
|
-
}
|
|
1025
|
-
async function H(e) {
|
|
1026
|
-
const t = d.get(e);
|
|
1027
|
-
if (t) {
|
|
1028
|
-
t.stopped = !0, d.delete(e);
|
|
1029
|
-
try {
|
|
1030
|
-
W(t);
|
|
1031
|
-
} catch {
|
|
1032
|
-
}
|
|
1033
|
-
try {
|
|
1034
|
-
await t.encoder.flush();
|
|
1035
|
-
} catch {
|
|
1036
|
-
}
|
|
1037
|
-
try {
|
|
1038
|
-
t.encoder.close();
|
|
1039
|
-
} catch {
|
|
1040
|
-
}
|
|
1041
|
-
S(Lt(Rt({}), t.senderId, { trackId: t.trackId })), T({ type: "stopped", captureId: e }), Ht();
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
function Gt(e) {
|
|
1045
|
-
const t = d.get(e);
|
|
1046
|
-
!t || t.stopped || (t.inSegment = !0, t.segmentStartPending = !0);
|
|
1047
|
-
}
|
|
1048
|
-
function Jt(e) {
|
|
1049
|
-
const t = d.get(e);
|
|
1050
|
-
if (!(!t || t.stopped || !t.inSegment) && (t.segmentEndPending = !0, W(t), t.segmentEndPending && !t.stopped)) {
|
|
1051
|
-
const r = t.frameSize - t.pendingSamples;
|
|
1052
|
-
if (r > 0) {
|
|
1053
|
-
const n = new Float32Array(r);
|
|
1054
|
-
P(t, n);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
function Xt() {
|
|
1059
|
-
for (const e of Array.from(d.keys()))
|
|
1060
|
-
H(e);
|
|
1061
|
-
if (f) {
|
|
1062
|
-
try {
|
|
1063
|
-
f.close();
|
|
1064
|
-
} catch {
|
|
1065
|
-
}
|
|
1066
|
-
f = null;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
self.addEventListener("message", (e) => {
|
|
1070
|
-
const t = e.data;
|
|
1071
|
-
if (t.type === "attachSendPort") {
|
|
1072
|
-
if (f)
|
|
1073
|
-
try {
|
|
1074
|
-
f.close();
|
|
1075
|
-
} catch {
|
|
1076
|
-
}
|
|
1077
|
-
f = t.port;
|
|
1078
|
-
try {
|
|
1079
|
-
f.start?.();
|
|
1080
|
-
} catch {
|
|
1081
|
-
}
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
if (t.type === "start") {
|
|
1085
|
-
qt(t).catch((r) => {
|
|
1086
|
-
m(r, t.captureId);
|
|
1087
|
-
});
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
if (t.type === "pcm") {
|
|
1091
|
-
const r = d.get(t.captureId);
|
|
1092
|
-
if (!r || r.stopped)
|
|
1093
|
-
return;
|
|
1094
|
-
P(r, t.pcm);
|
|
1095
|
-
return;
|
|
1096
|
-
}
|
|
1097
|
-
if (t.type === "stop") {
|
|
1098
|
-
H(t.captureId).catch((r) => {
|
|
1099
|
-
_.warn(`Failed to stop audio capture: ${r}`), m(r, t.captureId);
|
|
1100
|
-
});
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
if (t.type === "startSegment") {
|
|
1104
|
-
Gt(t.captureId);
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
if (t.type === "endSegment") {
|
|
1108
|
-
Jt(t.captureId);
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
t.type === "dispose" && Xt();
|
|
1112
|
-
});
|