@ikonai/sdk 0.0.28 → 0.0.29
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-fxRKlQJF.js +932 -0
- package/assets/audio-playback-worker-C4Eyhfrh.js +1323 -0
- package/assets/protocol-worker-E7o-6_bZ.js +1422 -0
- package/assets/video-capture-worker-CTRX9PKp.js +843 -0
- package/assets/video-playback-worker-CIuL9Crw.js +875 -0
- package/channel/channel-manager.d.ts +1 -1
- package/channel/channel.d.ts +1 -1
- package/client/endpoint-selector.d.ts +1 -1
- package/client/ikon-client-config.d.ts +4 -9
- package/client/ikon-client.d.ts +5 -1
- package/connection/authenticator.d.ts +1 -1
- package/functions/function-registry.d.ts +1 -1
- package/functions/index.d.ts +1 -1
- package/functions/types.d.ts +1 -1
- package/index.d.ts +8 -8
- package/index.js +3878 -15843
- package/media/audio-constants.d.ts +20 -0
- package/media/ikon-audio-playback.d.ts +1 -1
- package/media/ikon-video-playback.d.ts +0 -8
- package/package.json +2 -1
- package/transport/transport.d.ts +1 -1
- package/transport/web-socket-transport.d.ts +6 -1
- package/transport/web-transport-transport.d.ts +17 -2
- package/{media/audio-worker-messages.d.ts → worker/audio-playback-worker.d.ts} +10 -10
- package/worker/video-playback-worker.d.ts +59 -0
- package/assets/audio-capture-worker-C5hNMTF7.js +0 -14835
- package/assets/audio-worker-Ci3tYX2B.js +0 -15121
- package/assets/protocol-worker-DXLojSe-.js +0 -15288
- package/assets/video-capture-worker-OBl3bsvx.js +0 -14733
- package/assets/video-worker-BoOfB8qz.js +0 -14761
- package/worker/audio-worker.d.ts +0 -1
- package/worker/video-worker.d.ts +0 -1
|
@@ -0,0 +1,1323 @@
|
|
|
1
|
+
function st(t) {
|
|
2
|
+
if (t.length < 8)
|
|
3
|
+
throw new Error("Protocol message too short");
|
|
4
|
+
return (t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24) >>> 0;
|
|
5
|
+
}
|
|
6
|
+
function z(t) {
|
|
7
|
+
const e = O(t), r = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
8
|
+
if (e.length < 27)
|
|
9
|
+
throw new Error("Protocol payload too short");
|
|
10
|
+
const s = r.getUint32(0, !0), n = r.getUint32(4, !0), a = r.getUint32(8, !0), i = r.getUint32(12, !0), o = r.getUint32(16, !0), _ = r.getUint32(20, !0), h = r.getUint8(24), E = r.getUint8(25), I = r.getUint8(26);
|
|
11
|
+
if (27 + _ * 4 > e.length)
|
|
12
|
+
throw new Error("Protocol header exceeds payload length");
|
|
13
|
+
const c = [];
|
|
14
|
+
let M = 27;
|
|
15
|
+
for (let Y = 0; Y < _; Y++)
|
|
16
|
+
c.push(r.getUint32(M, !0)), M += 4;
|
|
17
|
+
return {
|
|
18
|
+
length: s,
|
|
19
|
+
opcode: n,
|
|
20
|
+
senderId: a,
|
|
21
|
+
trackId: i,
|
|
22
|
+
sequenceId: o,
|
|
23
|
+
targetIds: c,
|
|
24
|
+
payloadVersion: h,
|
|
25
|
+
payloadType: E,
|
|
26
|
+
flags: I
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function j(t, e, r) {
|
|
30
|
+
const s = O(t), n = z(s);
|
|
31
|
+
if (e !== void 0 && n.opcode !== e)
|
|
32
|
+
throw new Error(`Unexpected opcode ${n.opcode}`);
|
|
33
|
+
if (n.payloadVersion !== r)
|
|
34
|
+
throw new Error(`Unexpected payload version ${n.payloadVersion}`);
|
|
35
|
+
if (n.payloadType !== 8)
|
|
36
|
+
throw new Error(`Unexpected payload type ${n.payloadType}`);
|
|
37
|
+
const a = 27 + n.targetIds.length * 4;
|
|
38
|
+
return s.subarray(a, n.length);
|
|
39
|
+
}
|
|
40
|
+
var L = /* @__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))(L || {});
|
|
41
|
+
const nt = 161, it = 162;
|
|
42
|
+
new TextEncoder();
|
|
43
|
+
const at = new TextDecoder("utf-8", { fatal: !0 });
|
|
44
|
+
class w {
|
|
45
|
+
constructor(e, r, s) {
|
|
46
|
+
this.buffer = e, this.version = r, this.offset = s, this.end = e.length - 1;
|
|
47
|
+
}
|
|
48
|
+
offset;
|
|
49
|
+
end;
|
|
50
|
+
static create(e) {
|
|
51
|
+
const r = O(e);
|
|
52
|
+
if (r.length < 2)
|
|
53
|
+
throw new Error("Teleport payload too short");
|
|
54
|
+
if (r[0] !== nt || r[r.length - 1] !== it)
|
|
55
|
+
throw new Error("Teleport object missing markers");
|
|
56
|
+
const s = { offset: 1 }, n = f(r, s, "InvalidLength");
|
|
57
|
+
return new w(r, n, s.offset);
|
|
58
|
+
}
|
|
59
|
+
next() {
|
|
60
|
+
if (this.offset >= this.end)
|
|
61
|
+
return null;
|
|
62
|
+
if (this.offset + 5 > this.buffer.length)
|
|
63
|
+
throw new Error("Teleport object truncated");
|
|
64
|
+
const e = lt(this.buffer, this.offset);
|
|
65
|
+
this.offset += 4;
|
|
66
|
+
const r = this.buffer[this.offset++], s = r >> 4 & 15;
|
|
67
|
+
if ((r & 15) !== 0)
|
|
68
|
+
throw new Error("Teleport field flags must be zero");
|
|
69
|
+
const n = y(s);
|
|
70
|
+
let a;
|
|
71
|
+
if (n >= 0)
|
|
72
|
+
u(this.buffer, this.offset, n), a = this.buffer.subarray(this.offset, this.offset + n), this.offset += n;
|
|
73
|
+
else {
|
|
74
|
+
const i = { offset: this.offset }, o = f(this.buffer, i, "InvalidLength");
|
|
75
|
+
u(this.buffer, i.offset, o), a = this.buffer.subarray(i.offset, i.offset + o), this.offset = i.offset + o;
|
|
76
|
+
}
|
|
77
|
+
return new ot(e, s, a);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class C {
|
|
81
|
+
constructor(e, r) {
|
|
82
|
+
this.type = e, this.payload = r;
|
|
83
|
+
}
|
|
84
|
+
asInt32() {
|
|
85
|
+
return this.ensureType(
|
|
86
|
+
3
|
|
87
|
+
/* Int32 */
|
|
88
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getInt32(0, !0);
|
|
89
|
+
}
|
|
90
|
+
asUInt32() {
|
|
91
|
+
return this.ensureType(
|
|
92
|
+
5
|
|
93
|
+
/* UInt32 */
|
|
94
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getUint32(0, !0);
|
|
95
|
+
}
|
|
96
|
+
asInt64() {
|
|
97
|
+
return this.ensureType(
|
|
98
|
+
4
|
|
99
|
+
/* Int64 */
|
|
100
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigInt64(0, !0);
|
|
101
|
+
}
|
|
102
|
+
asUInt64() {
|
|
103
|
+
return this.ensureType(
|
|
104
|
+
6
|
|
105
|
+
/* UInt64 */
|
|
106
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getBigUint64(0, !0);
|
|
107
|
+
}
|
|
108
|
+
asFloat32() {
|
|
109
|
+
return this.ensureType(
|
|
110
|
+
7
|
|
111
|
+
/* Float32 */
|
|
112
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 4).getFloat32(0, !0);
|
|
113
|
+
}
|
|
114
|
+
asFloat64() {
|
|
115
|
+
return this.ensureType(
|
|
116
|
+
8
|
|
117
|
+
/* Float64 */
|
|
118
|
+
), new DataView(this.payload.buffer, this.payload.byteOffset, 8).getFloat64(0, !0);
|
|
119
|
+
}
|
|
120
|
+
asBool() {
|
|
121
|
+
return this.ensureType(
|
|
122
|
+
2
|
|
123
|
+
/* Bool */
|
|
124
|
+
), this.payload.length > 0 && this.payload[0] !== 0;
|
|
125
|
+
}
|
|
126
|
+
asBinary() {
|
|
127
|
+
return this.ensureType(
|
|
128
|
+
13
|
|
129
|
+
/* Binary */
|
|
130
|
+
), this.payload;
|
|
131
|
+
}
|
|
132
|
+
asUtf8() {
|
|
133
|
+
return this.ensureType(
|
|
134
|
+
12
|
|
135
|
+
/* String */
|
|
136
|
+
), this.payload;
|
|
137
|
+
}
|
|
138
|
+
asString() {
|
|
139
|
+
return this.ensureType(
|
|
140
|
+
12
|
|
141
|
+
/* String */
|
|
142
|
+
), at.decode(this.payload);
|
|
143
|
+
}
|
|
144
|
+
asGuid() {
|
|
145
|
+
return this.ensureType(
|
|
146
|
+
14
|
|
147
|
+
/* Guid */
|
|
148
|
+
), l.fromBytes(this.payload);
|
|
149
|
+
}
|
|
150
|
+
asObject() {
|
|
151
|
+
return this.ensureType(
|
|
152
|
+
11
|
|
153
|
+
/* Object */
|
|
154
|
+
), w.create(this.payload);
|
|
155
|
+
}
|
|
156
|
+
asArray() {
|
|
157
|
+
return this.ensureType(
|
|
158
|
+
9
|
|
159
|
+
/* Array */
|
|
160
|
+
), V.create(this.payload);
|
|
161
|
+
}
|
|
162
|
+
asDictionary() {
|
|
163
|
+
return this.ensureType(
|
|
164
|
+
10
|
|
165
|
+
/* Dict */
|
|
166
|
+
), k.create(this.payload);
|
|
167
|
+
}
|
|
168
|
+
ensureType(e) {
|
|
169
|
+
if (this.type !== e)
|
|
170
|
+
throw new Error(`Teleport value has type ${L[this.type]}, expected ${L[e]}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
class ot extends C {
|
|
174
|
+
constructor(e, r, s) {
|
|
175
|
+
super(r, s), this.fieldId = e;
|
|
176
|
+
}
|
|
177
|
+
get isNull() {
|
|
178
|
+
return this.type === 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
class V {
|
|
182
|
+
payload;
|
|
183
|
+
elementType;
|
|
184
|
+
count;
|
|
185
|
+
offset;
|
|
186
|
+
index = 0;
|
|
187
|
+
constructor(e) {
|
|
188
|
+
if (this.payload = e, e.length === 0)
|
|
189
|
+
throw new Error("Array payload too short");
|
|
190
|
+
const r = e[0];
|
|
191
|
+
if (this.elementType = r >> 4 & 15, (r & 15) !== 0)
|
|
192
|
+
throw new Error("Array flags must be zero");
|
|
193
|
+
const s = { offset: 1 };
|
|
194
|
+
this.count = f(e, s, "ArrayMalformed"), this.offset = s.offset;
|
|
195
|
+
}
|
|
196
|
+
static create(e) {
|
|
197
|
+
return new V(O(e));
|
|
198
|
+
}
|
|
199
|
+
next() {
|
|
200
|
+
if (this.index >= this.count) {
|
|
201
|
+
if (this.offset !== this.payload.length)
|
|
202
|
+
throw new Error("Array payload contains trailing data");
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const e = this.readValue();
|
|
206
|
+
return this.index++, e;
|
|
207
|
+
}
|
|
208
|
+
readValue() {
|
|
209
|
+
switch (this.elementType) {
|
|
210
|
+
case 3:
|
|
211
|
+
case 5:
|
|
212
|
+
case 7:
|
|
213
|
+
case 8:
|
|
214
|
+
case 2:
|
|
215
|
+
case 4:
|
|
216
|
+
case 6:
|
|
217
|
+
case 14: {
|
|
218
|
+
const e = y(this.elementType);
|
|
219
|
+
u(this.payload, this.offset, e);
|
|
220
|
+
const r = this.payload.subarray(this.offset, this.offset + e);
|
|
221
|
+
return this.offset += e, new P(this.elementType, r);
|
|
222
|
+
}
|
|
223
|
+
case 12:
|
|
224
|
+
case 13: {
|
|
225
|
+
const e = { offset: this.offset }, r = f(this.payload, e, "ArrayMalformed");
|
|
226
|
+
u(this.payload, e.offset, r);
|
|
227
|
+
const s = this.payload.subarray(e.offset, e.offset + r);
|
|
228
|
+
return this.offset = e.offset + r, new P(this.elementType, s);
|
|
229
|
+
}
|
|
230
|
+
case 11: {
|
|
231
|
+
const e = { offset: this.offset }, r = f(this.payload, e, "ArrayMalformed");
|
|
232
|
+
u(this.payload, e.offset, r);
|
|
233
|
+
const s = this.payload.subarray(e.offset, e.offset + r);
|
|
234
|
+
return this.offset = e.offset + r, new P(11, s);
|
|
235
|
+
}
|
|
236
|
+
case 9: {
|
|
237
|
+
const e = v(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
|
|
238
|
+
return this.offset += e, new P(9, r);
|
|
239
|
+
}
|
|
240
|
+
case 10: {
|
|
241
|
+
const e = x(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
|
|
242
|
+
return this.offset += e, new P(10, r);
|
|
243
|
+
}
|
|
244
|
+
default:
|
|
245
|
+
throw new Error(`Unsupported array element type ${L[this.elementType]}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
class P extends C {
|
|
250
|
+
constructor(e, r) {
|
|
251
|
+
super(e, r);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
class k {
|
|
255
|
+
payload;
|
|
256
|
+
keyType;
|
|
257
|
+
valueType;
|
|
258
|
+
count;
|
|
259
|
+
offset;
|
|
260
|
+
index = 0;
|
|
261
|
+
constructor(e) {
|
|
262
|
+
if (this.payload = e, e.length < 2)
|
|
263
|
+
throw new Error("Dictionary payload too short");
|
|
264
|
+
if (this.keyType = e[0] >> 4 & 15, this.valueType = e[1] >> 4 & 15, (e[0] & 15) !== 0 || (e[1] & 15) !== 0)
|
|
265
|
+
throw new Error("Dictionary key/value flags must be zero");
|
|
266
|
+
$(this.keyType);
|
|
267
|
+
const r = { offset: 2 };
|
|
268
|
+
this.count = f(e, r, "DictMalformed"), this.offset = r.offset;
|
|
269
|
+
}
|
|
270
|
+
static create(e) {
|
|
271
|
+
return new k(O(e));
|
|
272
|
+
}
|
|
273
|
+
next() {
|
|
274
|
+
if (this.index >= this.count) {
|
|
275
|
+
if (this.offset !== this.payload.length)
|
|
276
|
+
throw new Error("Dictionary payload contains trailing data");
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
const e = this.readKey(), r = this.readValue();
|
|
280
|
+
return this.index++, new _t(e, r);
|
|
281
|
+
}
|
|
282
|
+
readKey() {
|
|
283
|
+
const e = y(this.keyType);
|
|
284
|
+
if (e >= 0) {
|
|
285
|
+
u(this.payload, this.offset, e);
|
|
286
|
+
const r = this.payload.subarray(this.offset, this.offset + e);
|
|
287
|
+
return this.offset += e, new C(this.keyType, r);
|
|
288
|
+
}
|
|
289
|
+
if (this.keyType === 12 || this.keyType === 13) {
|
|
290
|
+
const r = { offset: this.offset }, s = f(this.payload, r, "DictMalformed");
|
|
291
|
+
u(this.payload, r.offset, s);
|
|
292
|
+
const n = this.payload.subarray(r.offset, r.offset + s);
|
|
293
|
+
return this.offset = r.offset + s, new C(this.keyType, n);
|
|
294
|
+
}
|
|
295
|
+
throw new Error("Unsupported dictionary key type");
|
|
296
|
+
}
|
|
297
|
+
readValue() {
|
|
298
|
+
switch (this.valueType) {
|
|
299
|
+
case 12:
|
|
300
|
+
case 13: {
|
|
301
|
+
const e = { offset: this.offset }, r = f(this.payload, e, "DictMalformed");
|
|
302
|
+
u(this.payload, e.offset, r);
|
|
303
|
+
const s = this.payload.subarray(e.offset, e.offset + r);
|
|
304
|
+
return this.offset = e.offset + r, new C(this.valueType, s);
|
|
305
|
+
}
|
|
306
|
+
case 11: {
|
|
307
|
+
const e = { offset: this.offset }, r = f(this.payload, e, "DictMalformed");
|
|
308
|
+
u(this.payload, e.offset, r);
|
|
309
|
+
const s = this.payload.subarray(e.offset, e.offset + r);
|
|
310
|
+
return this.offset = e.offset + r, new C(11, s);
|
|
311
|
+
}
|
|
312
|
+
case 9: {
|
|
313
|
+
const e = v(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
|
|
314
|
+
return this.offset += e, new C(9, r);
|
|
315
|
+
}
|
|
316
|
+
case 10: {
|
|
317
|
+
const e = x(this.payload, this.offset), r = this.payload.subarray(this.offset, this.offset + e);
|
|
318
|
+
return this.offset += e, new C(10, r);
|
|
319
|
+
}
|
|
320
|
+
case 3:
|
|
321
|
+
case 5:
|
|
322
|
+
case 7:
|
|
323
|
+
case 8:
|
|
324
|
+
case 2:
|
|
325
|
+
case 4:
|
|
326
|
+
case 6:
|
|
327
|
+
case 14:
|
|
328
|
+
case 1: {
|
|
329
|
+
const e = y(this.valueType);
|
|
330
|
+
u(this.payload, this.offset, e);
|
|
331
|
+
const r = this.payload.subarray(this.offset, this.offset + e);
|
|
332
|
+
return this.offset += e, new C(this.valueType, r);
|
|
333
|
+
}
|
|
334
|
+
default:
|
|
335
|
+
throw new Error(`Unsupported dictionary value type ${L[this.valueType]}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
class _t {
|
|
340
|
+
constructor(e, r) {
|
|
341
|
+
this.key = e, this.value = r;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
class l {
|
|
345
|
+
constructor(e) {
|
|
346
|
+
this.bytes = e;
|
|
347
|
+
}
|
|
348
|
+
static fromString(e) {
|
|
349
|
+
if (!e)
|
|
350
|
+
throw new Error("Guid string is empty");
|
|
351
|
+
const r = e.replace(/-/g, "");
|
|
352
|
+
if (r.length !== 32)
|
|
353
|
+
throw new Error("Guid string must be 32 hex characters");
|
|
354
|
+
const s = new Uint8Array(16), n = l.parseHexSlice(r, 0, 8), a = l.parseHexSlice(r, 8, 4), i = l.parseHexSlice(r, 12, 4);
|
|
355
|
+
l.writeUInt32LE(s, 0, n), l.writeUInt16LE(s, 4, a), l.writeUInt16LE(s, 6, i);
|
|
356
|
+
for (let o = 0; o < 8; o++)
|
|
357
|
+
s[8 + o] = l.parseHexSlice(r, 16 + o * 2, 2);
|
|
358
|
+
return new l(s);
|
|
359
|
+
}
|
|
360
|
+
static fromBytes(e) {
|
|
361
|
+
if (e.length !== 16)
|
|
362
|
+
throw new Error("Guid byte array must be 16 bytes");
|
|
363
|
+
return new l(Uint8Array.from(e));
|
|
364
|
+
}
|
|
365
|
+
static createZero() {
|
|
366
|
+
return new l(new Uint8Array(16));
|
|
367
|
+
}
|
|
368
|
+
static createRandom() {
|
|
369
|
+
const e = new Uint8Array(16), r = globalThis.crypto;
|
|
370
|
+
if (r?.getRandomValues)
|
|
371
|
+
r.getRandomValues(e);
|
|
372
|
+
else
|
|
373
|
+
for (let s = 0; s < e.length; s++)
|
|
374
|
+
e[s] = Math.floor(Math.random() * 256);
|
|
375
|
+
return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new l(e);
|
|
376
|
+
}
|
|
377
|
+
toString() {
|
|
378
|
+
const e = this.bytes;
|
|
379
|
+
return [
|
|
380
|
+
l.toHex(l.readUInt32LE(e, 0), 8),
|
|
381
|
+
l.toHex(l.readUInt16LE(e, 4), 4),
|
|
382
|
+
l.toHex(l.readUInt16LE(e, 6), 4),
|
|
383
|
+
K(e.subarray(8, 10)),
|
|
384
|
+
K(e.subarray(10, 16))
|
|
385
|
+
].join("-");
|
|
386
|
+
}
|
|
387
|
+
asBytes() {
|
|
388
|
+
return this.bytes.slice();
|
|
389
|
+
}
|
|
390
|
+
static parseHexSlice(e, r, s) {
|
|
391
|
+
const n = e.substr(r, s), a = Number.parseInt(n, 16);
|
|
392
|
+
if (Number.isNaN(a))
|
|
393
|
+
throw new Error("Guid string contains invalid characters");
|
|
394
|
+
return a >>> 0;
|
|
395
|
+
}
|
|
396
|
+
static writeUInt32LE(e, r, s) {
|
|
397
|
+
const n = s >>> 0;
|
|
398
|
+
e[r] = n & 255, e[r + 1] = n >>> 8 & 255, e[r + 2] = n >>> 16 & 255, e[r + 3] = n >>> 24 & 255;
|
|
399
|
+
}
|
|
400
|
+
static writeUInt16LE(e, r, s) {
|
|
401
|
+
const n = s & 65535;
|
|
402
|
+
e[r] = n & 255, e[r + 1] = n >>> 8 & 255;
|
|
403
|
+
}
|
|
404
|
+
static readUInt32LE(e, r) {
|
|
405
|
+
return (e[r] | e[r + 1] << 8 | e[r + 2] << 16 | e[r + 3] << 24) >>> 0;
|
|
406
|
+
}
|
|
407
|
+
static readUInt16LE(e, r) {
|
|
408
|
+
return (e[r] | e[r + 1] << 8) & 65535;
|
|
409
|
+
}
|
|
410
|
+
static toHex(e, r) {
|
|
411
|
+
return (e >>> 0).toString(16).padStart(r, "0");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function f(t, e, r) {
|
|
415
|
+
if (e.offset >= t.length)
|
|
416
|
+
throw new Error(r);
|
|
417
|
+
let s = 0, n = 0, a = 0;
|
|
418
|
+
for (; e.offset < t.length; ) {
|
|
419
|
+
const i = t[e.offset++];
|
|
420
|
+
if (a++, s |= (i & 127) << n, (i & 128) === 0) {
|
|
421
|
+
if (a !== Et(s))
|
|
422
|
+
throw new Error("Teleport VarUInt is not canonical");
|
|
423
|
+
return s >>> 0;
|
|
424
|
+
}
|
|
425
|
+
if (n += 7, n >= 35)
|
|
426
|
+
throw new Error("Teleport VarUInt exceeds 32-bit range");
|
|
427
|
+
}
|
|
428
|
+
throw new Error(r);
|
|
429
|
+
}
|
|
430
|
+
function Et(t) {
|
|
431
|
+
return t < 128 ? 1 : t < 16384 ? 2 : t < 2097152 ? 3 : t < 268435456 ? 4 : 5;
|
|
432
|
+
}
|
|
433
|
+
function y(t) {
|
|
434
|
+
switch (t) {
|
|
435
|
+
case 3:
|
|
436
|
+
case 5:
|
|
437
|
+
case 7:
|
|
438
|
+
return 4;
|
|
439
|
+
case 4:
|
|
440
|
+
case 6:
|
|
441
|
+
case 8:
|
|
442
|
+
return 8;
|
|
443
|
+
case 14:
|
|
444
|
+
return 16;
|
|
445
|
+
case 2:
|
|
446
|
+
return 1;
|
|
447
|
+
case 1:
|
|
448
|
+
return 0;
|
|
449
|
+
default:
|
|
450
|
+
return -1;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function $(t) {
|
|
454
|
+
if (t === 9 || t === 11 || t === 10 || t === 1)
|
|
455
|
+
throw new Error("Dictionary keys must be primitive Teleport types");
|
|
456
|
+
}
|
|
457
|
+
function u(t, e, r) {
|
|
458
|
+
if (e < 0 || r < 0 || e + r > t.length)
|
|
459
|
+
throw new Error("Teleport payload exceeds bounds");
|
|
460
|
+
}
|
|
461
|
+
function lt(t, e) {
|
|
462
|
+
return (t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24) >>> 0;
|
|
463
|
+
}
|
|
464
|
+
function v(t, e) {
|
|
465
|
+
if (e >= t.length)
|
|
466
|
+
throw new Error("Array payload exceeds bounds");
|
|
467
|
+
const r = t[e], s = r >> 4 & 15;
|
|
468
|
+
if ((r & 15) !== 0)
|
|
469
|
+
throw new Error("Array flags must be zero");
|
|
470
|
+
const n = { offset: e + 1 }, a = f(t, n, "ArrayMalformed"), i = y(s);
|
|
471
|
+
if (i >= 0) {
|
|
472
|
+
const _ = i * a;
|
|
473
|
+
return u(t, n.offset, _), n.offset + _ - e;
|
|
474
|
+
}
|
|
475
|
+
let o = n.offset;
|
|
476
|
+
for (let _ = 0; _ < a; _++)
|
|
477
|
+
o = G(s, t, o, "ArrayMalformed");
|
|
478
|
+
return o - e;
|
|
479
|
+
}
|
|
480
|
+
function x(t, e) {
|
|
481
|
+
if (e + 2 > t.length)
|
|
482
|
+
throw new Error("Dictionary payload too short");
|
|
483
|
+
const r = t[e] >> 4 & 15, s = t[e + 1] >> 4 & 15;
|
|
484
|
+
if ((t[e] & 15) !== 0 || (t[e + 1] & 15) !== 0)
|
|
485
|
+
throw new Error("Dictionary key/value flags must be zero");
|
|
486
|
+
$(r);
|
|
487
|
+
const n = { offset: e + 2 }, a = f(t, n, "DictMalformed");
|
|
488
|
+
let i = n.offset;
|
|
489
|
+
for (let o = 0; o < a; o++)
|
|
490
|
+
i = G(r, t, i, "DictMalformed"), i = G(s, t, i, "DictMalformed");
|
|
491
|
+
return i - e;
|
|
492
|
+
}
|
|
493
|
+
function G(t, e, r, s) {
|
|
494
|
+
const n = y(t);
|
|
495
|
+
if (n >= 0)
|
|
496
|
+
return u(e, r, n), r + n;
|
|
497
|
+
switch (t) {
|
|
498
|
+
case 12:
|
|
499
|
+
case 13: {
|
|
500
|
+
const a = { offset: r }, i = f(e, a, s);
|
|
501
|
+
return u(e, a.offset, i), a.offset + i;
|
|
502
|
+
}
|
|
503
|
+
case 11: {
|
|
504
|
+
const a = { offset: r }, i = f(e, a, s);
|
|
505
|
+
return u(e, a.offset, i), a.offset + i;
|
|
506
|
+
}
|
|
507
|
+
case 9:
|
|
508
|
+
return r + v(e, r);
|
|
509
|
+
case 10:
|
|
510
|
+
return r + x(e, r);
|
|
511
|
+
default:
|
|
512
|
+
throw new Error(`Unsupported Teleport type ${L[t]}`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function K(t) {
|
|
516
|
+
return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
517
|
+
}
|
|
518
|
+
function O(t) {
|
|
519
|
+
return t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
520
|
+
}
|
|
521
|
+
var T = /* @__PURE__ */ ((t) => (t[t.Unknown = 0] = "Unknown", t[t.Opus = 1] = "Opus", t[t.Mp3 = 2] = "Mp3", t[t.RawPcm16 = 3] = "RawPcm16", t))(T || {}), b = /* @__PURE__ */ ((t) => (t[t.NONE = 0] = "NONE", t[t.CONSTANT_GROUP_BITS = 15] = "CONSTANT_GROUP_BITS", t[t.CONSTANT_GROUP_OFFSET = 16] = "CONSTANT_GROUP_OFFSET", t[t.GROUP_CORE = 65536] = "GROUP_CORE", t[t.CORE_AUTH_RESPONSE = 65537] = "CORE_AUTH_RESPONSE", t[t.CORE_AUTH_TICKET = 65538] = "CORE_AUTH_TICKET", t[t.CORE_GLOBAL_STATE = 65539] = "CORE_GLOBAL_STATE", t[t.CORE_ON_SERVER_STATUS_PING = 65540] = "CORE_ON_SERVER_STATUS_PING", t[t.CORE_ON_USER_JOINED = 65541] = "CORE_ON_USER_JOINED", t[t.CORE_ON_USER_LEFT = 65542] = "CORE_ON_USER_LEFT", t[t.CORE_ON_CLIENT_JOINED = 65543] = "CORE_ON_CLIENT_JOINED", t[t.CORE_ON_CLIENT_LEFT = 65544] = "CORE_ON_CLIENT_LEFT", t[t.CORE_ON_SERVER_STARTED = 65545] = "CORE_ON_SERVER_STARTED", t[t.CORE_ON_SERVER_STOPPED = 65546] = "CORE_ON_SERVER_STOPPED", t[t.CORE_ON_SERVER_STOPPING = 65547] = "CORE_ON_SERVER_STOPPING", t[t.CORE_ON_CLIENT_READY = 65548] = "CORE_ON_CLIENT_READY", t[t.CORE_CLIENT_READY = 65549] = "CORE_CLIENT_READY", t[t.CORE_SERVER_INIT = 65550] = "CORE_SERVER_INIT", t[t.CORE_ON_PLUGIN_RELOADED = 65551] = "CORE_ON_PLUGIN_RELOADED", t[t.CORE_SERVER_START = 65552] = "CORE_SERVER_START", t[t.CORE_SERVER_STOP = 65553] = "CORE_SERVER_STOP", t[t.CORE_ON_HOSTED_SERVER_EXIT = 65554] = "CORE_ON_HOSTED_SERVER_EXIT", t[t.CORE_DYNAMIC_CONFIG = 65555] = "CORE_DYNAMIC_CONFIG", t[t.CORE_PROXY_RPC_AUTH_TICKET = 65556] = "CORE_PROXY_RPC_AUTH_TICKET", t[t.CORE_SERVER_INIT2 = 65557] = "CORE_SERVER_INIT2", t[t.GROUP_KEEPALIVE = 131072] = "GROUP_KEEPALIVE", t[t.KEEPALIVE_REQUEST = 131073] = "KEEPALIVE_REQUEST", t[t.KEEPALIVE_RESPONSE = 131074] = "KEEPALIVE_RESPONSE", t[t.GROUP_EVENTS = 262144] = "GROUP_EVENTS", t[t.EVENTS_PROFILE_UPDATE = 262145] = "EVENTS_PROFILE_UPDATE", t[t.EVENTS_CHANNEL_COMPLETE = 262146] = "EVENTS_CHANNEL_COMPLETE", t[t.EVENTS_SPEECH_PLAYBACK_COMPLETE = 262147] = "EVENTS_SPEECH_PLAYBACK_COMPLETE", t[t.GROUP_ANALYTICS = 524288] = "GROUP_ANALYTICS", t[t.ANALYTICS_LOGS = 524289] = "ANALYTICS_LOGS", t[t.ANALYTICS_EVENTS = 524290] = "ANALYTICS_EVENTS", t[t.ANALYTICS_USAGES = 524291] = "ANALYTICS_USAGES", t[t.ANALYTICS_USAGE = 524292] = "ANALYTICS_USAGE", t[t.ANALYTICS_SPECIAL_LOG = 524293] = "ANALYTICS_SPECIAL_LOG", t[t.ANALYTICS_PROCESSING_UPDATE = 524294] = "ANALYTICS_PROCESSING_UPDATE", t[t.ANALYTICS_REACTIVE_PROCESSING_UPDATE = 524295] = "ANALYTICS_REACTIVE_PROCESSING_UPDATE", t[t.ANALYTICS_IKON_PROXY_SERVER_STATS = 524296] = "ANALYTICS_IKON_PROXY_SERVER_STATS", t[t.GROUP_ACTIONS = 1048576] = "GROUP_ACTIONS", t[t.ACTION_CALL = 1048577] = "ACTION_CALL", t[t.ACTION_ACTIVE = 1048578] = "ACTION_ACTIVE", t[t.ACTION_TEXT_OUTPUT = 1048579] = "ACTION_TEXT_OUTPUT", t[t.ACTION_TEXT_OUTPUT_DELTA = 1048580] = "ACTION_TEXT_OUTPUT_DELTA", t[t.ACTION_TEXT_OUTPUT_DELTA_FULL = 1048581] = "ACTION_TEXT_OUTPUT_DELTA_FULL", t[t.ACTION_SET_STATE = 1048582] = "ACTION_SET_STATE", t[t.ACTION_TAP = 1048583] = "ACTION_TAP", t[t.ACTION_PAN = 1048584] = "ACTION_PAN", t[t.ACTION_ZOOM = 1048585] = "ACTION_ZOOM", t[t.ACTION_FILE_UPLOAD_BEGIN = 1048586] = "ACTION_FILE_UPLOAD_BEGIN", t[t.ACTION_FILE_UPLOAD_DATA = 1048587] = "ACTION_FILE_UPLOAD_DATA", t[t.ACTION_FILE_UPLOAD_ACK = 1048588] = "ACTION_FILE_UPLOAD_ACK", t[t.ACTION_FILE_UPLOAD_END = 1048589] = "ACTION_FILE_UPLOAD_END", t[t.ACTION_FILE_UPLOAD_RESULT = 1048590] = "ACTION_FILE_UPLOAD_RESULT", t[t.ACTION_OPEN_CHANNEL = 1048591] = "ACTION_OPEN_CHANNEL", t[t.ACTION_OPEN_EXTERNAL_URL = 1048592] = "ACTION_OPEN_EXTERNAL_URL", t[t.ACTION_UI_OPEN_VIEW = 1048593] = "ACTION_UI_OPEN_VIEW", t[t.ACTION_UI_CLOSE_VIEW = 1048594] = "ACTION_UI_CLOSE_VIEW", t[t.ACTION_UI_BLOCKING_BEGIN = 1048595] = "ACTION_UI_BLOCKING_BEGIN", t[t.ACTION_UI_BLOCKING_END = 1048596] = "ACTION_UI_BLOCKING_END", t[t.ACTION_UI_UPDATE_TEXT_DELTA = 1048597] = "ACTION_UI_UPDATE_TEXT_DELTA", t[t.ACTION_UI_DELETE_CONTAINER = 1048598] = "ACTION_UI_DELETE_CONTAINER", t[t.ACTION_UPDATE_GFX_SHADER = 1048599] = "ACTION_UPDATE_GFX_SHADER", t[t.ACTION_FUNCTION_REGISTER = 1048600] = "ACTION_FUNCTION_REGISTER", t[t.ACTION_FUNCTION_CALL = 1048601] = "ACTION_FUNCTION_CALL", t[t.ACTION_FUNCTION_RESULT = 1048602] = "ACTION_FUNCTION_RESULT", t[t.ACTION_GENERATE_ANSWER = 1048603] = "ACTION_GENERATE_ANSWER", t[t.ACTION_REGENERATE_ANSWER = 1048604] = "ACTION_REGENERATE_ANSWER", t[t.ACTION_CLEAR_CHAT_MESSAGE_HISTORY = 1048605] = "ACTION_CLEAR_CHAT_MESSAGE_HISTORY", t[t.ACTION_CLEAR_STATE = 1048606] = "ACTION_CLEAR_STATE", t[t.ACTION_RELOAD_CHANNELS = 1048607] = "ACTION_RELOAD_CHANNELS", t[t.ACTION_RELOAD_PROFILE = 1048608] = "ACTION_RELOAD_PROFILE", t[t.ACTION_CLASSIFICATION_RESULT = 1048609] = "ACTION_CLASSIFICATION_RESULT", t[t.ACTION_AUDIO_STOP = 1048610] = "ACTION_AUDIO_STOP", t[t.ACTION_CALL_TEXT = 1048611] = "ACTION_CALL_TEXT", t[t.ACTION_RELOAD_APPLICATION = 1048612] = "ACTION_RELOAD_APPLICATION", t[t.ACTION_CANCEL_GENERATION = 1048613] = "ACTION_CANCEL_GENERATION", t[t.ACTION_UI_SET_CONTAINER_STABLE = 1048614] = "ACTION_UI_SET_CONTAINER_STABLE", t[t.ACTION_SPEECH_RECOGNIZED = 1048615] = "ACTION_SPEECH_RECOGNIZED", t[t.ACTION_CALL_RESULT = 1048616] = "ACTION_CALL_RESULT", t[t.ACTION_RELOAD_PROVIDER = 1048617] = "ACTION_RELOAD_PROVIDER", t[t.ACTION_DOWNLOAD = 1048618] = "ACTION_DOWNLOAD", t[t.ACTION_SCROLL_TO_CONTAINER = 1048619] = "ACTION_SCROLL_TO_CONTAINER", t[t.ACTION_UI_CLEAR_STREAM = 1048620] = "ACTION_UI_CLEAR_STREAM", t[t.ACTION_PLAY_SOUND = 1048621] = "ACTION_PLAY_SOUND", t[t.ACTION_ENTER_FULLSCREEN = 1048622] = "ACTION_ENTER_FULLSCREEN", t[t.ACTION_STOP_SOUND = 1048623] = "ACTION_STOP_SOUND", t[t.ACTION_START_RECORDING = 1048624] = "ACTION_START_RECORDING", t[t.ACTION_STOP_RECORDING = 1048625] = "ACTION_STOP_RECORDING", t[t.ACTION_OPTIMISTIC_CLIENT_CALLS = 1048626] = "ACTION_OPTIMISTIC_CLIENT_CALLS", t[t.ACTION_FUNCTION_ENUMERATION_ITEM = 1048627] = "ACTION_FUNCTION_ENUMERATION_ITEM", t[t.ACTION_FUNCTION_ENUMERATION_END = 1048628] = "ACTION_FUNCTION_ENUMERATION_END", t[t.ACTION_FUNCTION_CANCEL = 1048629] = "ACTION_FUNCTION_CANCEL", t[t.ACTION_FUNCTION_DISPOSE = 1048630] = "ACTION_FUNCTION_DISPOSE", t[t.ACTION_FUNCTION_ERROR = 1048631] = "ACTION_FUNCTION_ERROR", t[t.ACTION_FUNCTION_ACK = 1048632] = "ACTION_FUNCTION_ACK", t[t.ACTION_FUNCTION_AWAITING_APPROVAL = 1048633] = "ACTION_FUNCTION_AWAITING_APPROVAL", t[t.ACTION_FUNCTION_APPROVAL_REQUIRED = 1048634] = "ACTION_FUNCTION_APPROVAL_REQUIRED", t[t.ACTION_FUNCTION_APPROVAL_RESPONSE = 1048635] = "ACTION_FUNCTION_APPROVAL_RESPONSE", t[t.UI_UPDATE_ACK = 1048636] = "UI_UPDATE_ACK", t[t.ACTION_CALL2 = 1048637] = "ACTION_CALL2", t[t.ACTION_FUNCTION_REGISTER_BATCH = 1048638] = "ACTION_FUNCTION_REGISTER_BATCH", t[t.GROUP_UI = 2097152] = "GROUP_UI", t[t.UI_STREAM_BEGIN = 2097153] = "UI_STREAM_BEGIN", t[t.UI_STREAM_END = 2097154] = "UI_STREAM_END", t[t.UI_CONTAINER_BEGIN = 2097155] = "UI_CONTAINER_BEGIN", t[t.UI_CONTAINER_END = 2097156] = "UI_CONTAINER_END", t[t.UI_SECTION_BEGIN = 2097157] = "UI_SECTION_BEGIN", t[t.UI_SECTION_END = 2097158] = "UI_SECTION_END", t[t.UI_LIST_BEGIN = 2097159] = "UI_LIST_BEGIN", t[t.UI_LIST_ITEM = 2097160] = "UI_LIST_ITEM", t[t.UI_LIST_END = 2097161] = "UI_LIST_END", t[t.UI_TEXT = 2097162] = "UI_TEXT", t[t.UI_HEADER = 2097163] = "UI_HEADER", t[t.UI_SEPARATOR = 2097164] = "UI_SEPARATOR", t[t.UI_BUTTON = 2097165] = "UI_BUTTON", t[t.UI_ICON_BUTTON = 2097166] = "UI_ICON_BUTTON", t[t.UI_IMAGE = 2097167] = "UI_IMAGE", t[t.UI_FILE = 2097168] = "UI_FILE", t[t.UI_BADGE = 2097169] = "UI_BADGE", t[t.UI_CONTENT_LINK = 2097170] = "UI_CONTENT_LINK", t[t.UI_MAP = 2097171] = "UI_MAP", t[t.UI_VEGA_CHART = 2097172] = "UI_VEGA_CHART", t[t.UI_ICON = 2097173] = "UI_ICON", t[t.UI_FILE_UPLOAD_SECTION_BEGIN = 2097174] = "UI_FILE_UPLOAD_SECTION_BEGIN", t[t.UI_FILE_UPLOAD_SECTION_END = 2097175] = "UI_FILE_UPLOAD_SECTION_END", t[t.UI_MATERIAL_SYMBOL = 2097176] = "UI_MATERIAL_SYMBOL", t[t.UI_BUTTON_BEGIN = 2097177] = "UI_BUTTON_BEGIN", t[t.UI_BUTTON_END = 2097178] = "UI_BUTTON_END", t[t.UI_CONTAINER_DELETE = 2097179] = "UI_CONTAINER_DELETE", t[t.UI_INPUT_TEXT = 2097180] = "UI_INPUT_TEXT", t[t.UI_PROGRESS_BAR = 2097181] = "UI_PROGRESS_BAR", t[t.UI_UPDATE_BEGIN = 2097182] = "UI_UPDATE_BEGIN", t[t.UI_UPDATE_END = 2097183] = "UI_UPDATE_END", t[t.UI_AUTOCOMPLETE = 2097184] = "UI_AUTOCOMPLETE", t[t.UI_CHECKBOX = 2097185] = "UI_CHECKBOX", t[t.UI_QS = 2097186] = "UI_QS", t[t.UI_ELEMENT = 2097187] = "UI_ELEMENT", t[t.UI_STYLES = 2097188] = "UI_STYLES", t[t.UI_SVG = 2097189] = "UI_SVG", t[t.UI_UPDATE = 2097190] = "UI_UPDATE", t[t.UI_INIT = 2097191] = "UI_INIT", t[t.UI_STYLES_BATCH = 2097192] = "UI_STYLES_BATCH", t[t.GROUP_COMMON = 4128768] = "GROUP_COMMON", t[t.GROUP_AUDIO = 4194304] = "GROUP_AUDIO", t[t.AUDIO_STREAM_BEGIN = 4194305] = "AUDIO_STREAM_BEGIN", t[t.AUDIO_STREAM_END = 4194306] = "AUDIO_STREAM_END", t[t.AUDIO_FRAME = 4194307] = "AUDIO_FRAME", t[t.AUDIO_FRAME_VOLUME = 4194308] = "AUDIO_FRAME_VOLUME", t[t.AUDIO_FRAME2 = 4194309] = "AUDIO_FRAME2", t[t.GROUP_VIDEO = 8388608] = "GROUP_VIDEO", t[t.VIDEO_STREAM_BEGIN = 8388609] = "VIDEO_STREAM_BEGIN", t[t.VIDEO_STREAM_END = 8388610] = "VIDEO_STREAM_END", t[t.VIDEO_FRAME = 8388611] = "VIDEO_FRAME", t[t.VIDEO_REQUEST_IDR_FRAME = 8388612] = "VIDEO_REQUEST_IDR_FRAME", t[t.VIDEO_INVALIDATE_FRAME = 8388613] = "VIDEO_INVALIDATE_FRAME", t[t.GROUP_TRACKING = 16777216] = "GROUP_TRACKING", t[t.TRACKING_STREAM_BEGIN = 16777217] = "TRACKING_STREAM_BEGIN", t[t.TRACKING_STREAM_END = 16777218] = "TRACKING_STREAM_END", t[t.TRACKING_FRAME = 16777219] = "TRACKING_FRAME", t[t.GROUP_SCENE = 33554432] = "GROUP_SCENE", t[t.SCENE_MESH = 33554433] = "SCENE_MESH", t[t.SCENE_ARRAY = 33554434] = "SCENE_ARRAY", t[t.GROUP_ALL = 67043328] = "GROUP_ALL", t[t.CONSTANT_GROUP_MASK = 2147418112] = "CONSTANT_GROUP_MASK", t))(b || {});
|
|
522
|
+
const It = 1, ht = 4194309, ut = 205938238, ft = 1594075008, At = 2026534360, Tt = 3409001585, Nt = 3466650495, ct = 4007456593, Ct = 4017217601, St = 4065417427, Rt = 4086360332;
|
|
523
|
+
function Ut(t) {
|
|
524
|
+
const e = {};
|
|
525
|
+
return Q(e), e;
|
|
526
|
+
}
|
|
527
|
+
function Q(t) {
|
|
528
|
+
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;
|
|
529
|
+
}
|
|
530
|
+
function mt(t, e) {
|
|
531
|
+
const r = w.create(t);
|
|
532
|
+
return Lt(r, e);
|
|
533
|
+
}
|
|
534
|
+
function Lt(t, e) {
|
|
535
|
+
const r = e ?? Ut();
|
|
536
|
+
return Q(r), yt(t, r), r;
|
|
537
|
+
}
|
|
538
|
+
function yt(t, e) {
|
|
539
|
+
let r;
|
|
540
|
+
for (; (r = t.next()) !== null; )
|
|
541
|
+
switch (r.fieldId) {
|
|
542
|
+
case ut: {
|
|
543
|
+
if (r.isNull) throw new Error();
|
|
544
|
+
e.AverageVolume = r.asFloat32();
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
case ft: {
|
|
548
|
+
if (r.isNull) throw new Error();
|
|
549
|
+
e.IsFirst = r.asBool();
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
case At: {
|
|
553
|
+
if (r.isNull) throw new Error();
|
|
554
|
+
e.TimeStampInInterleavedSamples = r.asUInt64();
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
case Tt: {
|
|
558
|
+
if (r.isNull) throw new Error();
|
|
559
|
+
e.Samples = r.asBinary();
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
case Nt: {
|
|
563
|
+
if (r.isNull) throw new Error();
|
|
564
|
+
e.AudioEventEstimatedDuration = r.asFloat32();
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
case ct: {
|
|
568
|
+
if (r.isNull) throw new Error();
|
|
569
|
+
e.FrameSizeInInterleavedSamples = r.asUInt32();
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
case Ct: {
|
|
573
|
+
if (r.isNull) throw new Error();
|
|
574
|
+
e.IsLast = r.asBool();
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
case St: {
|
|
578
|
+
if (r.isNull) throw new Error();
|
|
579
|
+
e.Sequence = r.asUInt32();
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case Rt: {
|
|
583
|
+
if (r.isNull) throw new Error();
|
|
584
|
+
e.Epoch = r.asUInt32();
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function Dt(t, e) {
|
|
590
|
+
const r = j(t, ht, It);
|
|
591
|
+
return mt(r, e);
|
|
592
|
+
}
|
|
593
|
+
const Pt = 1, dt = 4194305, gt = 1368629611, wt = 2431514951, Ot = 2914494629, Mt = 3284746250, Ft = 4101844078;
|
|
594
|
+
function bt(t) {
|
|
595
|
+
const e = {};
|
|
596
|
+
return J(e), e;
|
|
597
|
+
}
|
|
598
|
+
function J(t) {
|
|
599
|
+
return t.Description = "", t.Codec = T.Unknown, t.SampleRate = 0, t.Channels = 0, t.BitDepth = 0, t;
|
|
600
|
+
}
|
|
601
|
+
function Bt(t, e) {
|
|
602
|
+
const r = w.create(t);
|
|
603
|
+
return Gt(r, e);
|
|
604
|
+
}
|
|
605
|
+
function Gt(t, e) {
|
|
606
|
+
const r = e ?? bt();
|
|
607
|
+
return J(r), Vt(t, r), r;
|
|
608
|
+
}
|
|
609
|
+
function Vt(t, e) {
|
|
610
|
+
let r;
|
|
611
|
+
for (; (r = t.next()) !== null; )
|
|
612
|
+
switch (r.fieldId) {
|
|
613
|
+
case gt: {
|
|
614
|
+
if (r.isNull) throw new Error();
|
|
615
|
+
e.Description = r.asString();
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case wt: {
|
|
619
|
+
if (r.isNull) throw new Error();
|
|
620
|
+
e.Channels = r.asInt32();
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
case Ot: {
|
|
624
|
+
if (r.isNull) throw new Error();
|
|
625
|
+
e.BitDepth = r.asInt32();
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
case Mt: {
|
|
629
|
+
if (r.isNull) throw new Error();
|
|
630
|
+
e.Codec = r.asInt32();
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
case Ft: {
|
|
634
|
+
if (r.isNull) throw new Error();
|
|
635
|
+
e.SampleRate = r.asInt32();
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function kt(t, e) {
|
|
641
|
+
const r = j(t, dt, Pt);
|
|
642
|
+
return Bt(r, e);
|
|
643
|
+
}
|
|
644
|
+
class W {
|
|
645
|
+
static getStorageForCapacity(e, r) {
|
|
646
|
+
const s = Int32Array.BYTES_PER_ELEMENT * 2, n = r.BYTES_PER_ELEMENT * e;
|
|
647
|
+
return new SharedArrayBuffer(s + n);
|
|
648
|
+
}
|
|
649
|
+
readWrite;
|
|
650
|
+
storage;
|
|
651
|
+
buf;
|
|
652
|
+
constructor(e, r) {
|
|
653
|
+
this.buf = e, this.readWrite = new Int32Array(e, 0, 2);
|
|
654
|
+
const s = Int32Array.BYTES_PER_ELEMENT * 2, n = (e.byteLength - s) / Float32Array.BYTES_PER_ELEMENT;
|
|
655
|
+
this.storage = new r(e, s, n);
|
|
656
|
+
}
|
|
657
|
+
get capacity() {
|
|
658
|
+
return this.storage.length;
|
|
659
|
+
}
|
|
660
|
+
flush() {
|
|
661
|
+
Atomics.store(this.readWrite, 0, 0), Atomics.store(this.readWrite, 1, 0);
|
|
662
|
+
}
|
|
663
|
+
availableRead() {
|
|
664
|
+
const e = Atomics.load(this.readWrite, 0), r = Atomics.load(this.readWrite, 1);
|
|
665
|
+
return r >= e ? r - e : this.capacity - (e - r);
|
|
666
|
+
}
|
|
667
|
+
availableWrite() {
|
|
668
|
+
return this.capacity - this.availableRead() - 1;
|
|
669
|
+
}
|
|
670
|
+
push(e) {
|
|
671
|
+
const r = Math.min(this.availableWrite(), e.length);
|
|
672
|
+
if (r <= 0)
|
|
673
|
+
return 0;
|
|
674
|
+
let s = Atomics.load(this.readWrite, 1);
|
|
675
|
+
const n = Math.min(r, this.capacity - s);
|
|
676
|
+
this.storage.set(e.subarray(0, n), s);
|
|
677
|
+
const a = r - n;
|
|
678
|
+
return a > 0 && this.storage.set(e.subarray(n, n + a), 0), s = (s + r) % this.capacity, Atomics.store(this.readWrite, 1, s), Atomics.notify(this.readWrite, 1), r;
|
|
679
|
+
}
|
|
680
|
+
pop(e) {
|
|
681
|
+
const r = Math.min(this.availableRead(), e.length);
|
|
682
|
+
if (r <= 0)
|
|
683
|
+
return 0;
|
|
684
|
+
let s = Atomics.load(this.readWrite, 0);
|
|
685
|
+
const n = Math.min(r, this.capacity - s);
|
|
686
|
+
e.set(this.storage.subarray(s, s + n), 0);
|
|
687
|
+
const a = r - n;
|
|
688
|
+
return a > 0 && e.set(this.storage.subarray(0, a), n), s = (s + r) % this.capacity, Atomics.store(this.readWrite, 0, s), r;
|
|
689
|
+
}
|
|
690
|
+
skip(e) {
|
|
691
|
+
const r = Math.min(this.availableRead(), e);
|
|
692
|
+
if (r <= 0)
|
|
693
|
+
return 0;
|
|
694
|
+
let s = Atomics.load(this.readWrite, 0);
|
|
695
|
+
return s = (s + r) % this.capacity, Atomics.store(this.readWrite, 0, s), r;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
const vt = globalThis;
|
|
699
|
+
function xt() {
|
|
700
|
+
if (typeof SharedArrayBuffer > "u" || typeof Atomics > "u" || vt.crossOriginIsolated === !1)
|
|
701
|
+
return !1;
|
|
702
|
+
try {
|
|
703
|
+
new SharedArrayBuffer(1);
|
|
704
|
+
} catch {
|
|
705
|
+
return !1;
|
|
706
|
+
}
|
|
707
|
+
return !0;
|
|
708
|
+
}
|
|
709
|
+
let pt = 1;
|
|
710
|
+
function Ht(t, e) {
|
|
711
|
+
return `[${t}] ${e}`;
|
|
712
|
+
}
|
|
713
|
+
function F(t, e, r, s) {
|
|
714
|
+
if ((/* @__PURE__ */ new Date()).toISOString(), pt <= t) {
|
|
715
|
+
const n = Ht(e, r);
|
|
716
|
+
switch (t) {
|
|
717
|
+
case 0:
|
|
718
|
+
console.debug(n, ...s);
|
|
719
|
+
break;
|
|
720
|
+
case 1:
|
|
721
|
+
console.info(n, ...s);
|
|
722
|
+
break;
|
|
723
|
+
case 2:
|
|
724
|
+
console.warn(n, ...s);
|
|
725
|
+
break;
|
|
726
|
+
case 3:
|
|
727
|
+
console.error(n, ...s);
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function Yt(t) {
|
|
733
|
+
return {
|
|
734
|
+
debug(e, ...r) {
|
|
735
|
+
F(0, t, e, r);
|
|
736
|
+
},
|
|
737
|
+
info(e, ...r) {
|
|
738
|
+
F(1, t, e, r);
|
|
739
|
+
},
|
|
740
|
+
warn(e, ...r) {
|
|
741
|
+
F(2, t, e, r);
|
|
742
|
+
},
|
|
743
|
+
error(e, ...r) {
|
|
744
|
+
F(3, t, e, r);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
const Z = 48e3, q = 2, Kt = 1500, Wt = 10, Xt = 80, zt = 50, X = 64, jt = Yt("AudioPlaybackWorker"), D = (t, e) => {
|
|
749
|
+
self.postMessage(t, e ?? []);
|
|
750
|
+
}, $t = xt();
|
|
751
|
+
let B = "pcm", tt = !0, R = Z, S = q, m = null;
|
|
752
|
+
function U(t, e) {
|
|
753
|
+
const r = t instanceof Error ? t : new Error(String(t));
|
|
754
|
+
D({ type: "error", error: { name: r.name, message: r.message, stack: r.stack }, streamId: e });
|
|
755
|
+
}
|
|
756
|
+
function p(t) {
|
|
757
|
+
const e = z(t);
|
|
758
|
+
return `${e.senderId}_${e.trackId}`;
|
|
759
|
+
}
|
|
760
|
+
class Qt {
|
|
761
|
+
mode;
|
|
762
|
+
ring = null;
|
|
763
|
+
sab = void 0;
|
|
764
|
+
streamId;
|
|
765
|
+
outputSampleRate;
|
|
766
|
+
outputChannels;
|
|
767
|
+
closed = !1;
|
|
768
|
+
pendingPcmChunks = [];
|
|
769
|
+
pendingPcmSamples = 0;
|
|
770
|
+
lastPcmFlushTimeMs = 0;
|
|
771
|
+
constructor(e) {
|
|
772
|
+
this.streamId = e, this.mode = "pcm", this.outputSampleRate = R, this.outputChannels = S, this.rebind(B);
|
|
773
|
+
}
|
|
774
|
+
close() {
|
|
775
|
+
this.closed = !0, this.pendingPcmChunks = [], this.pendingPcmSamples = 0, this.ring = null, this.sab = void 0;
|
|
776
|
+
}
|
|
777
|
+
setOutputFormat(e, r) {
|
|
778
|
+
this.outputSampleRate = e, this.outputChannels = r;
|
|
779
|
+
}
|
|
780
|
+
rebind(e) {
|
|
781
|
+
if (!this.closed) {
|
|
782
|
+
if (this.mode = e, e === "sab" && $t) {
|
|
783
|
+
const r = Math.floor(Kt * this.outputSampleRate * this.outputChannels / 1e3), s = W.getStorageForCapacity(r, Float32Array), n = new W(s, Float32Array);
|
|
784
|
+
n.flush(), this.sab = s, this.ring = n;
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
this.sab = void 0, this.ring = null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
flushPendingPcm(e) {
|
|
791
|
+
if (this.closed || this.mode !== "pcm" || this.pendingPcmSamples <= 0)
|
|
792
|
+
return;
|
|
793
|
+
const r = performance.now(), s = Math.max(1, Math.round(this.outputSampleRate * this.outputChannels * Xt / 1e3));
|
|
794
|
+
if (!(e || this.pendingPcmSamples >= s || this.lastPcmFlushTimeMs > 0 && r - this.lastPcmFlushTimeMs >= zt))
|
|
795
|
+
return;
|
|
796
|
+
const a = new Float32Array(this.pendingPcmSamples);
|
|
797
|
+
let i = 0;
|
|
798
|
+
for (const o of this.pendingPcmChunks)
|
|
799
|
+
a.set(o, i), i += o.length;
|
|
800
|
+
this.pendingPcmChunks = [], this.pendingPcmSamples = 0, this.lastPcmFlushTimeMs = r, D({ type: "pcm", streamId: this.streamId, pcm: a }, [a.buffer]);
|
|
801
|
+
}
|
|
802
|
+
drainPcm() {
|
|
803
|
+
this.flushPendingPcm(!0);
|
|
804
|
+
}
|
|
805
|
+
writePcm(e) {
|
|
806
|
+
if (!this.closed) {
|
|
807
|
+
if (this.mode === "sab" && this.ring) {
|
|
808
|
+
const r = this.ring, s = this.outputChannels;
|
|
809
|
+
let n = e;
|
|
810
|
+
const a = Math.floor(Math.max(0, r.capacity - 1) / s) * s;
|
|
811
|
+
n.length > a && (n = n.subarray(n.length - a));
|
|
812
|
+
const i = Math.floor(r.availableWrite() / s) * s;
|
|
813
|
+
if (i <= 0)
|
|
814
|
+
return;
|
|
815
|
+
n.length > i && (n = n.subarray(n.length - i)), r.push(n);
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
this.pendingPcmChunks.push(e), this.pendingPcmSamples += e.length, this.lastPcmFlushTimeMs === 0 && (this.lastPcmFlushTimeMs = performance.now()), this.flushPendingPcm(!1);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
getSharedArrayBuffer() {
|
|
822
|
+
return this.sab;
|
|
823
|
+
}
|
|
824
|
+
flush() {
|
|
825
|
+
this.closed || (this.pendingPcmChunks = [], this.pendingPcmSamples = 0, this.lastPcmFlushTimeMs = 0, this.ring?.flush());
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function Jt(t) {
|
|
829
|
+
switch (t) {
|
|
830
|
+
case T.Opus:
|
|
831
|
+
return "opus";
|
|
832
|
+
case T.Mp3:
|
|
833
|
+
return "mp3";
|
|
834
|
+
default:
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
let d = null;
|
|
839
|
+
function Zt(t) {
|
|
840
|
+
const e = new DataView(t.buffer, t.byteOffset, t.byteLength), r = Math.floor(t.byteLength / 2);
|
|
841
|
+
(!d || d.length < r) && (d = new Float32Array(r));
|
|
842
|
+
for (let s = 0; s < r; s++)
|
|
843
|
+
d[s] = e.getInt16(s * 2, !0) / 32768;
|
|
844
|
+
return d.subarray(0, r);
|
|
845
|
+
}
|
|
846
|
+
class H {
|
|
847
|
+
inputSampleRate;
|
|
848
|
+
inputChannels;
|
|
849
|
+
sink;
|
|
850
|
+
// Pre-allocated grow-only buffers for conversion pipeline
|
|
851
|
+
_resampleBuffer = null;
|
|
852
|
+
_remixBuffer = null;
|
|
853
|
+
_interleavedBuffer = null;
|
|
854
|
+
constructor(e) {
|
|
855
|
+
this.inputSampleRate = e.inputSampleRate, this.inputChannels = e.inputChannels, this.sink = e.sink;
|
|
856
|
+
}
|
|
857
|
+
getResampleBuffer(e) {
|
|
858
|
+
return (!this._resampleBuffer || this._resampleBuffer.length < e) && (this._resampleBuffer = new Float32Array(e)), this._resampleBuffer;
|
|
859
|
+
}
|
|
860
|
+
getRemixBuffer(e) {
|
|
861
|
+
return (!this._remixBuffer || this._remixBuffer.length < e) && (this._remixBuffer = new Float32Array(e)), this._remixBuffer;
|
|
862
|
+
}
|
|
863
|
+
getInterleavedBuffer(e) {
|
|
864
|
+
return (!this._interleavedBuffer || this._interleavedBuffer.length < e) && (this._interleavedBuffer = new Float32Array(e)), this._interleavedBuffer;
|
|
865
|
+
}
|
|
866
|
+
reset() {
|
|
867
|
+
}
|
|
868
|
+
writeConvertedPcm(e, r, s) {
|
|
869
|
+
const n = this.convertPcmBuffer(e, r, s);
|
|
870
|
+
n.length > 0 && this.sink.writePcm(n);
|
|
871
|
+
}
|
|
872
|
+
convertAudioData(e) {
|
|
873
|
+
const r = e.numberOfFrames, s = e.numberOfChannels, n = e.format, a = typeof n == "string" && n.includes("planar"), i = "f32-planar", o = "f32", _ = () => {
|
|
874
|
+
const I = new Array(s);
|
|
875
|
+
for (let A = 0; A < s; A++) {
|
|
876
|
+
const c = new Float32Array(r);
|
|
877
|
+
e.copyTo(c, { planeIndex: A, format: i }), I[A] = c;
|
|
878
|
+
}
|
|
879
|
+
return le(I, r);
|
|
880
|
+
}, h = () => {
|
|
881
|
+
const I = new Float32Array(r * s);
|
|
882
|
+
return e.copyTo(I, { planeIndex: 0, format: o }), I;
|
|
883
|
+
};
|
|
884
|
+
let E;
|
|
885
|
+
if (a)
|
|
886
|
+
try {
|
|
887
|
+
E = _();
|
|
888
|
+
} catch (I) {
|
|
889
|
+
jt.debug(`Failed to read planar audio data, falling back to interleaved copy: ${I}`), E = h();
|
|
890
|
+
}
|
|
891
|
+
else
|
|
892
|
+
E = h();
|
|
893
|
+
return E;
|
|
894
|
+
}
|
|
895
|
+
convertPcmBuffer(e, r, s) {
|
|
896
|
+
if (e.length === 0)
|
|
897
|
+
return e;
|
|
898
|
+
let n = e, a = e.length, i = r;
|
|
899
|
+
if (s !== R) {
|
|
900
|
+
const o = a / i, h = Math.max(1, Math.round(o * R / s)) * i, E = this.getResampleBuffer(h);
|
|
901
|
+
a = Ie(n, E, i, s, R), n = E;
|
|
902
|
+
}
|
|
903
|
+
if (i !== S) {
|
|
904
|
+
const _ = a / i * S, h = this.getRemixBuffer(_);
|
|
905
|
+
a = he(n.subarray(0, a), h, i, S), n = h, i = S;
|
|
906
|
+
}
|
|
907
|
+
return n.subarray(0, a);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
class qt extends H {
|
|
911
|
+
feedChunk(e) {
|
|
912
|
+
e.isFirst && this.reset();
|
|
913
|
+
const r = Zt(e.data);
|
|
914
|
+
this.writeConvertedPcm(r, this.inputChannels, this.inputSampleRate), e.isLast && this.reset();
|
|
915
|
+
}
|
|
916
|
+
close() {
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
class te extends H {
|
|
920
|
+
decoder;
|
|
921
|
+
codec;
|
|
922
|
+
constructor(e) {
|
|
923
|
+
super({ inputChannels: e.inputChannels, inputSampleRate: e.inputSampleRate, sink: e.sink }), this.codec = e.codec, this.decoder = new AudioDecoder({
|
|
924
|
+
output: (r) => {
|
|
925
|
+
try {
|
|
926
|
+
const s = this.convertAudioData(r);
|
|
927
|
+
this.writeConvertedPcm(s, r.numberOfChannels, r.sampleRate);
|
|
928
|
+
} catch (s) {
|
|
929
|
+
U(s);
|
|
930
|
+
} finally {
|
|
931
|
+
try {
|
|
932
|
+
r.close();
|
|
933
|
+
} catch {
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
},
|
|
937
|
+
error: (r) => {
|
|
938
|
+
U(r);
|
|
939
|
+
}
|
|
940
|
+
}), this.decoder.configure({ codec: e.codec, numberOfChannels: e.inputChannels, sampleRate: e.inputSampleRate });
|
|
941
|
+
}
|
|
942
|
+
feedChunk(e) {
|
|
943
|
+
try {
|
|
944
|
+
if (e.isFirst && this.reset(), this.decoder.state !== "configured")
|
|
945
|
+
return;
|
|
946
|
+
this.decoder.decode(
|
|
947
|
+
new EncodedAudioChunk({
|
|
948
|
+
type: "key",
|
|
949
|
+
timestamp: e.timestampUs,
|
|
950
|
+
duration: e.durationUs,
|
|
951
|
+
data: e.data
|
|
952
|
+
})
|
|
953
|
+
), e.isLast && this.decoder.flush().catch(() => {
|
|
954
|
+
});
|
|
955
|
+
} catch (r) {
|
|
956
|
+
U(r);
|
|
957
|
+
try {
|
|
958
|
+
this.reset();
|
|
959
|
+
} catch {
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
reset() {
|
|
964
|
+
super.reset();
|
|
965
|
+
try {
|
|
966
|
+
this.decoder.reset(), this.decoder.configure({ codec: this.codec, numberOfChannels: this.inputChannels, sampleRate: this.inputSampleRate });
|
|
967
|
+
} catch (e) {
|
|
968
|
+
U(e);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
close() {
|
|
972
|
+
try {
|
|
973
|
+
this.decoder.close();
|
|
974
|
+
} catch {
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
class ee extends H {
|
|
979
|
+
decoder = null;
|
|
980
|
+
isReady = !1;
|
|
981
|
+
decoderSampleRate = 48e3;
|
|
982
|
+
resetTask = null;
|
|
983
|
+
pendingChunks = [];
|
|
984
|
+
resetGeneration = 0;
|
|
985
|
+
async initialise(e, r) {
|
|
986
|
+
const { OpusDecoder: s } = await import("./index-CvFH-Dkf.js"), a = [8e3, 12e3, 16e3, 24e3, 48e3].reduce((i, o) => Math.abs(o - r) < Math.abs(i - r) ? o : i);
|
|
987
|
+
this.decoderSampleRate = a, this.decoder = new s({ channels: e, sampleRate: this.decoderSampleRate }), await this.decoder.ready, this.isReady = !0;
|
|
988
|
+
}
|
|
989
|
+
scheduleReset() {
|
|
990
|
+
if (!this.decoder || this.resetTask)
|
|
991
|
+
return;
|
|
992
|
+
const e = ++this.resetGeneration;
|
|
993
|
+
this.resetTask = this.decoder.reset().catch(() => {
|
|
994
|
+
}).finally(() => {
|
|
995
|
+
this.resetGeneration === e && (this.resetTask = null, this.flushPendingChunks());
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
flushPendingChunks() {
|
|
999
|
+
if (this.resetTask)
|
|
1000
|
+
return;
|
|
1001
|
+
if (!this.isReady || !this.decoder) {
|
|
1002
|
+
this.pendingChunks = [];
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
if (this.pendingChunks.length === 0)
|
|
1006
|
+
return;
|
|
1007
|
+
const e = this.pendingChunks.splice(0);
|
|
1008
|
+
for (let r = 0; r < e.length; r++)
|
|
1009
|
+
if (this.decodeChunk(e[r]), this.resetTask) {
|
|
1010
|
+
this.pendingChunks = e.slice(r + 1).concat(this.pendingChunks);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
reset() {
|
|
1015
|
+
super.reset();
|
|
1016
|
+
try {
|
|
1017
|
+
this.scheduleReset();
|
|
1018
|
+
} catch {
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
decodeChunk(e) {
|
|
1022
|
+
if (!(!this.isReady || !this.decoder))
|
|
1023
|
+
try {
|
|
1024
|
+
if (e.data.byteLength === 0)
|
|
1025
|
+
return;
|
|
1026
|
+
const r = e.data.byteOffset === 0 && e.data.byteLength === e.data.buffer.byteLength ? e.data : e.data.slice(), s = this.decoder.decodeFrame(r), n = s.channelData, a = s.samplesDecoded, i = n.length;
|
|
1027
|
+
if (!i || !a)
|
|
1028
|
+
return;
|
|
1029
|
+
const o = a * i, _ = this.getInterleavedBuffer(o);
|
|
1030
|
+
let h = 0;
|
|
1031
|
+
for (let E = 0; E < a; E++)
|
|
1032
|
+
for (let I = 0; I < i; I++)
|
|
1033
|
+
_[h++] = n[I][E] ?? 0;
|
|
1034
|
+
this.writeConvertedPcm(_.subarray(0, o), i, this.decoderSampleRate), e.isLast && this.reset();
|
|
1035
|
+
} catch (r) {
|
|
1036
|
+
U(r), this.scheduleReset();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
feedChunk(e) {
|
|
1040
|
+
if (!(!this.isReady || !this.decoder)) {
|
|
1041
|
+
if (e.isFirst && this.reset(), this.resetTask) {
|
|
1042
|
+
this.pendingChunks.push(e);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
this.decodeChunk(e);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
close() {
|
|
1049
|
+
try {
|
|
1050
|
+
this.decoder?.free();
|
|
1051
|
+
} catch {
|
|
1052
|
+
}
|
|
1053
|
+
this.decoder = null;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
const N = /* @__PURE__ */ new Map();
|
|
1057
|
+
async function re(t) {
|
|
1058
|
+
if (t.closed || t.decoder)
|
|
1059
|
+
return;
|
|
1060
|
+
if (t.codec === T.RawPcm16) {
|
|
1061
|
+
t.decoder = new qt({ inputChannels: t.inputChannels, inputSampleRate: t.inputSampleRate, sink: t.sink });
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
if (t.codec !== T.Opus && t.codec !== T.Mp3)
|
|
1065
|
+
throw new Error(`Unsupported audio codec: ${T[t.codec] ?? t.codec}`);
|
|
1066
|
+
const e = Jt(t.codec);
|
|
1067
|
+
if (tt && typeof AudioDecoder < "u" && e !== null)
|
|
1068
|
+
try {
|
|
1069
|
+
if ((await AudioDecoder.isConfigSupported({ codec: e, numberOfChannels: t.inputChannels, sampleRate: t.inputSampleRate })).supported) {
|
|
1070
|
+
const n = new te({
|
|
1071
|
+
codec: e,
|
|
1072
|
+
inputChannels: t.inputChannels,
|
|
1073
|
+
inputSampleRate: t.inputSampleRate,
|
|
1074
|
+
sink: t.sink
|
|
1075
|
+
});
|
|
1076
|
+
if (t.closed) {
|
|
1077
|
+
n.close();
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
t.decoder = n;
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
} catch {
|
|
1084
|
+
}
|
|
1085
|
+
if (t.codec === T.Opus) {
|
|
1086
|
+
const s = new ee({ inputChannels: t.inputChannels, inputSampleRate: t.inputSampleRate, sink: t.sink });
|
|
1087
|
+
if (await s.initialise(t.inputChannels, t.inputSampleRate), t.closed) {
|
|
1088
|
+
s.close();
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
t.decoder = s;
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
throw new Error(`No available decoder for codec: ${T[t.codec] ?? t.codec}`);
|
|
1095
|
+
}
|
|
1096
|
+
function se(t) {
|
|
1097
|
+
if (t.closed) {
|
|
1098
|
+
t.pendingFrames.splice(0);
|
|
1099
|
+
try {
|
|
1100
|
+
t.decoder?.close();
|
|
1101
|
+
} catch {
|
|
1102
|
+
}
|
|
1103
|
+
t.decoder = null;
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
if (!t.decoder)
|
|
1107
|
+
return;
|
|
1108
|
+
const e = t.pendingFrames.splice(0);
|
|
1109
|
+
for (const r of e)
|
|
1110
|
+
et(t, r);
|
|
1111
|
+
}
|
|
1112
|
+
function et(t, e) {
|
|
1113
|
+
if (t.closed || !t.decoder)
|
|
1114
|
+
return;
|
|
1115
|
+
const r = e.Epoch, s = Number(e.TimeStampInInterleavedSamples), n = e.FrameSizeInInterleavedSamples;
|
|
1116
|
+
if (t.currentEpoch !== r && (t.currentEpoch = r, t.epochSet = !1, t.lastArrivalTimeMs = 0, t.jitterMs = 0, t.sink.flush(), t.decoder.reset()), !t.epochSet) {
|
|
1117
|
+
t.epochSet = !0;
|
|
1118
|
+
const A = t.inputSampleRate * t.inputChannels;
|
|
1119
|
+
t.expectedIntervalMs = n * 1e3 / A;
|
|
1120
|
+
}
|
|
1121
|
+
const a = performance.now();
|
|
1122
|
+
if (t.lastArrivalTimeMs > 0) {
|
|
1123
|
+
const A = a - t.lastArrivalTimeMs, c = Math.abs(A - t.expectedIntervalMs);
|
|
1124
|
+
t.jitterMs = t.jitterMs + (c - t.jitterMs) / Wt;
|
|
1125
|
+
}
|
|
1126
|
+
t.lastArrivalTimeMs = a;
|
|
1127
|
+
const i = t.inputSampleRate * t.inputChannels, o = R * S, _ = Math.round(s * o / i), h = Math.round(n * o / i), E = Math.round(s * 1e6 / i), I = Math.round(n * 1e6 / i);
|
|
1128
|
+
D({
|
|
1129
|
+
type: "frame",
|
|
1130
|
+
streamId: t.streamId,
|
|
1131
|
+
epoch: r,
|
|
1132
|
+
timestampInterleavedSamples: _,
|
|
1133
|
+
frameSizeInterleavedSamples: h,
|
|
1134
|
+
isFirst: e.IsFirst,
|
|
1135
|
+
isLast: e.IsLast,
|
|
1136
|
+
jitterMs: t.jitterMs
|
|
1137
|
+
}), t.decoder.feedChunk({
|
|
1138
|
+
data: e.Samples,
|
|
1139
|
+
isFirst: e.IsFirst,
|
|
1140
|
+
isLast: e.IsLast,
|
|
1141
|
+
timestampUs: E,
|
|
1142
|
+
durationUs: I
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
function ne(t) {
|
|
1146
|
+
const e = p(t), r = kt(t), s = N.get(e);
|
|
1147
|
+
if (s) {
|
|
1148
|
+
s.closed = !0, s.pendingFrames.splice(0);
|
|
1149
|
+
try {
|
|
1150
|
+
s.decoder?.close();
|
|
1151
|
+
} catch {
|
|
1152
|
+
}
|
|
1153
|
+
try {
|
|
1154
|
+
s.sink.drainPcm(), s.sink.close();
|
|
1155
|
+
} catch {
|
|
1156
|
+
}
|
|
1157
|
+
N.delete(e);
|
|
1158
|
+
}
|
|
1159
|
+
const n = new Qt(e), a = {
|
|
1160
|
+
streamId: e,
|
|
1161
|
+
codec: r.Codec,
|
|
1162
|
+
inputSampleRate: r.SampleRate,
|
|
1163
|
+
inputChannels: r.Channels,
|
|
1164
|
+
sink: n,
|
|
1165
|
+
decoder: null,
|
|
1166
|
+
pendingFrames: [],
|
|
1167
|
+
initTask: null,
|
|
1168
|
+
currentEpoch: -1,
|
|
1169
|
+
epochSet: !1,
|
|
1170
|
+
closed: !1,
|
|
1171
|
+
lastArrivalTimeMs: 0,
|
|
1172
|
+
jitterMs: 0,
|
|
1173
|
+
expectedIntervalMs: 20
|
|
1174
|
+
};
|
|
1175
|
+
N.set(e, a), D({
|
|
1176
|
+
type: "streamBegin",
|
|
1177
|
+
streamId: e,
|
|
1178
|
+
sharedArrayBuffer: n.getSharedArrayBuffer()
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
function ie() {
|
|
1182
|
+
for (const t of N.values())
|
|
1183
|
+
D({
|
|
1184
|
+
type: "streamBegin",
|
|
1185
|
+
streamId: t.streamId,
|
|
1186
|
+
sharedArrayBuffer: t.sink.getSharedArrayBuffer()
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
function ae(t) {
|
|
1190
|
+
const e = p(t), r = N.get(e);
|
|
1191
|
+
if (r) {
|
|
1192
|
+
r.closed = !0, r.pendingFrames.splice(0);
|
|
1193
|
+
try {
|
|
1194
|
+
r.sink.drainPcm(), r.sink.close();
|
|
1195
|
+
} catch {
|
|
1196
|
+
}
|
|
1197
|
+
try {
|
|
1198
|
+
r.decoder?.close();
|
|
1199
|
+
} catch {
|
|
1200
|
+
}
|
|
1201
|
+
r.decoder = null, N.delete(e), D({ type: "streamEnd", streamId: e });
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function oe(t) {
|
|
1205
|
+
const e = p(t), r = N.get(e);
|
|
1206
|
+
if (!r || r.closed)
|
|
1207
|
+
return;
|
|
1208
|
+
const s = Dt(t);
|
|
1209
|
+
if (!r.decoder) {
|
|
1210
|
+
r.pendingFrames.length >= X && r.pendingFrames.splice(0, r.pendingFrames.length - X + 1), r.pendingFrames.push(s), r.initTask || (r.initTask = re(r).then(() => se(r)).catch((n) => {
|
|
1211
|
+
r.closed || U(n, e);
|
|
1212
|
+
}));
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
et(r, s);
|
|
1216
|
+
}
|
|
1217
|
+
function _e(t) {
|
|
1218
|
+
switch (st(t)) {
|
|
1219
|
+
case b.AUDIO_STREAM_BEGIN:
|
|
1220
|
+
ne(t);
|
|
1221
|
+
return;
|
|
1222
|
+
case b.AUDIO_STREAM_END:
|
|
1223
|
+
ae(t);
|
|
1224
|
+
return;
|
|
1225
|
+
case b.AUDIO_FRAME2:
|
|
1226
|
+
oe(t);
|
|
1227
|
+
return;
|
|
1228
|
+
default:
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function rt() {
|
|
1233
|
+
if (m) {
|
|
1234
|
+
try {
|
|
1235
|
+
m.close();
|
|
1236
|
+
} catch {
|
|
1237
|
+
}
|
|
1238
|
+
m = null;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function Ee() {
|
|
1242
|
+
rt();
|
|
1243
|
+
for (const t of N.values()) {
|
|
1244
|
+
try {
|
|
1245
|
+
t.sink.drainPcm(), t.sink.close();
|
|
1246
|
+
} catch {
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
t.decoder?.close();
|
|
1250
|
+
} catch {
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
N.clear();
|
|
1254
|
+
}
|
|
1255
|
+
self.addEventListener("message", (t) => {
|
|
1256
|
+
const e = t.data;
|
|
1257
|
+
if (e.type === "configure") {
|
|
1258
|
+
B = e.transport, tt = e.preferWebCodecs ?? !0, R = Number.isFinite(e.outputSampleRate) && e.outputSampleRate > 0 ? e.outputSampleRate : Z, S = Number.isFinite(e.outputChannels) && e.outputChannels > 0 ? e.outputChannels : q;
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (e.type === "attachProtocolPort") {
|
|
1262
|
+
rt(), m = e.port, m.start?.(), m.addEventListener("message", (r) => {
|
|
1263
|
+
const s = r.data;
|
|
1264
|
+
s?.type === "protocol" && s.message instanceof ArrayBuffer && _e(new Uint8Array(s.message));
|
|
1265
|
+
});
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
if (e.type === "rebind") {
|
|
1269
|
+
B = e.transport, typeof e.outputSampleRate == "number" && Number.isFinite(e.outputSampleRate) && e.outputSampleRate > 0 && (R = e.outputSampleRate), typeof e.outputChannels == "number" && Number.isFinite(e.outputChannels) && e.outputChannels > 0 && (S = e.outputChannels);
|
|
1270
|
+
for (const r of N.values())
|
|
1271
|
+
r.sink.setOutputFormat(R, S), r.sink.rebind(B);
|
|
1272
|
+
ie();
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
e.type === "dispose" && Ee();
|
|
1276
|
+
});
|
|
1277
|
+
let g = null;
|
|
1278
|
+
function le(t, e) {
|
|
1279
|
+
if (t.length === 1)
|
|
1280
|
+
return t[0];
|
|
1281
|
+
const r = t.length, s = e * r;
|
|
1282
|
+
(!g || g.length < s) && (g = new Float32Array(s));
|
|
1283
|
+
let n = 0;
|
|
1284
|
+
for (let a = 0; a < e; a++)
|
|
1285
|
+
for (let i = 0; i < r; i++)
|
|
1286
|
+
g[n++] = t[i][a] ?? 0;
|
|
1287
|
+
return g.subarray(0, s);
|
|
1288
|
+
}
|
|
1289
|
+
function Ie(t, e, r, s, n) {
|
|
1290
|
+
if (s === n)
|
|
1291
|
+
return e.set(t), t.length;
|
|
1292
|
+
const a = t.length / r, i = Math.max(1, Math.round(a * n / s));
|
|
1293
|
+
for (let o = 0; o < r; o++)
|
|
1294
|
+
for (let _ = 0; _ < i; _++) {
|
|
1295
|
+
const h = _ * s / n, E = Math.floor(h), I = Math.min(a - 1, E + 1), A = h - E, c = t[E * r + o] ?? 0, M = t[I * r + o] ?? 0;
|
|
1296
|
+
e[_ * r + o] = c * (1 - A) + M * A;
|
|
1297
|
+
}
|
|
1298
|
+
return i * r;
|
|
1299
|
+
}
|
|
1300
|
+
function he(t, e, r, s) {
|
|
1301
|
+
const n = t.length / r;
|
|
1302
|
+
if (r === s)
|
|
1303
|
+
return e.set(t), t.length;
|
|
1304
|
+
if (r === 1 && s === 2) {
|
|
1305
|
+
for (let i = 0; i < n; i++) {
|
|
1306
|
+
const o = t[i] ?? 0;
|
|
1307
|
+
e[i * 2] = o, e[i * 2 + 1] = o;
|
|
1308
|
+
}
|
|
1309
|
+
return n * 2;
|
|
1310
|
+
}
|
|
1311
|
+
if (r === 2 && s === 1) {
|
|
1312
|
+
for (let i = 0; i < n; i++) {
|
|
1313
|
+
const o = t[i * 2] ?? 0, _ = t[i * 2 + 1] ?? 0;
|
|
1314
|
+
e[i] = (o + _) * 0.5;
|
|
1315
|
+
}
|
|
1316
|
+
return n;
|
|
1317
|
+
}
|
|
1318
|
+
const a = Math.min(r, s);
|
|
1319
|
+
for (let i = 0; i < n; i++)
|
|
1320
|
+
for (let o = 0; o < a; o++)
|
|
1321
|
+
e[i * s + o] = t[i * r + o] ?? 0;
|
|
1322
|
+
return n * s;
|
|
1323
|
+
}
|