@ikonai/sdk-ui 1.0.58 → 1.0.60
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-Brmt2Z7a.js +1279 -0
- package/assets/audio-playback-worker-DDytpSb8.js +1590 -0
- package/assets/index-Ca9sTcGt.js +119 -0
- package/assets/index-D_vz6N3U.js +267 -0
- package/assets/libopus-ChbDZJKA.js +139 -0
- package/assets/protocol-worker-HqYf8zdj.js +1674 -0
- package/assets/ui-worker-BYuSlB0y.js +2784 -0
- package/assets/video-capture-worker-CzxOnQmS.js +1126 -0
- package/assets/video-playback-worker-DPsTlza0.js +1005 -0
- package/index.js +626 -604
- package/package.json +1 -1
- package/assets/ui-worker-D4hZvsPd.js +0 -2700
|
@@ -0,0 +1,1674 @@
|
|
|
1
|
+
function z(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 G(t) {
|
|
7
|
+
return z(t) & 4294901760;
|
|
8
|
+
}
|
|
9
|
+
function Y(t) {
|
|
10
|
+
const e = ut(t), s = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
11
|
+
if (e.length < 27)
|
|
12
|
+
throw new Error("Protocol payload too short");
|
|
13
|
+
const r = s.getUint32(0, !0), n = s.getUint32(4, !0), i = s.getUint32(8, !0), E = s.getUint32(12, !0), a = s.getUint32(16, !0), o = s.getUint32(20, !0), c = s.getUint8(24), l = s.getUint8(25), _ = s.getUint8(26);
|
|
14
|
+
if (27 + o * 4 > e.length)
|
|
15
|
+
throw new Error("Protocol header exceeds payload length");
|
|
16
|
+
const I = [];
|
|
17
|
+
let w = 27;
|
|
18
|
+
for (let D = 0; D < o; D++)
|
|
19
|
+
I.push(s.getUint32(w, !0)), w += 4;
|
|
20
|
+
return {
|
|
21
|
+
length: r,
|
|
22
|
+
opcode: n,
|
|
23
|
+
senderId: i,
|
|
24
|
+
trackId: E,
|
|
25
|
+
sequenceId: a,
|
|
26
|
+
targetIds: I,
|
|
27
|
+
payloadVersion: c,
|
|
28
|
+
payloadType: l,
|
|
29
|
+
flags: _
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _t(t, e, s, r, n) {
|
|
33
|
+
const o = [], l = 27 + o.length * 4, _ = l + e.length, T = new Uint8Array(_), I = new DataView(T.buffer);
|
|
34
|
+
I.setUint32(0, _, !0), I.setUint32(4, t >>> 0, !0), I.setUint32(8, r >>> 0, !0), I.setUint32(12, 0, !0), I.setUint32(16, 0, !0), I.setUint32(20, o.length >>> 0, !0), I.setUint8(24, s & 255), I.setUint8(25, 8), I.setUint8(26, 0);
|
|
35
|
+
let w = 27;
|
|
36
|
+
for (let D = 0; D < o.length; D++)
|
|
37
|
+
I.setUint32(w, o[D] >>> 0, !0), w += 4;
|
|
38
|
+
return T.set(e, l), T;
|
|
39
|
+
}
|
|
40
|
+
var m = /* @__PURE__ */ ((t) => (t[t.Null = 1] = "Null", t[t.Bool = 2] = "Bool", t[t.Int32 = 3] = "Int32", t[t.Int64 = 4] = "Int64", t[t.UInt32 = 5] = "UInt32", t[t.UInt64 = 6] = "UInt64", t[t.Float32 = 7] = "Float32", t[t.Float64 = 8] = "Float64", t[t.Array = 9] = "Array", t[t.Dict = 10] = "Dict", t[t.Object = 11] = "Object", t[t.String = 12] = "String", t[t.Binary = 13] = "Binary", t[t.Guid = 14] = "Guid", t))(m || {});
|
|
41
|
+
const ht = 161, Tt = 162, K = new TextEncoder();
|
|
42
|
+
new TextDecoder("utf-8", { fatal: !0 });
|
|
43
|
+
class V {
|
|
44
|
+
constructor(e = 1) {
|
|
45
|
+
this.version = e, this.buffer.writeByte(ht), this.buffer.writeVarUInt(e >>> 0);
|
|
46
|
+
}
|
|
47
|
+
buffer = new O();
|
|
48
|
+
closed = !1;
|
|
49
|
+
cached;
|
|
50
|
+
writeInt32Field(e, s) {
|
|
51
|
+
this.writeFixedField(e, 3, () => this.buffer.writeInt32(s | 0));
|
|
52
|
+
}
|
|
53
|
+
writeUInt32Field(e, s) {
|
|
54
|
+
this.writeFixedField(e, 5, () => this.buffer.writeUInt32(s >>> 0));
|
|
55
|
+
}
|
|
56
|
+
writeInt64Field(e, s) {
|
|
57
|
+
this.writeFixedField(e, 4, () => this.buffer.writeBigInt64(s));
|
|
58
|
+
}
|
|
59
|
+
writeUInt64Field(e, s) {
|
|
60
|
+
this.writeFixedField(e, 6, () => this.buffer.writeBigUInt64(s));
|
|
61
|
+
}
|
|
62
|
+
writeFloat32Field(e, s) {
|
|
63
|
+
this.writeFixedField(e, 7, () => this.buffer.writeFloat32(s));
|
|
64
|
+
}
|
|
65
|
+
writeFloat64Field(e, s) {
|
|
66
|
+
this.writeFixedField(e, 8, () => this.buffer.writeFloat64(s));
|
|
67
|
+
}
|
|
68
|
+
writeBoolField(e, s) {
|
|
69
|
+
this.writeFixedField(e, 2, () => this.buffer.writeByte(s ? 1 : 0));
|
|
70
|
+
}
|
|
71
|
+
writeGuidField(e, s) {
|
|
72
|
+
const r = s instanceof h ? s.asBytes() : s;
|
|
73
|
+
if (r.length !== 16)
|
|
74
|
+
throw new Error("Guid payload must be 16 bytes");
|
|
75
|
+
this.writeFixedField(e, 14, () => this.buffer.writeBytes(r));
|
|
76
|
+
}
|
|
77
|
+
writeStringField(e, s) {
|
|
78
|
+
const r = K.encode(s ?? "");
|
|
79
|
+
this.writeVariableField(e, 12, r);
|
|
80
|
+
}
|
|
81
|
+
writeBinaryField(e, s) {
|
|
82
|
+
this.writeVariableField(e, 13, s);
|
|
83
|
+
}
|
|
84
|
+
writeObjectField(e, s, r) {
|
|
85
|
+
const n = new V(s);
|
|
86
|
+
r(n);
|
|
87
|
+
const i = n.finish();
|
|
88
|
+
this.writeVariableField(e, 11, i);
|
|
89
|
+
}
|
|
90
|
+
writeArrayField(e, s, r) {
|
|
91
|
+
const n = new x(s);
|
|
92
|
+
r(n);
|
|
93
|
+
const i = n.finish();
|
|
94
|
+
this.writeVariableField(e, 9, i);
|
|
95
|
+
}
|
|
96
|
+
writeDictionaryField(e, s, r, n) {
|
|
97
|
+
const i = new Z(s, r);
|
|
98
|
+
n(i);
|
|
99
|
+
const E = i.finish();
|
|
100
|
+
this.writeVariableField(e, 10, E);
|
|
101
|
+
}
|
|
102
|
+
finish() {
|
|
103
|
+
return this.closed || (this.buffer.writeByte(Tt), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
|
|
104
|
+
}
|
|
105
|
+
writeFixedField(e, s, r) {
|
|
106
|
+
this.writeFieldHeader(e, s, 0), r();
|
|
107
|
+
}
|
|
108
|
+
writeVariableField(e, s, r) {
|
|
109
|
+
this.writeFieldHeader(e, s, r.length), this.buffer.writeBytes(r);
|
|
110
|
+
}
|
|
111
|
+
writeFieldHeader(e, s, r) {
|
|
112
|
+
this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(H(s)), ct(s) && this.buffer.writeVarUInt(r >>> 0);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class x {
|
|
116
|
+
constructor(e) {
|
|
117
|
+
this.elementType = e;
|
|
118
|
+
}
|
|
119
|
+
payload = new O();
|
|
120
|
+
count = 0;
|
|
121
|
+
writeInt32(e) {
|
|
122
|
+
this.ensureElementType(
|
|
123
|
+
3
|
|
124
|
+
/* Int32 */
|
|
125
|
+
), this.count++, this.payload.writeInt32(e | 0);
|
|
126
|
+
}
|
|
127
|
+
writeUInt32(e) {
|
|
128
|
+
this.ensureElementType(
|
|
129
|
+
5
|
|
130
|
+
/* UInt32 */
|
|
131
|
+
), this.count++, this.payload.writeUInt32(e >>> 0);
|
|
132
|
+
}
|
|
133
|
+
writeInt64(e) {
|
|
134
|
+
this.ensureElementType(
|
|
135
|
+
4
|
|
136
|
+
/* Int64 */
|
|
137
|
+
), this.count++, this.payload.writeBigInt64(e);
|
|
138
|
+
}
|
|
139
|
+
writeUInt64(e) {
|
|
140
|
+
this.ensureElementType(
|
|
141
|
+
6
|
|
142
|
+
/* UInt64 */
|
|
143
|
+
), this.count++, this.payload.writeBigUInt64(e);
|
|
144
|
+
}
|
|
145
|
+
writeFloat32(e) {
|
|
146
|
+
this.ensureElementType(
|
|
147
|
+
7
|
|
148
|
+
/* Float32 */
|
|
149
|
+
), this.count++, this.payload.writeFloat32(e);
|
|
150
|
+
}
|
|
151
|
+
writeFloat64(e) {
|
|
152
|
+
this.ensureElementType(
|
|
153
|
+
8
|
|
154
|
+
/* Float64 */
|
|
155
|
+
), this.count++, this.payload.writeFloat64(e);
|
|
156
|
+
}
|
|
157
|
+
writeBool(e) {
|
|
158
|
+
this.ensureElementType(
|
|
159
|
+
2
|
|
160
|
+
/* Bool */
|
|
161
|
+
), this.count++, this.payload.writeByte(e ? 1 : 0);
|
|
162
|
+
}
|
|
163
|
+
writeGuid(e) {
|
|
164
|
+
this.ensureElementType(
|
|
165
|
+
14
|
|
166
|
+
/* Guid */
|
|
167
|
+
), this.count++;
|
|
168
|
+
const s = e instanceof h ? e.asBytes() : e;
|
|
169
|
+
if (s.length !== 16)
|
|
170
|
+
throw new Error("Guid payload must be 16 bytes");
|
|
171
|
+
this.payload.writeBytes(s);
|
|
172
|
+
}
|
|
173
|
+
writeString(e) {
|
|
174
|
+
this.ensureElementType(
|
|
175
|
+
12
|
|
176
|
+
/* String */
|
|
177
|
+
), this.count++;
|
|
178
|
+
const s = K.encode(e ?? "");
|
|
179
|
+
this.payload.writeVarUInt(s.length), this.payload.writeBytes(s);
|
|
180
|
+
}
|
|
181
|
+
writeBinary(e) {
|
|
182
|
+
this.ensureElementType(
|
|
183
|
+
13
|
|
184
|
+
/* Binary */
|
|
185
|
+
), this.count++, this.payload.writeVarUInt(e.length), this.payload.writeBytes(e);
|
|
186
|
+
}
|
|
187
|
+
writeObject(e, s) {
|
|
188
|
+
this.ensureElementType(
|
|
189
|
+
11
|
|
190
|
+
/* Object */
|
|
191
|
+
), this.count++;
|
|
192
|
+
const r = new V(e);
|
|
193
|
+
s(r);
|
|
194
|
+
const n = r.finish();
|
|
195
|
+
this.payload.writeVarUInt(n.length), this.payload.writeBytes(n);
|
|
196
|
+
}
|
|
197
|
+
writeArray(e, s) {
|
|
198
|
+
this.ensureElementType(
|
|
199
|
+
9
|
|
200
|
+
/* Array */
|
|
201
|
+
), this.count++;
|
|
202
|
+
const r = new x(e);
|
|
203
|
+
s(r);
|
|
204
|
+
const n = r.finish();
|
|
205
|
+
this.payload.writeBytes(n);
|
|
206
|
+
}
|
|
207
|
+
writeDictionary(e, s, r) {
|
|
208
|
+
this.ensureElementType(
|
|
209
|
+
10
|
|
210
|
+
/* Dict */
|
|
211
|
+
), this.count++;
|
|
212
|
+
const n = new Z(e, s);
|
|
213
|
+
r(n);
|
|
214
|
+
const i = n.finish();
|
|
215
|
+
this.payload.writeBytes(i);
|
|
216
|
+
}
|
|
217
|
+
finish() {
|
|
218
|
+
const e = new O();
|
|
219
|
+
return e.writeByte(H(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
|
|
220
|
+
}
|
|
221
|
+
ensureElementType(e) {
|
|
222
|
+
if (this.elementType !== e)
|
|
223
|
+
throw new Error(`Array element type is ${m[this.elementType]}, expected ${m[e]}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
class Z {
|
|
227
|
+
constructor(e, s) {
|
|
228
|
+
this.keyType = e, this.valueType = s, At(e);
|
|
229
|
+
}
|
|
230
|
+
payload = new O();
|
|
231
|
+
count = 0;
|
|
232
|
+
entryOpen = !1;
|
|
233
|
+
beginEntry() {
|
|
234
|
+
if (this.entryOpen)
|
|
235
|
+
throw new Error("Previous dictionary entry not completed");
|
|
236
|
+
return this.count++, this.entryOpen = !0, new It(this.keyType, this.valueType, this.payload, () => {
|
|
237
|
+
this.entryOpen = !1;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
finish() {
|
|
241
|
+
if (this.entryOpen)
|
|
242
|
+
throw new Error("Dictionary entry not completed");
|
|
243
|
+
const e = new O();
|
|
244
|
+
return e.writeByte(H(this.keyType)), e.writeByte(H(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
class It {
|
|
248
|
+
constructor(e, s, r, n) {
|
|
249
|
+
this.keyType = e, this.valueType = s, this.payload = r, this.onComplete = n;
|
|
250
|
+
}
|
|
251
|
+
keyWritten = !1;
|
|
252
|
+
valueWritten = !1;
|
|
253
|
+
completed = !1;
|
|
254
|
+
writeKeyInt32(e) {
|
|
255
|
+
this.ensureKeyType(
|
|
256
|
+
3
|
|
257
|
+
/* Int32 */
|
|
258
|
+
), this.payload.writeInt32(e | 0), this.keyWritten = !0;
|
|
259
|
+
}
|
|
260
|
+
writeKeyUInt32(e) {
|
|
261
|
+
this.ensureKeyType(
|
|
262
|
+
5
|
|
263
|
+
/* UInt32 */
|
|
264
|
+
), this.payload.writeUInt32(e >>> 0), this.keyWritten = !0;
|
|
265
|
+
}
|
|
266
|
+
writeKeyInt64(e) {
|
|
267
|
+
this.ensureKeyType(
|
|
268
|
+
4
|
|
269
|
+
/* Int64 */
|
|
270
|
+
), this.payload.writeBigInt64(e), this.keyWritten = !0;
|
|
271
|
+
}
|
|
272
|
+
writeKeyUInt64(e) {
|
|
273
|
+
this.ensureKeyType(
|
|
274
|
+
6
|
|
275
|
+
/* UInt64 */
|
|
276
|
+
), this.payload.writeBigUInt64(e), this.keyWritten = !0;
|
|
277
|
+
}
|
|
278
|
+
writeKeyFloat32(e) {
|
|
279
|
+
this.ensureKeyType(
|
|
280
|
+
7
|
|
281
|
+
/* Float32 */
|
|
282
|
+
), this.payload.writeFloat32(e), this.keyWritten = !0;
|
|
283
|
+
}
|
|
284
|
+
writeKeyFloat64(e) {
|
|
285
|
+
this.ensureKeyType(
|
|
286
|
+
8
|
|
287
|
+
/* Float64 */
|
|
288
|
+
), this.payload.writeFloat64(e), this.keyWritten = !0;
|
|
289
|
+
}
|
|
290
|
+
writeKeyBool(e) {
|
|
291
|
+
this.ensureKeyType(
|
|
292
|
+
2
|
|
293
|
+
/* Bool */
|
|
294
|
+
), this.payload.writeByte(e ? 1 : 0), this.keyWritten = !0;
|
|
295
|
+
}
|
|
296
|
+
writeKeyGuid(e) {
|
|
297
|
+
this.ensureKeyType(
|
|
298
|
+
14
|
|
299
|
+
/* Guid */
|
|
300
|
+
);
|
|
301
|
+
const s = e instanceof h ? e.asBytes() : e;
|
|
302
|
+
if (s.length !== 16)
|
|
303
|
+
throw new Error("Guid payload must be 16 bytes");
|
|
304
|
+
this.payload.writeBytes(s), this.keyWritten = !0;
|
|
305
|
+
}
|
|
306
|
+
writeKeyString(e) {
|
|
307
|
+
this.ensureKeyType(
|
|
308
|
+
12
|
|
309
|
+
/* String */
|
|
310
|
+
);
|
|
311
|
+
const s = K.encode(e ?? "");
|
|
312
|
+
this.payload.writeVarUInt(s.length), this.payload.writeBytes(s), this.keyWritten = !0;
|
|
313
|
+
}
|
|
314
|
+
writeKeyBinary(e) {
|
|
315
|
+
this.ensureKeyType(
|
|
316
|
+
13
|
|
317
|
+
/* Binary */
|
|
318
|
+
), this.payload.writeVarUInt(e.length), this.payload.writeBytes(e), this.keyWritten = !0;
|
|
319
|
+
}
|
|
320
|
+
writeValueInt32(e) {
|
|
321
|
+
this.ensureValueType(
|
|
322
|
+
3
|
|
323
|
+
/* Int32 */
|
|
324
|
+
), this.payload.writeInt32(e | 0), this.valueWritten = !0;
|
|
325
|
+
}
|
|
326
|
+
writeValueUInt32(e) {
|
|
327
|
+
this.ensureValueType(
|
|
328
|
+
5
|
|
329
|
+
/* UInt32 */
|
|
330
|
+
), this.payload.writeUInt32(e >>> 0), this.valueWritten = !0;
|
|
331
|
+
}
|
|
332
|
+
writeValueInt64(e) {
|
|
333
|
+
this.ensureValueType(
|
|
334
|
+
4
|
|
335
|
+
/* Int64 */
|
|
336
|
+
), this.payload.writeBigInt64(e), this.valueWritten = !0;
|
|
337
|
+
}
|
|
338
|
+
writeValueUInt64(e) {
|
|
339
|
+
this.ensureValueType(
|
|
340
|
+
6
|
|
341
|
+
/* UInt64 */
|
|
342
|
+
), this.payload.writeBigUInt64(e), this.valueWritten = !0;
|
|
343
|
+
}
|
|
344
|
+
writeValueFloat32(e) {
|
|
345
|
+
this.ensureValueType(
|
|
346
|
+
7
|
|
347
|
+
/* Float32 */
|
|
348
|
+
), this.payload.writeFloat32(e), this.valueWritten = !0;
|
|
349
|
+
}
|
|
350
|
+
writeValueFloat64(e) {
|
|
351
|
+
this.ensureValueType(
|
|
352
|
+
8
|
|
353
|
+
/* Float64 */
|
|
354
|
+
), this.payload.writeFloat64(e), this.valueWritten = !0;
|
|
355
|
+
}
|
|
356
|
+
writeValueBool(e) {
|
|
357
|
+
this.ensureValueType(
|
|
358
|
+
2
|
|
359
|
+
/* Bool */
|
|
360
|
+
), this.payload.writeByte(e ? 1 : 0), this.valueWritten = !0;
|
|
361
|
+
}
|
|
362
|
+
writeValueGuid(e) {
|
|
363
|
+
this.ensureValueType(
|
|
364
|
+
14
|
|
365
|
+
/* Guid */
|
|
366
|
+
);
|
|
367
|
+
const s = e instanceof h ? e.asBytes() : e;
|
|
368
|
+
if (s.length !== 16)
|
|
369
|
+
throw new Error("Guid payload must be 16 bytes");
|
|
370
|
+
this.payload.writeBytes(s), this.valueWritten = !0;
|
|
371
|
+
}
|
|
372
|
+
writeNullValue() {
|
|
373
|
+
this.ensureValueType(
|
|
374
|
+
1
|
|
375
|
+
/* Null */
|
|
376
|
+
), this.valueWritten = !0;
|
|
377
|
+
}
|
|
378
|
+
writeValueBinary(e) {
|
|
379
|
+
this.ensureValueType(
|
|
380
|
+
13
|
|
381
|
+
/* Binary */
|
|
382
|
+
), this.payload.writeVarUInt(e.length), this.payload.writeBytes(e), this.valueWritten = !0;
|
|
383
|
+
}
|
|
384
|
+
writeValueString(e) {
|
|
385
|
+
this.ensureValueType(
|
|
386
|
+
12
|
|
387
|
+
/* String */
|
|
388
|
+
);
|
|
389
|
+
const s = K.encode(e ?? "");
|
|
390
|
+
this.payload.writeVarUInt(s.length), this.payload.writeBytes(s), this.valueWritten = !0;
|
|
391
|
+
}
|
|
392
|
+
writeValueObject(e, s) {
|
|
393
|
+
this.ensureValueType(
|
|
394
|
+
11
|
|
395
|
+
/* Object */
|
|
396
|
+
);
|
|
397
|
+
const r = new V(e);
|
|
398
|
+
s(r);
|
|
399
|
+
const n = r.finish();
|
|
400
|
+
this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.valueWritten = !0;
|
|
401
|
+
}
|
|
402
|
+
writeValueArray(e, s) {
|
|
403
|
+
this.ensureValueType(
|
|
404
|
+
9
|
|
405
|
+
/* Array */
|
|
406
|
+
);
|
|
407
|
+
const r = new x(e);
|
|
408
|
+
s(r);
|
|
409
|
+
const n = r.finish();
|
|
410
|
+
this.payload.writeBytes(n), this.valueWritten = !0;
|
|
411
|
+
}
|
|
412
|
+
writeValueDictionary(e, s, r) {
|
|
413
|
+
this.ensureValueType(
|
|
414
|
+
10
|
|
415
|
+
/* Dict */
|
|
416
|
+
);
|
|
417
|
+
const n = new Z(e, s);
|
|
418
|
+
r(n);
|
|
419
|
+
const i = n.finish();
|
|
420
|
+
this.payload.writeBytes(i), this.valueWritten = !0;
|
|
421
|
+
}
|
|
422
|
+
complete() {
|
|
423
|
+
if (!this.completed) {
|
|
424
|
+
if (!this.keyWritten || !this.valueWritten)
|
|
425
|
+
throw new Error("Dictionary entry must write both key and value");
|
|
426
|
+
this.completed = !0, this.onComplete();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
ensureKeyType(e) {
|
|
430
|
+
if (this.keyType !== e)
|
|
431
|
+
throw new Error(`Dictionary key type is ${m[this.keyType]}, expected ${m[e]}`);
|
|
432
|
+
}
|
|
433
|
+
ensureValueType(e) {
|
|
434
|
+
if (this.valueType !== e)
|
|
435
|
+
throw new Error(`Dictionary value type is ${m[this.valueType]}, expected ${m[e]}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
class h {
|
|
439
|
+
constructor(e) {
|
|
440
|
+
this.bytes = e;
|
|
441
|
+
}
|
|
442
|
+
static fromString(e) {
|
|
443
|
+
if (!e)
|
|
444
|
+
throw new Error("Guid string is empty");
|
|
445
|
+
const s = e.replace(/-/g, "");
|
|
446
|
+
if (s.length !== 32)
|
|
447
|
+
throw new Error("Guid string must be 32 hex characters");
|
|
448
|
+
const r = new Uint8Array(16), n = h.parseHexSlice(s, 0, 8), i = h.parseHexSlice(s, 8, 4), E = h.parseHexSlice(s, 12, 4);
|
|
449
|
+
h.writeUInt32LE(r, 0, n), h.writeUInt16LE(r, 4, i), h.writeUInt16LE(r, 6, E);
|
|
450
|
+
for (let a = 0; a < 8; a++)
|
|
451
|
+
r[8 + a] = h.parseHexSlice(s, 16 + a * 2, 2);
|
|
452
|
+
return new h(r);
|
|
453
|
+
}
|
|
454
|
+
static fromBytes(e) {
|
|
455
|
+
if (e.length !== 16)
|
|
456
|
+
throw new Error("Guid byte array must be 16 bytes");
|
|
457
|
+
return new h(Uint8Array.from(e));
|
|
458
|
+
}
|
|
459
|
+
static createZero() {
|
|
460
|
+
return new h(new Uint8Array(16));
|
|
461
|
+
}
|
|
462
|
+
static createRandom() {
|
|
463
|
+
const e = new Uint8Array(16), s = globalThis.crypto;
|
|
464
|
+
if (s?.getRandomValues)
|
|
465
|
+
s.getRandomValues(e);
|
|
466
|
+
else
|
|
467
|
+
for (let r = 0; r < e.length; r++)
|
|
468
|
+
e[r] = Math.floor(Math.random() * 256);
|
|
469
|
+
return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new h(e);
|
|
470
|
+
}
|
|
471
|
+
toString() {
|
|
472
|
+
const e = this.bytes;
|
|
473
|
+
return [
|
|
474
|
+
h.toHex(h.readUInt32LE(e, 0), 8),
|
|
475
|
+
h.toHex(h.readUInt16LE(e, 4), 4),
|
|
476
|
+
h.toHex(h.readUInt16LE(e, 6), 4),
|
|
477
|
+
J(e.subarray(8, 10)),
|
|
478
|
+
J(e.subarray(10, 16))
|
|
479
|
+
].join("-");
|
|
480
|
+
}
|
|
481
|
+
asBytes() {
|
|
482
|
+
return this.bytes.slice();
|
|
483
|
+
}
|
|
484
|
+
static parseHexSlice(e, s, r) {
|
|
485
|
+
const n = e.substr(s, r), i = Number.parseInt(n, 16);
|
|
486
|
+
if (Number.isNaN(i))
|
|
487
|
+
throw new Error("Guid string contains invalid characters");
|
|
488
|
+
return i >>> 0;
|
|
489
|
+
}
|
|
490
|
+
static writeUInt32LE(e, s, r) {
|
|
491
|
+
const n = r >>> 0;
|
|
492
|
+
e[s] = n & 255, e[s + 1] = n >>> 8 & 255, e[s + 2] = n >>> 16 & 255, e[s + 3] = n >>> 24 & 255;
|
|
493
|
+
}
|
|
494
|
+
static writeUInt16LE(e, s, r) {
|
|
495
|
+
const n = r & 65535;
|
|
496
|
+
e[s] = n & 255, e[s + 1] = n >>> 8 & 255;
|
|
497
|
+
}
|
|
498
|
+
static readUInt32LE(e, s) {
|
|
499
|
+
return (e[s] | e[s + 1] << 8 | e[s + 2] << 16 | e[s + 3] << 24) >>> 0;
|
|
500
|
+
}
|
|
501
|
+
static readUInt16LE(e, s) {
|
|
502
|
+
return (e[s] | e[s + 1] << 8) & 65535;
|
|
503
|
+
}
|
|
504
|
+
static toHex(e, s) {
|
|
505
|
+
return (e >>> 0).toString(16).padStart(s, "0");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
class O {
|
|
509
|
+
static INITIAL_CAPACITY = 256;
|
|
510
|
+
buffer;
|
|
511
|
+
dataView;
|
|
512
|
+
length = 0;
|
|
513
|
+
constructor() {
|
|
514
|
+
this.buffer = new Uint8Array(O.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
|
|
515
|
+
}
|
|
516
|
+
ensureCapacity(e) {
|
|
517
|
+
const s = this.length + e;
|
|
518
|
+
if (s <= this.buffer.length)
|
|
519
|
+
return;
|
|
520
|
+
let r = this.buffer.length;
|
|
521
|
+
for (; r < s; )
|
|
522
|
+
r *= 2;
|
|
523
|
+
const n = new Uint8Array(r);
|
|
524
|
+
n.set(this.buffer.subarray(0, this.length)), this.buffer = n, this.dataView = new DataView(this.buffer.buffer);
|
|
525
|
+
}
|
|
526
|
+
writeByte(e) {
|
|
527
|
+
this.ensureCapacity(1), this.buffer[this.length++] = e & 255;
|
|
528
|
+
}
|
|
529
|
+
writeBytes(e) {
|
|
530
|
+
this.ensureCapacity(e.length), this.buffer.set(e, this.length), this.length += e.length;
|
|
531
|
+
}
|
|
532
|
+
writeUInt32(e) {
|
|
533
|
+
this.ensureCapacity(4), this.dataView.setUint32(this.length, e >>> 0, !0), this.length += 4;
|
|
534
|
+
}
|
|
535
|
+
writeInt32(e) {
|
|
536
|
+
this.ensureCapacity(4), this.dataView.setInt32(this.length, e | 0, !0), this.length += 4;
|
|
537
|
+
}
|
|
538
|
+
writeFloat32(e) {
|
|
539
|
+
this.ensureCapacity(4), this.dataView.setFloat32(this.length, e, !0), this.length += 4;
|
|
540
|
+
}
|
|
541
|
+
writeFloat64(e) {
|
|
542
|
+
this.ensureCapacity(8), this.dataView.setFloat64(this.length, e, !0), this.length += 8;
|
|
543
|
+
}
|
|
544
|
+
writeBigInt64(e) {
|
|
545
|
+
this.ensureCapacity(8), this.dataView.setBigInt64(this.length, e, !0), this.length += 8;
|
|
546
|
+
}
|
|
547
|
+
writeBigUInt64(e) {
|
|
548
|
+
this.ensureCapacity(8), this.dataView.setBigUint64(this.length, e, !0), this.length += 8;
|
|
549
|
+
}
|
|
550
|
+
writeVarUInt(e) {
|
|
551
|
+
let s = e >>> 0;
|
|
552
|
+
for (; s >= 128; )
|
|
553
|
+
this.ensureCapacity(1), this.buffer[this.length++] = s & 127 | 128, s >>>= 7;
|
|
554
|
+
this.ensureCapacity(1), this.buffer[this.length++] = s & 127;
|
|
555
|
+
}
|
|
556
|
+
toUint8Array() {
|
|
557
|
+
return this.buffer.slice(0, this.length);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function H(t, e = 0) {
|
|
561
|
+
if ((e & 240) !== 0)
|
|
562
|
+
throw new Error("Teleport flags must fit into 4 bits");
|
|
563
|
+
return (t & 15) << 4 | e & 15;
|
|
564
|
+
}
|
|
565
|
+
function ct(t) {
|
|
566
|
+
return t === 12 || t === 13 || t === 9 || t === 11 || t === 10;
|
|
567
|
+
}
|
|
568
|
+
function At(t) {
|
|
569
|
+
if (t === 9 || t === 11 || t === 10 || t === 1)
|
|
570
|
+
throw new Error("Dictionary keys must be primitive Teleport types");
|
|
571
|
+
}
|
|
572
|
+
function J(t) {
|
|
573
|
+
return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
574
|
+
}
|
|
575
|
+
function ut(t) {
|
|
576
|
+
return t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
577
|
+
}
|
|
578
|
+
var f = /* @__PURE__ */ ((t) => (t[t.None = 0] = "None", t[t.WebSocket = 1] = "WebSocket", t[t.WebSocketProxy = 2] = "WebSocketProxy", t[t.WebTransport = 4] = "WebTransport", t[t.WebTransportProxy = 8] = "WebTransportProxy", t[t.Tcp = 16] = "Tcp", t[t.TcpProxy = 32] = "TcpProxy", t[t.Https = 64] = "Https", t[t.WebRTC = 128] = "WebRTC", t[t.TcpTls = 256] = "TcpTls", t[t.Udp = 512] = "Udp", t[t.UdpDtls = 1024] = "UdpDtls", t))(f || {}), k = /* @__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.CORE_UPDATE_CLIENT_CONTEXT = 65558] = "CORE_UPDATE_CLIENT_CONTEXT", t[t.CORE_BACKGROUND_WORK_ACTIVE = 65559] = "CORE_BACKGROUND_WORK_ACTIVE", t[t.CORE_RESET_IDLE = 65560] = "CORE_RESET_IDLE", t[t.CORE_CLIENT_DISCONNECTING = 65561] = "CORE_CLIENT_DISCONNECTING", t[t.CORE_WEBRTC_OFFER = 65566] = "CORE_WEBRTC_OFFER", t[t.CORE_WEBRTC_ANSWER = 65567] = "CORE_WEBRTC_ANSWER", t[t.CORE_WEBRTC_ICE_CANDIDATE = 65568] = "CORE_WEBRTC_ICE_CANDIDATE", t[t.CORE_WEBRTC_READY = 65569] = "CORE_WEBRTC_READY", t[t.CORE_WEBRTC_AUDIO_SEGMENT = 65570] = "CORE_WEBRTC_AUDIO_SEGMENT", t[t.CORE_WEBRTC_TRACK_MAP = 65571] = "CORE_WEBRTC_TRACK_MAP", t[t.CORE_WEBRTC_VIDEO_CAPTURE = 65572] = "CORE_WEBRTC_VIDEO_CAPTURE", t[t.CORE_RELAY_AGENT_AUTH = 65576] = "CORE_RELAY_AGENT_AUTH", t[t.CORE_RELAY_AGENT_AUTH_RESULT = 65577] = "CORE_RELAY_AGENT_AUTH_RESULT", t[t.CORE_RELAY_HEARTBEAT = 65578] = "CORE_RELAY_HEARTBEAT", t[t.CORE_RELAY_TCP_CONNECTION_OPENED = 65579] = "CORE_RELAY_TCP_CONNECTION_OPENED", t[t.CORE_RELAY_TCP_CONNECTION_CLOSED = 65580] = "CORE_RELAY_TCP_CONNECTION_CLOSED", t[t.CORE_RELAY_TCP_DATA = 65581] = "CORE_RELAY_TCP_DATA", t[t.CORE_RELAY_UDP_DATA = 65582] = "CORE_RELAY_UDP_DATA", t[t.CORE_RELAY_ADD_TUNNEL = 65583] = "CORE_RELAY_ADD_TUNNEL", t[t.CORE_RELAY_TUNNEL_ADDED = 65584] = "CORE_RELAY_TUNNEL_ADDED", t[t.CORE_RELAY_REMOVE_TUNNEL = 65585] = "CORE_RELAY_REMOVE_TUNNEL", t[t.CORE_IKON_SERVER_ENDPOINT_HOST_INFO = 65586] = "CORE_IKON_SERVER_ENDPOINT_HOST_INFO", t[t.CORE_CLIENT_INITIALIZATION = 65587] = "CORE_CLIENT_INITIALIZATION", t[t.CORE_CLIENT_LIFECYCLE_BATCH = 65588] = "CORE_CLIENT_LIFECYCLE_BATCH", t[t.CORE_APP_CONFIG = 65589] = "CORE_APP_CONFIG", 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.ANALYTICS_IKON_RELAY_SERVER_STATS = 524297] = "ANALYTICS_IKON_RELAY_SERVER_STATS", t[t.ANALYTICS_IKON_TURN_SERVER_STATS = 524298] = "ANALYTICS_IKON_TURN_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_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.ACTION_TRIGGER_GIT_PULL = 1048639] = "ACTION_TRIGGER_GIT_PULL", t[t.ACTION_FILE_UPLOAD_CALLBACK = 1048640] = "ACTION_FILE_UPLOAD_CALLBACK", t[t.ACTION_CUSTOM_USER_MESSAGE = 1048641] = "ACTION_CUSTOM_USER_MESSAGE", t[t.ACTION_URL_CHANGED = 1048642] = "ACTION_URL_CHANGED", t[t.ACTION_FILE_UPLOAD_PRE_START2 = 1048643] = "ACTION_FILE_UPLOAD_PRE_START2", t[t.ACTION_FILE_UPLOAD_PRE_START_RESPONSE2 = 1048644] = "ACTION_FILE_UPLOAD_PRE_START_RESPONSE2", t[t.ACTION_FILE_UPLOAD_START2 = 1048645] = "ACTION_FILE_UPLOAD_START2", t[t.ACTION_FILE_UPLOAD_START_RESPONSE2 = 1048646] = "ACTION_FILE_UPLOAD_START_RESPONSE2", t[t.ACTION_FILE_UPLOAD_DATA2 = 1048647] = "ACTION_FILE_UPLOAD_DATA2", t[t.ACTION_FILE_UPLOAD_ACK2 = 1048648] = "ACTION_FILE_UPLOAD_ACK2", t[t.ACTION_FILE_UPLOAD_END2 = 1048649] = "ACTION_FILE_UPLOAD_END2", t[t.ACTION_FILE_UPLOAD_COMPLETE2 = 1048650] = "ACTION_FILE_UPLOAD_COMPLETE2", t[t.ACTION_FUNCTION_ENUMERATION_ITEM_BATCH = 1048651] = "ACTION_FUNCTION_ENUMERATION_ITEM_BATCH", t[t.ACTION_CALL_ACK = 1048652] = "ACTION_CALL_ACK", t[t.ACTION_TRIGGER_CRON = 1048653] = "ACTION_TRIGGER_CRON", 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.UI_STYLES_DELETE = 2097193] = "UI_STYLES_DELETE", 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.AUDIO_SHAPE_FRAME = 4194310] = "AUDIO_SHAPE_FRAME", 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.GROUP_APP_LOCAL = 1073741824] = "GROUP_APP_LOCAL", t[t.CONSTANT_GROUP_MASK = 2147418112] = "CONSTANT_GROUP_MASK", t))(k || {});
|
|
579
|
+
const st = 1, Ct = 131074;
|
|
580
|
+
function rt(t) {
|
|
581
|
+
return {};
|
|
582
|
+
}
|
|
583
|
+
function Nt(t) {
|
|
584
|
+
return new V(st).finish();
|
|
585
|
+
}
|
|
586
|
+
function nt(t, e, s) {
|
|
587
|
+
const r = Nt();
|
|
588
|
+
return _t(Ct, r, st, e);
|
|
589
|
+
}
|
|
590
|
+
class it extends Error {
|
|
591
|
+
constructor(e, s) {
|
|
592
|
+
super(e), this.cause = s, this.name = "ConnectionError";
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
class y extends it {
|
|
596
|
+
constructor(e, s) {
|
|
597
|
+
super(e, s), this.name = "TransportError";
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
class q extends y {
|
|
601
|
+
constructor(e) {
|
|
602
|
+
super(`No keepalive received within ${e}ms`), this.name = "KeepaliveTimeoutError";
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
class b extends y {
|
|
606
|
+
constructor(e, s) {
|
|
607
|
+
super(e, s), this.name = "AuthRejectedError";
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
class tt extends it {
|
|
611
|
+
constructor(e) {
|
|
612
|
+
super(`Maximum reconnection attempts (${e}) exceeded`), this.name = "MaxRetriesExceededError";
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function ft(t, e) {
|
|
616
|
+
return new Promise((s, r) => {
|
|
617
|
+
const n = () => {
|
|
618
|
+
clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
|
|
619
|
+
}, i = setTimeout(() => {
|
|
620
|
+
e?.removeEventListener("abort", n), s();
|
|
621
|
+
}, t);
|
|
622
|
+
if (e?.aborted) {
|
|
623
|
+
clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
e?.addEventListener("abort", n, { once: !0 });
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
let at = 1;
|
|
630
|
+
const Rt = /* @__PURE__ */ new Map();
|
|
631
|
+
function Ut(t) {
|
|
632
|
+
at = t;
|
|
633
|
+
}
|
|
634
|
+
const yt = {
|
|
635
|
+
0: "DEBUG",
|
|
636
|
+
1: "INFO",
|
|
637
|
+
2: "WARN",
|
|
638
|
+
3: "ERROR",
|
|
639
|
+
4: "NONE"
|
|
640
|
+
};
|
|
641
|
+
function St(t, e) {
|
|
642
|
+
return `[${t}] ${e}`;
|
|
643
|
+
}
|
|
644
|
+
function W(t, e, s, r) {
|
|
645
|
+
const n = (/* @__PURE__ */ new Date()).toISOString(), i = yt[t], E = {
|
|
646
|
+
timestamp: n,
|
|
647
|
+
level: t,
|
|
648
|
+
levelName: i,
|
|
649
|
+
component: e,
|
|
650
|
+
message: s,
|
|
651
|
+
args: r
|
|
652
|
+
};
|
|
653
|
+
for (const [a, o] of Rt) {
|
|
654
|
+
const c = o?.minLevel ?? 2;
|
|
655
|
+
if (t >= c)
|
|
656
|
+
try {
|
|
657
|
+
a(E);
|
|
658
|
+
} catch {
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if (at <= t) {
|
|
662
|
+
const a = St(e, s);
|
|
663
|
+
switch (t) {
|
|
664
|
+
case 0:
|
|
665
|
+
console.debug(a, ...r);
|
|
666
|
+
break;
|
|
667
|
+
case 1:
|
|
668
|
+
console.info(a, ...r);
|
|
669
|
+
break;
|
|
670
|
+
case 2:
|
|
671
|
+
console.warn(a, ...r);
|
|
672
|
+
break;
|
|
673
|
+
case 3:
|
|
674
|
+
console.error(a, ...r);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function p(t) {
|
|
680
|
+
return {
|
|
681
|
+
debug(e, ...s) {
|
|
682
|
+
W(0, t, e, s);
|
|
683
|
+
},
|
|
684
|
+
info(e, ...s) {
|
|
685
|
+
W(1, t, e, s);
|
|
686
|
+
},
|
|
687
|
+
warn(e, ...s) {
|
|
688
|
+
W(2, t, e, s);
|
|
689
|
+
},
|
|
690
|
+
error(e, ...s) {
|
|
691
|
+
W(3, t, e, s);
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
const wt = "ikon-retry";
|
|
696
|
+
function Lt(t, e) {
|
|
697
|
+
if (typeof window > "u")
|
|
698
|
+
return null;
|
|
699
|
+
const s = new URLSearchParams(window.location.search), r = s.get(t);
|
|
700
|
+
if (r !== null)
|
|
701
|
+
return r;
|
|
702
|
+
const n = s.get(t.replace(/-/g, "_"));
|
|
703
|
+
return n !== null ? n : null;
|
|
704
|
+
}
|
|
705
|
+
function gt(t, e) {
|
|
706
|
+
const s = Lt(t);
|
|
707
|
+
return s === "true" ? !0 : s === "false" ? !1 : null;
|
|
708
|
+
}
|
|
709
|
+
function Pt() {
|
|
710
|
+
return gt(wt) !== !1;
|
|
711
|
+
}
|
|
712
|
+
const M = p("WebSocketTransport"), mt = 1e4;
|
|
713
|
+
class Ot {
|
|
714
|
+
ws = null;
|
|
715
|
+
keepaliveTimeout = null;
|
|
716
|
+
isClosed = !1;
|
|
717
|
+
// Pre-allocated keepalive response message to avoid allocation per keepalive
|
|
718
|
+
keepaliveResponseMessage = null;
|
|
719
|
+
// Released on the first server-originated message; gates connect() resolution.
|
|
720
|
+
// null once connect() has settled (success or failure) — see connect()/handleProtocolMessage.
|
|
721
|
+
firstMessageResolver = null;
|
|
722
|
+
keepaliveTimeoutMs;
|
|
723
|
+
connectionTimeoutMs;
|
|
724
|
+
callbacks;
|
|
725
|
+
sessionId;
|
|
726
|
+
constructor(e) {
|
|
727
|
+
this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? mt;
|
|
728
|
+
}
|
|
729
|
+
get isConnected() {
|
|
730
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
731
|
+
}
|
|
732
|
+
async connect(e, s) {
|
|
733
|
+
this.isClosed = !1;
|
|
734
|
+
const r = Date.now();
|
|
735
|
+
return new Promise((n, i) => {
|
|
736
|
+
try {
|
|
737
|
+
this.ws = new WebSocket(e), this.ws.binaryType = "arraybuffer";
|
|
738
|
+
} catch (T) {
|
|
739
|
+
i(new y(`Failed to create WebSocket: ${T}`, T instanceof Error ? T : void 0));
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
let E = !1, a = !1;
|
|
743
|
+
const o = () => {
|
|
744
|
+
clearTimeout(_), this.ws && (this.ws.onopen = null, this.ws.onerror = null, this.ws.onclose = null, this.ws.onmessage = null);
|
|
745
|
+
}, c = () => {
|
|
746
|
+
a || (a = !0, clearTimeout(_), this.firstMessageResolver = null, M.debug(`WebSocket connected in ${Date.now() - r}ms`), n());
|
|
747
|
+
}, l = (T) => {
|
|
748
|
+
a || (a = !0, this.firstMessageResolver = null, o(), i(T));
|
|
749
|
+
};
|
|
750
|
+
this.firstMessageResolver = c;
|
|
751
|
+
const _ = setTimeout(() => {
|
|
752
|
+
this.ws?.close(), M.warn(`WebSocket connection timeout after ${this.connectionTimeoutMs}ms`), l(new y("WebSocket connection timeout"));
|
|
753
|
+
}, this.connectionTimeoutMs);
|
|
754
|
+
this.ws.onopen = () => {
|
|
755
|
+
E = !0, this.ws.send(s), this.resetKeepaliveTimeout();
|
|
756
|
+
}, this.ws.onerror = () => {
|
|
757
|
+
M.debug(`WebSocket connection failed after ${Date.now() - r}ms`), l(new y("WebSocket connection failed"));
|
|
758
|
+
}, this.ws.onclose = (T) => {
|
|
759
|
+
if (this.clearKeepaliveTimeout(), !a) {
|
|
760
|
+
l(E ? new b("WebSocket closed before first server message") : new y("WebSocket connection closed before opening"));
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (this.isClosed)
|
|
764
|
+
return;
|
|
765
|
+
const I = T.wasClean && (T.code === 1e3 || T.code === 1001), w = T.reason || `code=${T.code}`;
|
|
766
|
+
this.callbacks.onClose(w, I);
|
|
767
|
+
}, this.ws.onmessage = (T) => {
|
|
768
|
+
this.handleProtocolMessage(new Uint8Array(T.data));
|
|
769
|
+
};
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
send(e) {
|
|
773
|
+
this.ws?.readyState === WebSocket.OPEN ? this.ws.send(e) : M.warn("Cannot send: WebSocket not connected");
|
|
774
|
+
}
|
|
775
|
+
close() {
|
|
776
|
+
this.isClosed = !0, this.clearKeepaliveTimeout(), this.ws && (this.ws.close(1e3, "Client closing"), this.ws = null);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Get or create a cached keepalive response message.
|
|
780
|
+
*/
|
|
781
|
+
getKeepaliveResponse() {
|
|
782
|
+
return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = nt(rt(), this.sessionId)), this.keepaliveResponseMessage;
|
|
783
|
+
}
|
|
784
|
+
handleProtocolMessage(e) {
|
|
785
|
+
try {
|
|
786
|
+
const r = Y(e).opcode;
|
|
787
|
+
if (this.firstMessageResolver && this.firstMessageResolver(), r === k.KEEPALIVE_REQUEST) {
|
|
788
|
+
this.send(this.getKeepaliveResponse()), this.resetKeepaliveTimeout();
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
|
|
792
|
+
} catch (s) {
|
|
793
|
+
M.error("Failed to process protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
resetKeepaliveTimeout() {
|
|
797
|
+
this.clearKeepaliveTimeout(), !(this.keepaliveTimeoutMs <= 0) && (this.keepaliveTimeout = setTimeout(() => {
|
|
798
|
+
M.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
|
|
799
|
+
}, this.keepaliveTimeoutMs));
|
|
800
|
+
}
|
|
801
|
+
clearKeepaliveTimeout() {
|
|
802
|
+
this.keepaliveTimeout && (clearTimeout(this.keepaliveTimeout), this.keepaliveTimeout = null);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const S = p("WebTransportTransport"), Dt = 1e4, et = 4, Mt = 65536;
|
|
806
|
+
function ot() {
|
|
807
|
+
return typeof WebTransport < "u";
|
|
808
|
+
}
|
|
809
|
+
class bt {
|
|
810
|
+
transport = null;
|
|
811
|
+
stream = null;
|
|
812
|
+
reader = null;
|
|
813
|
+
writer = null;
|
|
814
|
+
keepaliveTimeout = null;
|
|
815
|
+
readLoopActive = !1;
|
|
816
|
+
isClosed = !1;
|
|
817
|
+
// Grow-only receive buffer with offset/length tracking to minimize allocations
|
|
818
|
+
receiveBuffer = new Uint8Array(Mt);
|
|
819
|
+
receiveBufferOffset = 0;
|
|
820
|
+
receiveBufferLength = 0;
|
|
821
|
+
// Cached DataView to avoid allocation per message
|
|
822
|
+
receiveDataView = null;
|
|
823
|
+
receiveDataViewBuffer = null;
|
|
824
|
+
// Pre-allocated keepalive response message
|
|
825
|
+
keepaliveResponseMessage = null;
|
|
826
|
+
// Released on the first server-originated message; gates connect() resolution.
|
|
827
|
+
// Both are nulled once connect() has settled — see connect()/handleProtocolMessage/handleClose.
|
|
828
|
+
firstMessageResolver = null;
|
|
829
|
+
firstMessageRejecter = null;
|
|
830
|
+
keepaliveTimeoutMs;
|
|
831
|
+
connectionTimeoutMs;
|
|
832
|
+
callbacks;
|
|
833
|
+
sessionId;
|
|
834
|
+
constructor(e) {
|
|
835
|
+
this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? Dt;
|
|
836
|
+
}
|
|
837
|
+
get isConnected() {
|
|
838
|
+
return this.transport !== null && this.writer !== null;
|
|
839
|
+
}
|
|
840
|
+
async connect(e, s) {
|
|
841
|
+
if (!ot())
|
|
842
|
+
throw new y("WebTransport is not supported in this browser");
|
|
843
|
+
this.isClosed = !1;
|
|
844
|
+
const r = Date.now(), n = new Promise((i, E) => {
|
|
845
|
+
this.firstMessageResolver = i, this.firstMessageRejecter = E;
|
|
846
|
+
});
|
|
847
|
+
try {
|
|
848
|
+
this.transport = new WebTransport(e);
|
|
849
|
+
let i;
|
|
850
|
+
const E = new Promise((l, _) => {
|
|
851
|
+
i = setTimeout(
|
|
852
|
+
() => _(new y("WebTransport connection timeout")),
|
|
853
|
+
this.connectionTimeoutMs
|
|
854
|
+
);
|
|
855
|
+
});
|
|
856
|
+
try {
|
|
857
|
+
await Promise.race([this.transport.ready, E]);
|
|
858
|
+
} catch (l) {
|
|
859
|
+
throw l instanceof y && S.warn(`WebTransport connection timeout after ${this.connectionTimeoutMs}ms`), l;
|
|
860
|
+
} finally {
|
|
861
|
+
clearTimeout(i);
|
|
862
|
+
}
|
|
863
|
+
this.transport.closed.then(() => {
|
|
864
|
+
this.handleClose("Connection closed", !0);
|
|
865
|
+
}).catch((l) => {
|
|
866
|
+
S.error("WebTransport connection closed with error:", l), this.handleClose(l.message || "Connection error", !1);
|
|
867
|
+
}), this.stream = await this.transport.createBidirectionalStream(), this.reader = this.stream.readable.getReader(), this.writer = this.stream.writable.getWriter(), await this.writer.write(s), this.resetKeepaliveTimeout(), this.startReadLoop();
|
|
868
|
+
const a = Math.max(this.connectionTimeoutMs - (Date.now() - r), 1);
|
|
869
|
+
let o;
|
|
870
|
+
const c = new Promise((l, _) => {
|
|
871
|
+
o = setTimeout(
|
|
872
|
+
() => _(new y("WebTransport closed before first server message")),
|
|
873
|
+
a
|
|
874
|
+
);
|
|
875
|
+
});
|
|
876
|
+
try {
|
|
877
|
+
await Promise.race([n, c]);
|
|
878
|
+
} finally {
|
|
879
|
+
clearTimeout(o);
|
|
880
|
+
}
|
|
881
|
+
this.firstMessageResolver = null, this.firstMessageRejecter = null, S.info(`WebTransport connected in ${Date.now() - r}ms`);
|
|
882
|
+
} catch (i) {
|
|
883
|
+
this.firstMessageResolver = null, this.firstMessageRejecter = null, this.isClosed = !0, this.cleanup();
|
|
884
|
+
const E = Date.now() - r;
|
|
885
|
+
throw S.warn(`WebTransport connection failed after ${E}ms: ${i}`), new y(`Failed to connect WebTransport: ${i}`, i instanceof Error ? i : void 0);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
send(e) {
|
|
889
|
+
if (!this.writer) {
|
|
890
|
+
S.warn("Cannot send: WebTransport not connected");
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
this.writer.write(e).catch((s) => {
|
|
894
|
+
S.error("Failed to send protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
close() {
|
|
898
|
+
this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup();
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Start the read loop to receive messages.
|
|
902
|
+
*/
|
|
903
|
+
async startReadLoop() {
|
|
904
|
+
if (this.reader) {
|
|
905
|
+
this.readLoopActive = !0;
|
|
906
|
+
try {
|
|
907
|
+
for (; this.readLoopActive && this.reader; ) {
|
|
908
|
+
const { value: e, done: s } = await this.reader.read();
|
|
909
|
+
if (s)
|
|
910
|
+
break;
|
|
911
|
+
e && (this.appendToBuffer(e), this.processBufferedMessages());
|
|
912
|
+
}
|
|
913
|
+
this.readLoopActive && this.handleClose("Stream ended", !1);
|
|
914
|
+
} catch (e) {
|
|
915
|
+
this.readLoopActive && (S.error("Read loop error:", e), this.callbacks.onError(e instanceof Error ? e : new Error(String(e))));
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Append incoming data to the receive buffer using grow-only strategy.
|
|
921
|
+
* Compacts when offset exceeds half capacity and data is sparse.
|
|
922
|
+
*/
|
|
923
|
+
appendToBuffer(e) {
|
|
924
|
+
const s = this.receiveBufferLength + e.length, r = this.receiveBufferOffset + this.receiveBufferLength;
|
|
925
|
+
if (r + e.length > this.receiveBuffer.length)
|
|
926
|
+
if (s > this.receiveBuffer.length) {
|
|
927
|
+
const n = Math.max(s, this.receiveBuffer.length * 2), i = new Uint8Array(n);
|
|
928
|
+
i.set(this.receiveBuffer.subarray(this.receiveBufferOffset, r)), this.receiveBuffer = i, this.receiveBufferOffset = 0, this.receiveDataViewBuffer = null;
|
|
929
|
+
} else
|
|
930
|
+
this.receiveBuffer.copyWithin(0, this.receiveBufferOffset, r), this.receiveBufferOffset = 0;
|
|
931
|
+
this.receiveBuffer.set(e, this.receiveBufferOffset + this.receiveBufferLength), this.receiveBufferLength += e.length;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Get or create a cached DataView for the receive buffer.
|
|
935
|
+
*/
|
|
936
|
+
getReceiveDataView() {
|
|
937
|
+
const e = this.receiveBuffer.buffer;
|
|
938
|
+
return this.receiveDataViewBuffer !== e && (this.receiveDataViewBuffer = e, this.receiveDataView = new DataView(e)), this.receiveDataView;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get or create a cached keepalive response message.
|
|
942
|
+
*/
|
|
943
|
+
getKeepaliveResponse() {
|
|
944
|
+
return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = nt(rt(), this.sessionId)), this.keepaliveResponseMessage;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Process complete messages from the receive buffer.
|
|
948
|
+
* Protocol messages start with a 4-byte little-endian length field.
|
|
949
|
+
* Uses subarray views to avoid per-message allocations.
|
|
950
|
+
*/
|
|
951
|
+
processBufferedMessages() {
|
|
952
|
+
const e = this.getReceiveDataView();
|
|
953
|
+
for (; this.receiveBufferLength >= et; ) {
|
|
954
|
+
const s = e.getUint32(this.receiveBufferOffset, !0);
|
|
955
|
+
if (s < et) {
|
|
956
|
+
S.error(`Invalid message length: ${s}`), this.callbacks.onError(new Error(`Invalid protocol message length: ${s}`)), this.receiveBufferOffset = 0, this.receiveBufferLength = 0;
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (this.receiveBufferLength < s)
|
|
960
|
+
return;
|
|
961
|
+
const r = this.receiveBuffer.subarray(this.receiveBufferOffset, this.receiveBufferOffset + s);
|
|
962
|
+
this.receiveBufferOffset += s, this.receiveBufferLength -= s, this.handleProtocolMessage(r);
|
|
963
|
+
}
|
|
964
|
+
this.receiveBufferLength === 0 && (this.receiveBufferOffset = 0);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Handle incoming protocol message.
|
|
968
|
+
*/
|
|
969
|
+
handleProtocolMessage(e) {
|
|
970
|
+
try {
|
|
971
|
+
const r = Y(e).opcode;
|
|
972
|
+
if (this.firstMessageResolver && this.firstMessageResolver(), r === k.KEEPALIVE_REQUEST) {
|
|
973
|
+
this.send(this.getKeepaliveResponse()), this.resetKeepaliveTimeout();
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
|
|
977
|
+
} catch (s) {
|
|
978
|
+
S.error("Failed to process protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Handle connection close.
|
|
983
|
+
*/
|
|
984
|
+
handleClose(e, s) {
|
|
985
|
+
if (!this.isClosed) {
|
|
986
|
+
if (this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup(), this.firstMessageRejecter) {
|
|
987
|
+
this.firstMessageRejecter(new b(`WebTransport closed before first server message: ${e}`)), this.firstMessageResolver = null, this.firstMessageRejecter = null;
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
this.callbacks.onClose(e, s);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Reset the keepalive timeout.
|
|
995
|
+
*/
|
|
996
|
+
resetKeepaliveTimeout() {
|
|
997
|
+
this.clearKeepaliveTimeout(), !(this.keepaliveTimeoutMs <= 0) && (this.keepaliveTimeout = setTimeout(() => {
|
|
998
|
+
S.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
|
|
999
|
+
}, this.keepaliveTimeoutMs));
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Clear the keepalive timeout.
|
|
1003
|
+
*/
|
|
1004
|
+
clearKeepaliveTimeout() {
|
|
1005
|
+
this.keepaliveTimeout && (clearTimeout(this.keepaliveTimeout), this.keepaliveTimeout = null);
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Clean up resources.
|
|
1009
|
+
*/
|
|
1010
|
+
cleanup() {
|
|
1011
|
+
if (this.reader && (this.reader.releaseLock(), this.reader = null), this.writer && (this.writer.releaseLock(), this.writer = null), this.stream = null, this.receiveBufferOffset = 0, this.receiveBufferLength = 0, this.transport) {
|
|
1012
|
+
try {
|
|
1013
|
+
this.transport.close();
|
|
1014
|
+
} catch {
|
|
1015
|
+
}
|
|
1016
|
+
this.transport = null;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const $ = p("Channel");
|
|
1021
|
+
class vt {
|
|
1022
|
+
state = "disconnected";
|
|
1023
|
+
transport = null;
|
|
1024
|
+
config;
|
|
1025
|
+
entrypoint;
|
|
1026
|
+
constructor(e) {
|
|
1027
|
+
this.config = e, this.entrypoint = e.entrypoint;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Get the current channel state.
|
|
1031
|
+
*/
|
|
1032
|
+
get channelState() {
|
|
1033
|
+
return this.state;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Get the opcode groups this channel handles.
|
|
1037
|
+
*/
|
|
1038
|
+
get opcodeGroups() {
|
|
1039
|
+
return this.entrypoint.OpcodeGroupsFromServer;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Get the entrypoint type.
|
|
1043
|
+
*/
|
|
1044
|
+
get type() {
|
|
1045
|
+
return this.entrypoint.Type;
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Check if transport is connected.
|
|
1049
|
+
*/
|
|
1050
|
+
get isConnected() {
|
|
1051
|
+
return this.transport?.isConnected ?? !1;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Connect to the entrypoint.
|
|
1055
|
+
*/
|
|
1056
|
+
async connect() {
|
|
1057
|
+
if (this.state !== "disconnected")
|
|
1058
|
+
throw new Error(`Cannot connect: already in state ${this.state}`);
|
|
1059
|
+
this.setState("connecting");
|
|
1060
|
+
try {
|
|
1061
|
+
await this.connectTransport(), this.setState("connected");
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
throw this.setState("disconnected"), e;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Disconnect the channel.
|
|
1068
|
+
*/
|
|
1069
|
+
disconnect() {
|
|
1070
|
+
this.transport && (this.transport.close(), this.transport = null), this.setState("disconnected");
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Force the channel to drop its transport and notify the manager so the
|
|
1074
|
+
* normal reconnect flow kicks in. Used when an upper layer (e.g. action-ack
|
|
1075
|
+
* timeout) has evidence the connection is dead even though the transport
|
|
1076
|
+
* still believes it is open.
|
|
1077
|
+
*/
|
|
1078
|
+
triggerReconnect(e) {
|
|
1079
|
+
this.transport && (this.transport.close(), this.transport = null), this.config.onClose?.(e, !1);
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Check transport health and trigger close if the connection is dead.
|
|
1083
|
+
* Used after tab resume to detect WebSockets closed by the OS while suspended.
|
|
1084
|
+
*/
|
|
1085
|
+
checkHealth() {
|
|
1086
|
+
this.state === "connected" && this.transport && !this.transport.isConnected && this.handleClose("Transport dead after tab resume", !1);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Send a protocol message through the channel.
|
|
1090
|
+
*/
|
|
1091
|
+
send(e) {
|
|
1092
|
+
if (!this.transport?.isConnected) {
|
|
1093
|
+
$.warn("Cannot send: channel not connected");
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
this.transport.send(e);
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Connect the transport to the entrypoint.
|
|
1100
|
+
*/
|
|
1101
|
+
async connectTransport() {
|
|
1102
|
+
const e = this.entrypoint, s = {
|
|
1103
|
+
sessionId: this.config.sessionId,
|
|
1104
|
+
keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
|
|
1105
|
+
connectionTimeoutMs: this.config.connectionTimeoutMs,
|
|
1106
|
+
callbacks: {
|
|
1107
|
+
onProtocolMessage: (r) => this.handleProtocolMessage(r),
|
|
1108
|
+
onClose: (r, n) => this.handleClose(r, n),
|
|
1109
|
+
onError: (r) => this.handleError(r)
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
switch (e.Type) {
|
|
1113
|
+
case f.WebSocket:
|
|
1114
|
+
case f.WebSocketProxy:
|
|
1115
|
+
this.transport = new Ot(s);
|
|
1116
|
+
break;
|
|
1117
|
+
case f.WebTransport:
|
|
1118
|
+
case f.WebTransportProxy:
|
|
1119
|
+
if (!ot())
|
|
1120
|
+
throw new Error("WebTransport is not supported in this browser");
|
|
1121
|
+
this.transport = new bt(s);
|
|
1122
|
+
break;
|
|
1123
|
+
default:
|
|
1124
|
+
throw new Error(`Unsupported entrypoint type: ${f[e.Type]}`);
|
|
1125
|
+
}
|
|
1126
|
+
await this.transport.connect(e.Uri, e.AuthTicket);
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Handle incoming protocol message.
|
|
1130
|
+
*/
|
|
1131
|
+
handleProtocolMessage(e) {
|
|
1132
|
+
try {
|
|
1133
|
+
const s = e;
|
|
1134
|
+
if (z(s) === k.CORE_ON_SERVER_STOPPING) {
|
|
1135
|
+
$.debug("Received server stopping message"), this.setState("stopped"), this.transport?.close();
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
this.config.onProtocolMessage?.(s);
|
|
1139
|
+
} catch (s) {
|
|
1140
|
+
$.error("Failed to handle protocol message:", s), this.config.onError?.(s instanceof Error ? s : new Error(String(s)));
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Handle transport close.
|
|
1145
|
+
*/
|
|
1146
|
+
handleClose(e, s) {
|
|
1147
|
+
this.transport = null, this.config.onClose?.(e, s);
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Handle transport error.
|
|
1151
|
+
*/
|
|
1152
|
+
handleError(e) {
|
|
1153
|
+
this.config.onError?.(e), e instanceof q && this.handleClose("Keepalive timeout", !1);
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Update and notify state change.
|
|
1157
|
+
*/
|
|
1158
|
+
setState(e) {
|
|
1159
|
+
this.state !== e && (this.state = e, this.config.onStateChange?.(e));
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
const A = p("ChannelManager"), Bt = 5e3;
|
|
1163
|
+
class Ft {
|
|
1164
|
+
channels = /* @__PURE__ */ new Map();
|
|
1165
|
+
// keyed by opcode group
|
|
1166
|
+
activeType = null;
|
|
1167
|
+
state = "idle";
|
|
1168
|
+
reconnectAttempts = 0;
|
|
1169
|
+
shouldReconnect = !0;
|
|
1170
|
+
entrypoints = [];
|
|
1171
|
+
abortController = null;
|
|
1172
|
+
connectionTimeoutMs;
|
|
1173
|
+
stabilityTimer = null;
|
|
1174
|
+
config;
|
|
1175
|
+
constructor(e) {
|
|
1176
|
+
this.config = e;
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Get the current state.
|
|
1180
|
+
*/
|
|
1181
|
+
get managerState() {
|
|
1182
|
+
return this.state;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Get the active endpoint type.
|
|
1186
|
+
*/
|
|
1187
|
+
get activeEndpointType() {
|
|
1188
|
+
return this.activeType;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Connect to the server using the provided entrypoints.
|
|
1192
|
+
*/
|
|
1193
|
+
async connect(e, s) {
|
|
1194
|
+
if (this.state !== "idle" && this.state !== "offline")
|
|
1195
|
+
throw new Error(`Cannot connect: already in state ${this.state}`);
|
|
1196
|
+
if (this.entrypoints = e, this.shouldReconnect = !0, this.reconnectAttempts = 0, this.abortController = new AbortController(), s?.retry) {
|
|
1197
|
+
this.attemptReconnect();
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
await this.connectInternal();
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Disconnect all channels.
|
|
1204
|
+
*/
|
|
1205
|
+
disconnect() {
|
|
1206
|
+
this.shouldReconnect = !1, this.abortController?.abort(), this.abortController = null, this.disconnectAll(), this.setState("idle");
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Send a protocol message to the appropriate channel.
|
|
1210
|
+
* The opcode group is extracted from the message automatically.
|
|
1211
|
+
*/
|
|
1212
|
+
sendProtocolMessage(e) {
|
|
1213
|
+
const s = G(e);
|
|
1214
|
+
for (const [r, n] of this.channels)
|
|
1215
|
+
if (r & s) {
|
|
1216
|
+
n.send(e);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
this.state === "connected" && A.warn("No channel found for message");
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Send a protocol message to all channels (for broadcast messages).
|
|
1223
|
+
*/
|
|
1224
|
+
sendToAll(e) {
|
|
1225
|
+
for (const s of this.channels.values())
|
|
1226
|
+
s.send(e);
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Check health of all channels.
|
|
1230
|
+
* Used after tab resume to detect WebSockets closed by the OS while suspended.
|
|
1231
|
+
* Only checks when connected — non-sudden disconnects (SDK-initiated or server
|
|
1232
|
+
* stopping) clear the channels and transition to idle/stopped before this runs.
|
|
1233
|
+
*/
|
|
1234
|
+
checkHealth() {
|
|
1235
|
+
if (this.state === "connected")
|
|
1236
|
+
for (const e of this.channels.values())
|
|
1237
|
+
e.checkHealth();
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Force every active channel to drop its transport and notify the manager,
|
|
1241
|
+
* kicking off the normal reconnect flow. Used when a higher layer has
|
|
1242
|
+
* evidence that the connection is dead (e.g. no ACK received for a user
|
|
1243
|
+
* action within the ack-timeout window).
|
|
1244
|
+
*/
|
|
1245
|
+
triggerReconnect(e) {
|
|
1246
|
+
if (this.state === "connected") {
|
|
1247
|
+
A.debug(`Forcing reconnect: ${e}`);
|
|
1248
|
+
for (const s of this.channels.values())
|
|
1249
|
+
s.triggerReconnect(e);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Internal connect implementation.
|
|
1254
|
+
* @param isReconnect - If true, don't set offline state on failure (let attemptReconnect handle it)
|
|
1255
|
+
*/
|
|
1256
|
+
async connectInternal(e = !1) {
|
|
1257
|
+
this.setState("connecting");
|
|
1258
|
+
const s = this.entrypoints.filter((i) => i.Type !== f.WebRTC), r = this.groupByType(s);
|
|
1259
|
+
if (r.size === 0)
|
|
1260
|
+
throw this.setState("offline"), new Error("No entrypoints available");
|
|
1261
|
+
let n;
|
|
1262
|
+
if (this.config.orderedEndpointTypes && this.config.orderedEndpointTypes.length > 0) {
|
|
1263
|
+
const i = new Set(r.keys());
|
|
1264
|
+
n = this.config.orderedEndpointTypes.filter((E) => i.has(E));
|
|
1265
|
+
} else this.config.endpointSelector ? n = this.config.endpointSelector.getOrderedTypes(r) : n = Array.from(r.keys());
|
|
1266
|
+
this.connectionTimeoutMs = n.length > 1 ? 5e3 : 1e4, A.debug(`Endpoint types to try: [${n.map((i) => f[i]).join(", ")}], transport timeout: ${this.connectionTimeoutMs}ms`);
|
|
1267
|
+
for (const i of n) {
|
|
1268
|
+
if (!this.shouldReconnect)
|
|
1269
|
+
return;
|
|
1270
|
+
const E = r.get(i), a = Date.now();
|
|
1271
|
+
A.debug(`Trying ${f[i]} (${E.length} channel(s))`);
|
|
1272
|
+
try {
|
|
1273
|
+
await this.connectAllChannels(E), this.config.endpointSelector?.rememberWorkingType(i), this.config.onRememberWorkingType?.(i), this.activeType = i, A.debug(`Connected via ${f[i]} in ${Date.now() - a}ms`), this.setState("connected"), this.startStabilityTimer();
|
|
1274
|
+
return;
|
|
1275
|
+
} catch (o) {
|
|
1276
|
+
A.warn(`Failed to connect using ${f[i]} after ${Date.now() - a}ms: ${o instanceof Error ? o.message : o}`);
|
|
1277
|
+
const c = this.channels.size > 0;
|
|
1278
|
+
if (this.disconnectAll(), o instanceof b)
|
|
1279
|
+
throw o;
|
|
1280
|
+
if (c && this.config.onRefreshEntrypoints)
|
|
1281
|
+
try {
|
|
1282
|
+
A.info("Partial connection detected, refreshing entrypoints");
|
|
1283
|
+
const l = await this.config.onRefreshEntrypoints();
|
|
1284
|
+
this.entrypoints = l.entrypoints, this.config.sessionId = l.sessionId;
|
|
1285
|
+
const _ = l.entrypoints.filter((I) => I.Type !== f.WebRTC), T = this.groupByType(_);
|
|
1286
|
+
for (const [I, w] of T)
|
|
1287
|
+
r.set(I, w);
|
|
1288
|
+
} catch (l) {
|
|
1289
|
+
A.warn(`Failed to refresh entrypoints: ${l}`);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
throw e || this.setState("offline"), new Error("Failed to connect using any endpoint type");
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Connect all channels for a given endpoint type in parallel.
|
|
1297
|
+
*/
|
|
1298
|
+
async connectAllChannels(e) {
|
|
1299
|
+
if (e.length === 0)
|
|
1300
|
+
throw new Error("No entrypoints to connect");
|
|
1301
|
+
const r = (await Promise.allSettled(e.map((n) => this.connectChannel(n)))).filter((n) => n.status === "rejected");
|
|
1302
|
+
if (r.length > 0) {
|
|
1303
|
+
const n = r.map((i) => i.reason instanceof Error ? i.reason.message : String(i.reason));
|
|
1304
|
+
throw r.some((i) => i.reason instanceof b) ? new b(n.join(", ")) : new Error(n.join(", "));
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Connect a single channel.
|
|
1309
|
+
*/
|
|
1310
|
+
async connectChannel(e) {
|
|
1311
|
+
const s = new vt({
|
|
1312
|
+
entrypoint: e,
|
|
1313
|
+
sessionId: this.config.sessionId,
|
|
1314
|
+
keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
|
|
1315
|
+
connectionTimeoutMs: this.connectionTimeoutMs,
|
|
1316
|
+
onProtocolMessage: (r) => {
|
|
1317
|
+
this.config.onProtocolMessage?.(r);
|
|
1318
|
+
},
|
|
1319
|
+
onStateChange: (r) => {
|
|
1320
|
+
this.handleChannelStateChange(e.OpcodeGroupsFromServer, r);
|
|
1321
|
+
},
|
|
1322
|
+
onClose: (r, n) => {
|
|
1323
|
+
this.handleChannelClose(e.OpcodeGroupsFromServer, r, n);
|
|
1324
|
+
},
|
|
1325
|
+
onError: (r) => {
|
|
1326
|
+
this.config.onError?.(r);
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
await s.connect(), this.channels.set(e.OpcodeGroupsFromServer, s);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Group entrypoints by type.
|
|
1333
|
+
*/
|
|
1334
|
+
groupByType(e) {
|
|
1335
|
+
const s = /* @__PURE__ */ new Map();
|
|
1336
|
+
for (const r of e) {
|
|
1337
|
+
const n = s.get(r.Type) ?? [];
|
|
1338
|
+
n.push(r), s.set(r.Type, n);
|
|
1339
|
+
}
|
|
1340
|
+
return s;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Handle channel state change.
|
|
1344
|
+
*/
|
|
1345
|
+
handleChannelStateChange(e, s) {
|
|
1346
|
+
s === "stopped" && (this.shouldReconnect = !1, this.disconnectAll(), this.setState("stopped"));
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Handle channel close.
|
|
1350
|
+
*
|
|
1351
|
+
* Only `CORE_ON_SERVER_STOPPING` (handled separately via channel state →
|
|
1352
|
+
* `handleChannelStateChange`) means the server is gone. Any transport-level
|
|
1353
|
+
* close — including a clean WebSocket code 1000 — just means this transport
|
|
1354
|
+
* dropped, and we reconnect.
|
|
1355
|
+
*/
|
|
1356
|
+
handleChannelClose(e, s, r) {
|
|
1357
|
+
this.state === "idle" || this.state === "stopped" || this.state === "offline" || this.channels.has(e) && this.state === "connected" && (A.warn("Channel closed unexpectedly, attempting reconnect"), this.disconnectAll(), this.attemptReconnect());
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Attempt to reconnect with fixed-interval retry.
|
|
1361
|
+
* First attempt is immediate, subsequent attempts wait reconnectBackoffMs.
|
|
1362
|
+
*/
|
|
1363
|
+
async attemptReconnect() {
|
|
1364
|
+
if (this.shouldReconnect) {
|
|
1365
|
+
if (!Pt()) {
|
|
1366
|
+
A.warn("Retry disabled via ikon-retry=false, skipping reconnect"), this.setState("offline"), this.config.onError?.(new tt(0));
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
|
|
1370
|
+
A.warn(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached`), this.setState("offline"), this.config.onError?.(new tt(this.config.maxReconnectAttempts));
|
|
1371
|
+
return;
|
|
1372
|
+
}
|
|
1373
|
+
if (this.setState("reconnecting"), this.reconnectAttempts++, this.reconnectAttempts > 1 ? (A.info(`Reconnecting in ${this.config.reconnectBackoffMs}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), await ft(this.config.reconnectBackoffMs, this.abortController?.signal)) : A.info(`Reconnecting immediately (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), !!this.shouldReconnect)
|
|
1374
|
+
try {
|
|
1375
|
+
await this.connectInternal(!0);
|
|
1376
|
+
} catch (e) {
|
|
1377
|
+
if (e instanceof b) {
|
|
1378
|
+
A.warn("Auth rejected during reconnect, stopping retries and signaling full re-auth"), this.config.onError?.(e), this.setState("offline");
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
await this.attemptReconnect();
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Disconnect all channels.
|
|
1387
|
+
*/
|
|
1388
|
+
disconnectAll() {
|
|
1389
|
+
for (const e of this.channels.values())
|
|
1390
|
+
e.disconnect();
|
|
1391
|
+
this.channels.clear(), this.activeType = null;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Update and notify state change.
|
|
1395
|
+
*/
|
|
1396
|
+
setState(e) {
|
|
1397
|
+
this.state !== e && (this.state === "connected" && e !== "connected" && this.clearStabilityTimer(), this.state = e, this.config.onStateChange?.(e));
|
|
1398
|
+
}
|
|
1399
|
+
startStabilityTimer() {
|
|
1400
|
+
this.clearStabilityTimer(), this.stabilityTimer = setTimeout(() => {
|
|
1401
|
+
this.stabilityTimer = null, this.state === "connected" && (this.reconnectAttempts = 0);
|
|
1402
|
+
}, Bt);
|
|
1403
|
+
}
|
|
1404
|
+
clearStabilityTimer() {
|
|
1405
|
+
this.stabilityTimer && (clearTimeout(this.stabilityTimer), this.stabilityTimer = null);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const Et = p("ProtocolWorker"), g = (t, e) => {
|
|
1409
|
+
self.postMessage(t, e ?? []);
|
|
1410
|
+
};
|
|
1411
|
+
let u = null, B = null, F = null, j, N = null;
|
|
1412
|
+
const P = [], R = [], d = /* @__PURE__ */ new Map(), U = [], C = [], L = /* @__PURE__ */ new Map(), X = [];
|
|
1413
|
+
function Q() {
|
|
1414
|
+
try {
|
|
1415
|
+
u?.disconnect();
|
|
1416
|
+
} catch (t) {
|
|
1417
|
+
Et.warn(`Failed to disconnect channel manager: ${t}`);
|
|
1418
|
+
}
|
|
1419
|
+
u = null;
|
|
1420
|
+
for (let t = 0; t < R.length; t++)
|
|
1421
|
+
try {
|
|
1422
|
+
R[t].port.close();
|
|
1423
|
+
} catch {
|
|
1424
|
+
}
|
|
1425
|
+
P.length = 0, R.length = 0, d.clear();
|
|
1426
|
+
for (let t = 0; t < C.length; t++)
|
|
1427
|
+
try {
|
|
1428
|
+
C[t].port.close();
|
|
1429
|
+
} catch {
|
|
1430
|
+
}
|
|
1431
|
+
U.length = 0, C.length = 0, L.clear();
|
|
1432
|
+
}
|
|
1433
|
+
function v(t) {
|
|
1434
|
+
const e = t instanceof Error ? t : new Error(String(t));
|
|
1435
|
+
g({ type: "error", error: { name: e.name, message: e.message, stack: e.stack } });
|
|
1436
|
+
}
|
|
1437
|
+
function dt() {
|
|
1438
|
+
let t = 0;
|
|
1439
|
+
for (let e = 0; e < R.length; e++)
|
|
1440
|
+
t |= R[e].opcodeGroupsMask;
|
|
1441
|
+
return t;
|
|
1442
|
+
}
|
|
1443
|
+
function Gt(t) {
|
|
1444
|
+
if (j === void 0)
|
|
1445
|
+
return !0;
|
|
1446
|
+
const e = G(t);
|
|
1447
|
+
if ((e & j) !== 0)
|
|
1448
|
+
return !0;
|
|
1449
|
+
const s = dt();
|
|
1450
|
+
return (e & s) !== 0;
|
|
1451
|
+
}
|
|
1452
|
+
function lt(t) {
|
|
1453
|
+
X.length = 0;
|
|
1454
|
+
for (let e = 0; e < R.length; e++) {
|
|
1455
|
+
const s = R[e];
|
|
1456
|
+
(s.opcodeGroupsMask & t) !== 0 && X.push(s.port);
|
|
1457
|
+
}
|
|
1458
|
+
return X;
|
|
1459
|
+
}
|
|
1460
|
+
function Vt(t, e) {
|
|
1461
|
+
return (G(t) & e) !== 0;
|
|
1462
|
+
}
|
|
1463
|
+
function kt(t, e) {
|
|
1464
|
+
if (!u || !e || typeof e != "object")
|
|
1465
|
+
return;
|
|
1466
|
+
const s = e;
|
|
1467
|
+
if (!(s.type !== "send" || !(s.message instanceof ArrayBuffer)))
|
|
1468
|
+
try {
|
|
1469
|
+
const r = new Uint8Array(s.message);
|
|
1470
|
+
if (!Vt(r, t))
|
|
1471
|
+
return;
|
|
1472
|
+
u.sendProtocolMessage(r), N && N.postMessage({ direction: "sent", message: Array.from(r) });
|
|
1473
|
+
} catch (r) {
|
|
1474
|
+
v(r);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
async function pt(t) {
|
|
1478
|
+
Q(), u = new Ft({
|
|
1479
|
+
sessionId: t.sessionId,
|
|
1480
|
+
keepaliveTimeoutMs: t.keepaliveTimeoutMs,
|
|
1481
|
+
reconnectBackoffMs: t.reconnectBackoffMs,
|
|
1482
|
+
maxReconnectAttempts: t.maxReconnectAttempts,
|
|
1483
|
+
orderedEndpointTypes: t.orderedEndpointTypes,
|
|
1484
|
+
webRtcEnabled: t.webRtcEnabled,
|
|
1485
|
+
onStateChange: (e) => {
|
|
1486
|
+
g({ type: "state", state: e, activeType: u?.activeEndpointType ?? void 0 });
|
|
1487
|
+
},
|
|
1488
|
+
onRememberWorkingType: () => {
|
|
1489
|
+
g({ type: "state", state: u?.managerState ?? "idle", activeType: u?.activeEndpointType ?? void 0 });
|
|
1490
|
+
},
|
|
1491
|
+
onError: (e) => {
|
|
1492
|
+
v(e);
|
|
1493
|
+
},
|
|
1494
|
+
onRefreshEntrypoints: () => new Promise((e, s) => {
|
|
1495
|
+
B = e, F = s, g({ type: "refreshEntrypoints" });
|
|
1496
|
+
}),
|
|
1497
|
+
onProtocolMessage: (e) => {
|
|
1498
|
+
N && (N.postMessage({ direction: "received", message: Array.from(e) }), z(e) === k.ANALYTICS_LOGS && N.postMessage({ type: "serverLogs", message: Array.from(e) }));
|
|
1499
|
+
const s = G(e), r = Gt(e), n = lt(s);
|
|
1500
|
+
if (!(!r && n.length === 0))
|
|
1501
|
+
try {
|
|
1502
|
+
const i = Y(e), E = e.buffer instanceof ArrayBuffer && e.byteOffset === 0 && e.byteLength === e.buffer.byteLength, a = n.length > 0;
|
|
1503
|
+
if (a && !r && n.length === 1 && E) {
|
|
1504
|
+
const o = e.buffer;
|
|
1505
|
+
n[0].postMessage({ type: "protocol", message: o, headers: i }, [o]);
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
if (!a && r && E) {
|
|
1509
|
+
const o = e.buffer;
|
|
1510
|
+
g({ type: "protocol", message: o, headers: i }, [o]);
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (a && E) {
|
|
1514
|
+
const o = [];
|
|
1515
|
+
for (let _ = 1; _ < n.length; _++)
|
|
1516
|
+
o.push(e.slice().buffer);
|
|
1517
|
+
const c = r ? e.slice().buffer : null, l = e.buffer;
|
|
1518
|
+
n[0].postMessage({ type: "protocol", message: l, headers: i }, [l]);
|
|
1519
|
+
for (let _ = 1; _ < n.length; _++)
|
|
1520
|
+
n[_].postMessage({ type: "protocol", message: o[_ - 1], headers: i }, [o[_ - 1]]);
|
|
1521
|
+
c && g({ type: "protocol", message: c, headers: i }, [c]);
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (a)
|
|
1525
|
+
for (const o of n) {
|
|
1526
|
+
const c = e.slice().buffer;
|
|
1527
|
+
o.postMessage({ type: "protocol", message: c, headers: i }, [c]);
|
|
1528
|
+
}
|
|
1529
|
+
if (r) {
|
|
1530
|
+
const o = e.slice().buffer;
|
|
1531
|
+
g({ type: "protocol", message: o, headers: i }, [o]);
|
|
1532
|
+
}
|
|
1533
|
+
} catch (i) {
|
|
1534
|
+
v(i);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}), await u.connect(t.entrypoints, { retry: t.retry });
|
|
1538
|
+
}
|
|
1539
|
+
self.addEventListener("message", (t) => {
|
|
1540
|
+
const e = t.data;
|
|
1541
|
+
if (e.type === "connect") {
|
|
1542
|
+
pt(e).catch((s) => {
|
|
1543
|
+
Et.error(`Failed to connect: ${s}`), v(s), Q();
|
|
1544
|
+
});
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
if (e.type === "disconnect") {
|
|
1548
|
+
Q(), g({ type: "state", state: "idle" });
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (e.type === "send") {
|
|
1552
|
+
if (!u)
|
|
1553
|
+
return;
|
|
1554
|
+
try {
|
|
1555
|
+
const s = new Uint8Array(e.message);
|
|
1556
|
+
u.sendProtocolMessage(s), N && N.postMessage({ direction: "sent", message: Array.from(s) });
|
|
1557
|
+
} catch (s) {
|
|
1558
|
+
v(s);
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (e.type === "setInterest") {
|
|
1563
|
+
j = e.opcodeGroupsMask;
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (e.type === "enableDevtools") {
|
|
1567
|
+
e.enabled && !N ? N = new BroadcastChannel("ikon:devtools") : !e.enabled && N && (N.close(), N = null);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
if (e.type === "setLogLevel") {
|
|
1571
|
+
Ut(e.level);
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
if (e.type === "checkHealth") {
|
|
1575
|
+
u?.checkHealth();
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
if (e.type === "triggerReconnect") {
|
|
1579
|
+
u?.triggerReconnect(e.reason);
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
if (e.type === "refreshedEntrypoints") {
|
|
1583
|
+
B && (B({ entrypoints: e.entrypoints, sessionId: e.sessionId }), B = null, F = null);
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
if (e.type === "refreshEntrypointsFailed") {
|
|
1587
|
+
F && (F(new Error("Failed to refresh entrypoints")), B = null, F = null);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
if (e.type === "forwardToPorts") {
|
|
1591
|
+
try {
|
|
1592
|
+
const s = new Uint8Array(e.message), r = G(s), n = lt(r);
|
|
1593
|
+
if (n.length > 0) {
|
|
1594
|
+
const i = Y(s);
|
|
1595
|
+
for (const E of n) {
|
|
1596
|
+
const a = s.slice().buffer;
|
|
1597
|
+
E.postMessage({ type: "protocol", message: a, headers: i }, [a]);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
} catch (s) {
|
|
1601
|
+
v(s);
|
|
1602
|
+
}
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
if (e.type === "attachPort") {
|
|
1606
|
+
try {
|
|
1607
|
+
e.port.start?.();
|
|
1608
|
+
} catch {
|
|
1609
|
+
}
|
|
1610
|
+
const s = P.length;
|
|
1611
|
+
P.push(e.portId), R.push({ port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }), d.set(e.portId, s);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
if (e.type === "detachPort") {
|
|
1615
|
+
const s = d.get(e.portId);
|
|
1616
|
+
if (s !== void 0) {
|
|
1617
|
+
const r = R[s];
|
|
1618
|
+
try {
|
|
1619
|
+
r.port.close();
|
|
1620
|
+
} catch {
|
|
1621
|
+
}
|
|
1622
|
+
const n = P.length - 1;
|
|
1623
|
+
if (s !== n) {
|
|
1624
|
+
const i = P[n];
|
|
1625
|
+
P[s] = i, R[s] = R[n], d.set(i, s);
|
|
1626
|
+
}
|
|
1627
|
+
P.length--, R.length--, d.delete(e.portId);
|
|
1628
|
+
}
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
if (e.type === "attachSendPort") {
|
|
1632
|
+
const s = L.get(e.portId);
|
|
1633
|
+
if (s !== void 0) {
|
|
1634
|
+
const i = C[s];
|
|
1635
|
+
try {
|
|
1636
|
+
i.port.close();
|
|
1637
|
+
} catch {
|
|
1638
|
+
}
|
|
1639
|
+
const E = U.length - 1;
|
|
1640
|
+
if (s !== E) {
|
|
1641
|
+
const a = U[E];
|
|
1642
|
+
U[s] = a, C[s] = C[E], L.set(a, s);
|
|
1643
|
+
}
|
|
1644
|
+
U.length--, C.length--, L.delete(e.portId);
|
|
1645
|
+
}
|
|
1646
|
+
const r = { port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }, n = U.length;
|
|
1647
|
+
U.push(e.portId), C.push(r), L.set(e.portId, n);
|
|
1648
|
+
try {
|
|
1649
|
+
r.port.start?.();
|
|
1650
|
+
} catch {
|
|
1651
|
+
}
|
|
1652
|
+
r.port.addEventListener("message", (i) => {
|
|
1653
|
+
kt(r.opcodeGroupsMask, i.data);
|
|
1654
|
+
});
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
if (e.type === "detachSendPort") {
|
|
1658
|
+
const s = L.get(e.portId);
|
|
1659
|
+
if (s !== void 0) {
|
|
1660
|
+
const r = C[s];
|
|
1661
|
+
try {
|
|
1662
|
+
r.port.close();
|
|
1663
|
+
} catch {
|
|
1664
|
+
}
|
|
1665
|
+
const n = U.length - 1;
|
|
1666
|
+
if (s !== n) {
|
|
1667
|
+
const i = U[n];
|
|
1668
|
+
U[s] = i, C[s] = C[n], L.set(i, s);
|
|
1669
|
+
}
|
|
1670
|
+
U.length--, C.length--, L.delete(e.portId);
|
|
1671
|
+
}
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
});
|