@ikonai/sdk 1.0.29 → 1.0.31
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/{protocol-worker-CGvoUu0T.js → protocol-worker-BNeN5rOx.js} +284 -280
- package/channel/channel-manager.d.ts +3 -1
- package/client/ikon-client.d.ts +2 -0
- package/index.d.ts +1 -1
- package/index.js +1567 -1529
- package/package.json +1 -1
- package/utils/query-params.d.ts +9 -0
|
@@ -7,18 +7,18 @@ function W(t) {
|
|
|
7
7
|
return $(t) & 4294901760;
|
|
8
8
|
}
|
|
9
9
|
function X(t) {
|
|
10
|
-
const e = Et(t),
|
|
10
|
+
const e = Et(t), r = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
11
11
|
if (e.length < 27)
|
|
12
12
|
throw new Error("Protocol payload too short");
|
|
13
|
-
const
|
|
13
|
+
const s = r.getUint32(0, !0), i = r.getUint32(4, !0), n = r.getUint32(8, !0), a = r.getUint32(12, !0), o = r.getUint32(16, !0), l = r.getUint32(20, !0), h = r.getUint8(24), N = r.getUint8(25), _ = r.getUint8(26);
|
|
14
14
|
if (27 + l * 4 > e.length)
|
|
15
15
|
throw new Error("Protocol header exceeds payload length");
|
|
16
16
|
const c = [];
|
|
17
17
|
let O = 27;
|
|
18
18
|
for (let b = 0; b < l; b++)
|
|
19
|
-
c.push(
|
|
19
|
+
c.push(r.getUint32(O, !0)), O += 4;
|
|
20
20
|
return {
|
|
21
|
-
length:
|
|
21
|
+
length: s,
|
|
22
22
|
opcode: i,
|
|
23
23
|
senderId: n,
|
|
24
24
|
trackId: a,
|
|
@@ -29,9 +29,9 @@ function X(t) {
|
|
|
29
29
|
flags: _
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
function it(t, e,
|
|
32
|
+
function it(t, e, r, s, i) {
|
|
33
33
|
const l = [], N = 27 + l.length * 4, _ = N + e.length, P = new Uint8Array(_), c = new DataView(P.buffer);
|
|
34
|
-
c.setUint32(0, _, !0), c.setUint32(4, t >>> 0, !0), c.setUint32(8,
|
|
34
|
+
c.setUint32(0, _, !0), c.setUint32(4, t >>> 0, !0), c.setUint32(8, s >>> 0, !0), c.setUint32(12, 0, !0), c.setUint32(16, 0, !0), c.setUint32(20, l.length >>> 0, !0), c.setUint8(24, r & 255), c.setUint8(25, 8), c.setUint8(26, 0);
|
|
35
35
|
let O = 27;
|
|
36
36
|
for (let b = 0; b < l.length; b++)
|
|
37
37
|
c.setUint32(O, l[b] >>> 0, !0), O += 4;
|
|
@@ -47,54 +47,54 @@ class M {
|
|
|
47
47
|
buffer = new m();
|
|
48
48
|
closed = !1;
|
|
49
49
|
cached;
|
|
50
|
-
writeInt32Field(e,
|
|
51
|
-
this.writeFixedField(e, 3, () => this.buffer.writeInt32(
|
|
50
|
+
writeInt32Field(e, r) {
|
|
51
|
+
this.writeFixedField(e, 3, () => this.buffer.writeInt32(r | 0));
|
|
52
52
|
}
|
|
53
|
-
writeUInt32Field(e,
|
|
54
|
-
this.writeFixedField(e, 5, () => this.buffer.writeUInt32(
|
|
53
|
+
writeUInt32Field(e, r) {
|
|
54
|
+
this.writeFixedField(e, 5, () => this.buffer.writeUInt32(r >>> 0));
|
|
55
55
|
}
|
|
56
|
-
writeInt64Field(e,
|
|
57
|
-
this.writeFixedField(e, 4, () => this.buffer.writeBigInt64(
|
|
56
|
+
writeInt64Field(e, r) {
|
|
57
|
+
this.writeFixedField(e, 4, () => this.buffer.writeBigInt64(r));
|
|
58
58
|
}
|
|
59
|
-
writeUInt64Field(e,
|
|
60
|
-
this.writeFixedField(e, 6, () => this.buffer.writeBigUInt64(
|
|
59
|
+
writeUInt64Field(e, r) {
|
|
60
|
+
this.writeFixedField(e, 6, () => this.buffer.writeBigUInt64(r));
|
|
61
61
|
}
|
|
62
|
-
writeFloat32Field(e,
|
|
63
|
-
this.writeFixedField(e, 7, () => this.buffer.writeFloat32(
|
|
62
|
+
writeFloat32Field(e, r) {
|
|
63
|
+
this.writeFixedField(e, 7, () => this.buffer.writeFloat32(r));
|
|
64
64
|
}
|
|
65
|
-
writeFloat64Field(e,
|
|
66
|
-
this.writeFixedField(e, 8, () => this.buffer.writeFloat64(
|
|
65
|
+
writeFloat64Field(e, r) {
|
|
66
|
+
this.writeFixedField(e, 8, () => this.buffer.writeFloat64(r));
|
|
67
67
|
}
|
|
68
|
-
writeBoolField(e,
|
|
69
|
-
this.writeFixedField(e, 2, () => this.buffer.writeByte(
|
|
68
|
+
writeBoolField(e, r) {
|
|
69
|
+
this.writeFixedField(e, 2, () => this.buffer.writeByte(r ? 1 : 0));
|
|
70
70
|
}
|
|
71
|
-
writeGuidField(e,
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
71
|
+
writeGuidField(e, r) {
|
|
72
|
+
const s = r instanceof E ? r.asBytes() : r;
|
|
73
|
+
if (s.length !== 16)
|
|
74
74
|
throw new Error("Guid payload must be 16 bytes");
|
|
75
|
-
this.writeFixedField(e, 14, () => this.buffer.writeBytes(
|
|
75
|
+
this.writeFixedField(e, 14, () => this.buffer.writeBytes(s));
|
|
76
76
|
}
|
|
77
|
-
writeStringField(e,
|
|
78
|
-
const
|
|
79
|
-
this.writeVariableField(e, 12,
|
|
77
|
+
writeStringField(e, r) {
|
|
78
|
+
const s = V.encode(r ?? "");
|
|
79
|
+
this.writeVariableField(e, 12, s);
|
|
80
80
|
}
|
|
81
|
-
writeBinaryField(e,
|
|
82
|
-
this.writeVariableField(e, 13,
|
|
81
|
+
writeBinaryField(e, r) {
|
|
82
|
+
this.writeVariableField(e, 13, r);
|
|
83
83
|
}
|
|
84
|
-
writeObjectField(e,
|
|
85
|
-
const i = new M(
|
|
86
|
-
|
|
84
|
+
writeObjectField(e, r, s) {
|
|
85
|
+
const i = new M(r);
|
|
86
|
+
s(i);
|
|
87
87
|
const n = i.finish();
|
|
88
88
|
this.writeVariableField(e, 11, n);
|
|
89
89
|
}
|
|
90
|
-
writeArrayField(e,
|
|
91
|
-
const i = new K(
|
|
92
|
-
|
|
90
|
+
writeArrayField(e, r, s) {
|
|
91
|
+
const i = new K(r);
|
|
92
|
+
s(i);
|
|
93
93
|
const n = i.finish();
|
|
94
94
|
this.writeVariableField(e, 9, n);
|
|
95
95
|
}
|
|
96
|
-
writeDictionaryField(e,
|
|
97
|
-
const n = new Q(
|
|
96
|
+
writeDictionaryField(e, r, s, i) {
|
|
97
|
+
const n = new Q(r, s);
|
|
98
98
|
i(n);
|
|
99
99
|
const a = n.finish();
|
|
100
100
|
this.writeVariableField(e, 10, a);
|
|
@@ -102,14 +102,14 @@ class M {
|
|
|
102
102
|
finish() {
|
|
103
103
|
return this.closed || (this.buffer.writeByte(at), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
|
|
104
104
|
}
|
|
105
|
-
writeFixedField(e,
|
|
106
|
-
this.writeFieldHeader(e,
|
|
105
|
+
writeFixedField(e, r, s) {
|
|
106
|
+
this.writeFieldHeader(e, r, 0), s();
|
|
107
107
|
}
|
|
108
|
-
writeVariableField(e,
|
|
109
|
-
this.writeFieldHeader(e,
|
|
108
|
+
writeVariableField(e, r, s) {
|
|
109
|
+
this.writeFieldHeader(e, r, s.length), this.buffer.writeBytes(s);
|
|
110
110
|
}
|
|
111
|
-
writeFieldHeader(e,
|
|
112
|
-
this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(k(
|
|
111
|
+
writeFieldHeader(e, r, s) {
|
|
112
|
+
this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(k(r)), lt(r) && this.buffer.writeVarUInt(s >>> 0);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
class K {
|
|
@@ -165,18 +165,18 @@ class K {
|
|
|
165
165
|
14
|
|
166
166
|
/* Guid */
|
|
167
167
|
), this.count++;
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
168
|
+
const r = e instanceof E ? e.asBytes() : e;
|
|
169
|
+
if (r.length !== 16)
|
|
170
170
|
throw new Error("Guid payload must be 16 bytes");
|
|
171
|
-
this.payload.writeBytes(
|
|
171
|
+
this.payload.writeBytes(r);
|
|
172
172
|
}
|
|
173
173
|
writeString(e) {
|
|
174
174
|
this.ensureElementType(
|
|
175
175
|
12
|
|
176
176
|
/* String */
|
|
177
177
|
), this.count++;
|
|
178
|
-
const
|
|
179
|
-
this.payload.writeVarUInt(
|
|
178
|
+
const r = V.encode(e ?? "");
|
|
179
|
+
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r);
|
|
180
180
|
}
|
|
181
181
|
writeBinary(e) {
|
|
182
182
|
this.ensureElementType(
|
|
@@ -184,33 +184,33 @@ class K {
|
|
|
184
184
|
/* Binary */
|
|
185
185
|
), this.count++, this.payload.writeVarUInt(e.length), this.payload.writeBytes(e);
|
|
186
186
|
}
|
|
187
|
-
writeObject(e,
|
|
187
|
+
writeObject(e, r) {
|
|
188
188
|
this.ensureElementType(
|
|
189
189
|
11
|
|
190
190
|
/* Object */
|
|
191
191
|
), this.count++;
|
|
192
|
-
const
|
|
193
|
-
s
|
|
194
|
-
const i =
|
|
192
|
+
const s = new M(e);
|
|
193
|
+
r(s);
|
|
194
|
+
const i = s.finish();
|
|
195
195
|
this.payload.writeVarUInt(i.length), this.payload.writeBytes(i);
|
|
196
196
|
}
|
|
197
|
-
writeArray(e,
|
|
197
|
+
writeArray(e, r) {
|
|
198
198
|
this.ensureElementType(
|
|
199
199
|
9
|
|
200
200
|
/* Array */
|
|
201
201
|
), this.count++;
|
|
202
|
-
const
|
|
203
|
-
s
|
|
204
|
-
const i =
|
|
202
|
+
const s = new K(e);
|
|
203
|
+
r(s);
|
|
204
|
+
const i = s.finish();
|
|
205
205
|
this.payload.writeBytes(i);
|
|
206
206
|
}
|
|
207
|
-
writeDictionary(e,
|
|
207
|
+
writeDictionary(e, r, s) {
|
|
208
208
|
this.ensureElementType(
|
|
209
209
|
10
|
|
210
210
|
/* Dict */
|
|
211
211
|
), this.count++;
|
|
212
|
-
const i = new Q(e,
|
|
213
|
-
|
|
212
|
+
const i = new Q(e, r);
|
|
213
|
+
s(i);
|
|
214
214
|
const n = i.finish();
|
|
215
215
|
this.payload.writeBytes(n);
|
|
216
216
|
}
|
|
@@ -224,8 +224,8 @@ class K {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
class Q {
|
|
227
|
-
constructor(e,
|
|
228
|
-
this.keyType = e, this.valueType =
|
|
227
|
+
constructor(e, r) {
|
|
228
|
+
this.keyType = e, this.valueType = r, ht(e);
|
|
229
229
|
}
|
|
230
230
|
payload = new m();
|
|
231
231
|
count = 0;
|
|
@@ -245,8 +245,8 @@ class Q {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
class ot {
|
|
248
|
-
constructor(e,
|
|
249
|
-
this.keyType = e, this.valueType =
|
|
248
|
+
constructor(e, r, s, i) {
|
|
249
|
+
this.keyType = e, this.valueType = r, this.payload = s, this.onComplete = i;
|
|
250
250
|
}
|
|
251
251
|
keyWritten = !1;
|
|
252
252
|
valueWritten = !1;
|
|
@@ -298,18 +298,18 @@ class ot {
|
|
|
298
298
|
14
|
|
299
299
|
/* Guid */
|
|
300
300
|
);
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
301
|
+
const r = e instanceof E ? e.asBytes() : e;
|
|
302
|
+
if (r.length !== 16)
|
|
303
303
|
throw new Error("Guid payload must be 16 bytes");
|
|
304
|
-
this.payload.writeBytes(
|
|
304
|
+
this.payload.writeBytes(r), this.keyWritten = !0;
|
|
305
305
|
}
|
|
306
306
|
writeKeyString(e) {
|
|
307
307
|
this.ensureKeyType(
|
|
308
308
|
12
|
|
309
309
|
/* String */
|
|
310
310
|
);
|
|
311
|
-
const
|
|
312
|
-
this.payload.writeVarUInt(
|
|
311
|
+
const r = V.encode(e ?? "");
|
|
312
|
+
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.keyWritten = !0;
|
|
313
313
|
}
|
|
314
314
|
writeKeyBinary(e) {
|
|
315
315
|
this.ensureKeyType(
|
|
@@ -364,10 +364,10 @@ class ot {
|
|
|
364
364
|
14
|
|
365
365
|
/* Guid */
|
|
366
366
|
);
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
367
|
+
const r = e instanceof E ? e.asBytes() : e;
|
|
368
|
+
if (r.length !== 16)
|
|
369
369
|
throw new Error("Guid payload must be 16 bytes");
|
|
370
|
-
this.payload.writeBytes(
|
|
370
|
+
this.payload.writeBytes(r), this.valueWritten = !0;
|
|
371
371
|
}
|
|
372
372
|
writeNullValue() {
|
|
373
373
|
this.ensureValueType(
|
|
@@ -386,36 +386,36 @@ class ot {
|
|
|
386
386
|
12
|
|
387
387
|
/* String */
|
|
388
388
|
);
|
|
389
|
-
const
|
|
390
|
-
this.payload.writeVarUInt(
|
|
389
|
+
const r = V.encode(e ?? "");
|
|
390
|
+
this.payload.writeVarUInt(r.length), this.payload.writeBytes(r), this.valueWritten = !0;
|
|
391
391
|
}
|
|
392
|
-
writeValueObject(e,
|
|
392
|
+
writeValueObject(e, r) {
|
|
393
393
|
this.ensureValueType(
|
|
394
394
|
11
|
|
395
395
|
/* Object */
|
|
396
396
|
);
|
|
397
|
-
const
|
|
398
|
-
s
|
|
399
|
-
const i =
|
|
397
|
+
const s = new M(e);
|
|
398
|
+
r(s);
|
|
399
|
+
const i = s.finish();
|
|
400
400
|
this.payload.writeVarUInt(i.length), this.payload.writeBytes(i), this.valueWritten = !0;
|
|
401
401
|
}
|
|
402
|
-
writeValueArray(e,
|
|
402
|
+
writeValueArray(e, r) {
|
|
403
403
|
this.ensureValueType(
|
|
404
404
|
9
|
|
405
405
|
/* Array */
|
|
406
406
|
);
|
|
407
|
-
const
|
|
408
|
-
s
|
|
409
|
-
const i =
|
|
407
|
+
const s = new K(e);
|
|
408
|
+
r(s);
|
|
409
|
+
const i = s.finish();
|
|
410
410
|
this.payload.writeBytes(i), this.valueWritten = !0;
|
|
411
411
|
}
|
|
412
|
-
writeValueDictionary(e,
|
|
412
|
+
writeValueDictionary(e, r, s) {
|
|
413
413
|
this.ensureValueType(
|
|
414
414
|
10
|
|
415
415
|
/* Dict */
|
|
416
416
|
);
|
|
417
|
-
const i = new Q(e,
|
|
418
|
-
|
|
417
|
+
const i = new Q(e, r);
|
|
418
|
+
s(i);
|
|
419
419
|
const n = i.finish();
|
|
420
420
|
this.payload.writeBytes(n), this.valueWritten = !0;
|
|
421
421
|
}
|
|
@@ -442,14 +442,14 @@ class E {
|
|
|
442
442
|
static fromString(e) {
|
|
443
443
|
if (!e)
|
|
444
444
|
throw new Error("Guid string is empty");
|
|
445
|
-
const
|
|
446
|
-
if (
|
|
445
|
+
const r = e.replace(/-/g, "");
|
|
446
|
+
if (r.length !== 32)
|
|
447
447
|
throw new Error("Guid string must be 32 hex characters");
|
|
448
|
-
const
|
|
449
|
-
E.writeUInt32LE(
|
|
448
|
+
const s = new Uint8Array(16), i = E.parseHexSlice(r, 0, 8), n = E.parseHexSlice(r, 8, 4), a = E.parseHexSlice(r, 12, 4);
|
|
449
|
+
E.writeUInt32LE(s, 0, i), E.writeUInt16LE(s, 4, n), E.writeUInt16LE(s, 6, a);
|
|
450
450
|
for (let o = 0; o < 8; o++)
|
|
451
|
-
|
|
452
|
-
return new E(
|
|
451
|
+
s[8 + o] = E.parseHexSlice(r, 16 + o * 2, 2);
|
|
452
|
+
return new E(s);
|
|
453
453
|
}
|
|
454
454
|
static fromBytes(e) {
|
|
455
455
|
if (e.length !== 16)
|
|
@@ -460,12 +460,12 @@ class E {
|
|
|
460
460
|
return new E(new Uint8Array(16));
|
|
461
461
|
}
|
|
462
462
|
static createRandom() {
|
|
463
|
-
const e = new Uint8Array(16),
|
|
464
|
-
if (
|
|
465
|
-
|
|
463
|
+
const e = new Uint8Array(16), r = globalThis.crypto;
|
|
464
|
+
if (r?.getRandomValues)
|
|
465
|
+
r.getRandomValues(e);
|
|
466
466
|
else
|
|
467
|
-
for (let
|
|
468
|
-
e[
|
|
467
|
+
for (let s = 0; s < e.length; s++)
|
|
468
|
+
e[s] = Math.floor(Math.random() * 256);
|
|
469
469
|
return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new E(e);
|
|
470
470
|
}
|
|
471
471
|
toString() {
|
|
@@ -481,28 +481,28 @@ class E {
|
|
|
481
481
|
asBytes() {
|
|
482
482
|
return this.bytes.slice();
|
|
483
483
|
}
|
|
484
|
-
static parseHexSlice(e,
|
|
485
|
-
const i = e.substr(
|
|
484
|
+
static parseHexSlice(e, r, s) {
|
|
485
|
+
const i = e.substr(r, s), n = Number.parseInt(i, 16);
|
|
486
486
|
if (Number.isNaN(n))
|
|
487
487
|
throw new Error("Guid string contains invalid characters");
|
|
488
488
|
return n >>> 0;
|
|
489
489
|
}
|
|
490
|
-
static writeUInt32LE(e,
|
|
491
|
-
const i =
|
|
492
|
-
e[
|
|
490
|
+
static writeUInt32LE(e, r, s) {
|
|
491
|
+
const i = s >>> 0;
|
|
492
|
+
e[r] = i & 255, e[r + 1] = i >>> 8 & 255, e[r + 2] = i >>> 16 & 255, e[r + 3] = i >>> 24 & 255;
|
|
493
493
|
}
|
|
494
|
-
static writeUInt16LE(e,
|
|
495
|
-
const i =
|
|
496
|
-
e[
|
|
494
|
+
static writeUInt16LE(e, r, s) {
|
|
495
|
+
const i = s & 65535;
|
|
496
|
+
e[r] = i & 255, e[r + 1] = i >>> 8 & 255;
|
|
497
497
|
}
|
|
498
|
-
static readUInt32LE(e,
|
|
499
|
-
return (e[
|
|
498
|
+
static readUInt32LE(e, r) {
|
|
499
|
+
return (e[r] | e[r + 1] << 8 | e[r + 2] << 16 | e[r + 3] << 24) >>> 0;
|
|
500
500
|
}
|
|
501
|
-
static readUInt16LE(e,
|
|
502
|
-
return (e[
|
|
501
|
+
static readUInt16LE(e, r) {
|
|
502
|
+
return (e[r] | e[r + 1] << 8) & 65535;
|
|
503
503
|
}
|
|
504
|
-
static toHex(e,
|
|
505
|
-
return (e >>> 0).toString(16).padStart(
|
|
504
|
+
static toHex(e, r) {
|
|
505
|
+
return (e >>> 0).toString(16).padStart(r, "0");
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
class m {
|
|
@@ -514,13 +514,13 @@ class m {
|
|
|
514
514
|
this.buffer = new Uint8Array(m.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
|
|
515
515
|
}
|
|
516
516
|
ensureCapacity(e) {
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
517
|
+
const r = this.length + e;
|
|
518
|
+
if (r <= this.buffer.length)
|
|
519
519
|
return;
|
|
520
|
-
let
|
|
521
|
-
for (;
|
|
522
|
-
|
|
523
|
-
const i = new Uint8Array(
|
|
520
|
+
let s = this.buffer.length;
|
|
521
|
+
for (; s < r; )
|
|
522
|
+
s *= 2;
|
|
523
|
+
const i = new Uint8Array(s);
|
|
524
524
|
i.set(this.buffer.subarray(0, this.length)), this.buffer = i, this.dataView = new DataView(this.buffer.buffer);
|
|
525
525
|
}
|
|
526
526
|
writeByte(e) {
|
|
@@ -548,10 +548,10 @@ class m {
|
|
|
548
548
|
this.ensureCapacity(8), this.dataView.setBigUint64(this.length, e, !0), this.length += 8;
|
|
549
549
|
}
|
|
550
550
|
writeVarUInt(e) {
|
|
551
|
-
let
|
|
552
|
-
for (;
|
|
553
|
-
this.ensureCapacity(1), this.buffer[this.length++] =
|
|
554
|
-
this.ensureCapacity(1), this.buffer[this.length++] =
|
|
551
|
+
let r = e >>> 0;
|
|
552
|
+
for (; r >= 128; )
|
|
553
|
+
this.ensureCapacity(1), this.buffer[this.length++] = r & 127 | 128, r >>>= 7;
|
|
554
|
+
this.ensureCapacity(1), this.buffer[this.length++] = r & 127;
|
|
555
555
|
}
|
|
556
556
|
toUint8Array() {
|
|
557
557
|
return this.buffer.slice(0, this.length);
|
|
@@ -583,18 +583,18 @@ function Z(t) {
|
|
|
583
583
|
function Tt(t) {
|
|
584
584
|
return new M(J).finish();
|
|
585
585
|
}
|
|
586
|
-
function tt(t, e,
|
|
587
|
-
const
|
|
588
|
-
return it(_t,
|
|
586
|
+
function tt(t, e, r) {
|
|
587
|
+
const s = Tt();
|
|
588
|
+
return it(_t, s, J, e);
|
|
589
589
|
}
|
|
590
590
|
class et extends Error {
|
|
591
|
-
constructor(e,
|
|
592
|
-
super(e), this.cause =
|
|
591
|
+
constructor(e, r) {
|
|
592
|
+
super(e), this.cause = r, this.name = "ConnectionError";
|
|
593
593
|
}
|
|
594
594
|
}
|
|
595
595
|
class L extends et {
|
|
596
|
-
constructor(e,
|
|
597
|
-
super(e,
|
|
596
|
+
constructor(e, r) {
|
|
597
|
+
super(e, r), this.name = "TransportError";
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
class z extends L {
|
|
@@ -608,14 +608,14 @@ class ct extends et {
|
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
610
|
function It(t, e) {
|
|
611
|
-
return new Promise((
|
|
611
|
+
return new Promise((r, s) => {
|
|
612
612
|
const i = () => {
|
|
613
|
-
clearTimeout(n),
|
|
613
|
+
clearTimeout(n), s(new Error("Aborted"));
|
|
614
614
|
}, n = setTimeout(() => {
|
|
615
|
-
e?.removeEventListener("abort", i),
|
|
615
|
+
e?.removeEventListener("abort", i), r();
|
|
616
616
|
}, t);
|
|
617
617
|
if (e?.aborted) {
|
|
618
|
-
clearTimeout(n),
|
|
618
|
+
clearTimeout(n), s(new Error("Aborted"));
|
|
619
619
|
return;
|
|
620
620
|
}
|
|
621
621
|
e?.addEventListener("abort", i, { once: !0 });
|
|
@@ -632,14 +632,14 @@ const At = /* @__PURE__ */ new Map(), Ct = {
|
|
|
632
632
|
function ft(t, e) {
|
|
633
633
|
return `[${t}] ${e}`;
|
|
634
634
|
}
|
|
635
|
-
function p(t, e,
|
|
635
|
+
function p(t, e, r, s) {
|
|
636
636
|
const i = (/* @__PURE__ */ new Date()).toISOString(), n = Ct[t], a = {
|
|
637
637
|
timestamp: i,
|
|
638
638
|
level: t,
|
|
639
639
|
levelName: n,
|
|
640
640
|
component: e,
|
|
641
|
-
message:
|
|
642
|
-
args:
|
|
641
|
+
message: r,
|
|
642
|
+
args: s
|
|
643
643
|
};
|
|
644
644
|
for (const [o, l] of At) {
|
|
645
645
|
const h = l?.minLevel ?? 2;
|
|
@@ -650,36 +650,36 @@ function p(t, e, s, r) {
|
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
if (ut <= t) {
|
|
653
|
-
const o = ft(e,
|
|
653
|
+
const o = ft(e, r);
|
|
654
654
|
switch (t) {
|
|
655
655
|
case 0:
|
|
656
|
-
console.debug(o, ...
|
|
656
|
+
console.debug(o, ...s);
|
|
657
657
|
break;
|
|
658
658
|
case 1:
|
|
659
|
-
console.info(o, ...
|
|
659
|
+
console.info(o, ...s);
|
|
660
660
|
break;
|
|
661
661
|
case 2:
|
|
662
|
-
console.warn(o, ...
|
|
662
|
+
console.warn(o, ...s);
|
|
663
663
|
break;
|
|
664
664
|
case 3:
|
|
665
|
-
console.error(o, ...
|
|
665
|
+
console.error(o, ...s);
|
|
666
666
|
break;
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
function F(t) {
|
|
671
671
|
return {
|
|
672
|
-
debug(e, ...
|
|
673
|
-
p(0, t, e,
|
|
672
|
+
debug(e, ...r) {
|
|
673
|
+
p(0, t, e, r);
|
|
674
674
|
},
|
|
675
|
-
info(e, ...
|
|
676
|
-
p(1, t, e,
|
|
675
|
+
info(e, ...r) {
|
|
676
|
+
p(1, t, e, r);
|
|
677
677
|
},
|
|
678
|
-
warn(e, ...
|
|
679
|
-
p(2, t, e,
|
|
678
|
+
warn(e, ...r) {
|
|
679
|
+
p(2, t, e, r);
|
|
680
680
|
},
|
|
681
|
-
error(e, ...
|
|
682
|
-
p(3, t, e,
|
|
681
|
+
error(e, ...r) {
|
|
682
|
+
p(3, t, e, r);
|
|
683
683
|
}
|
|
684
684
|
};
|
|
685
685
|
}
|
|
@@ -699,8 +699,8 @@ class Rt {
|
|
|
699
699
|
get isConnected() {
|
|
700
700
|
return this.ws?.readyState === WebSocket.OPEN;
|
|
701
701
|
}
|
|
702
|
-
async connect(e,
|
|
703
|
-
return this.isClosed = !1, new Promise((
|
|
702
|
+
async connect(e, r) {
|
|
703
|
+
return this.isClosed = !1, new Promise((s, i) => {
|
|
704
704
|
try {
|
|
705
705
|
this.ws = new WebSocket(e), this.ws.binaryType = "arraybuffer";
|
|
706
706
|
} catch (h) {
|
|
@@ -714,7 +714,7 @@ class Rt {
|
|
|
714
714
|
a || (a = !0, o(), this.ws?.close(), i(new L("WebSocket connection timeout")));
|
|
715
715
|
}, Nt);
|
|
716
716
|
this.ws.onopen = () => {
|
|
717
|
-
n = !0, clearTimeout(l), this.ws.send(
|
|
717
|
+
n = !0, clearTimeout(l), this.ws.send(r), this.resetKeepaliveTimeout(), a || (a = !0, s());
|
|
718
718
|
}, this.ws.onerror = () => {
|
|
719
719
|
clearTimeout(l), G.error("WebSocket error"), a || (a = !0, o(), i(new L("WebSocket connection failed")));
|
|
720
720
|
}, this.ws.onclose = (h) => {
|
|
@@ -750,8 +750,8 @@ class Rt {
|
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
752
752
|
this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
|
|
753
|
-
} catch (
|
|
754
|
-
G.error("Failed to process protocol message:",
|
|
753
|
+
} catch (r) {
|
|
754
|
+
G.error("Failed to process protocol message:", r), this.callbacks.onError(r instanceof Error ? r : new Error(String(r)));
|
|
755
755
|
}
|
|
756
756
|
}
|
|
757
757
|
resetKeepaliveTimeout() {
|
|
@@ -764,7 +764,7 @@ class Rt {
|
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
const y = F("WebTransportTransport"), q = 4, yt = 65536;
|
|
767
|
-
function
|
|
767
|
+
function rt() {
|
|
768
768
|
return typeof WebTransport < "u";
|
|
769
769
|
}
|
|
770
770
|
class St {
|
|
@@ -793,18 +793,18 @@ class St {
|
|
|
793
793
|
get isConnected() {
|
|
794
794
|
return this.transport !== null && this.writer !== null;
|
|
795
795
|
}
|
|
796
|
-
async connect(e,
|
|
797
|
-
if (!
|
|
796
|
+
async connect(e, r) {
|
|
797
|
+
if (!rt())
|
|
798
798
|
throw new L("WebTransport is not supported in this browser");
|
|
799
799
|
this.isClosed = !1;
|
|
800
800
|
try {
|
|
801
801
|
this.transport = new WebTransport(e), await this.transport.ready, y.debug(`Connected to WebTransport entrypoint: ${e}`), this.transport.closed.then(() => {
|
|
802
802
|
this.handleClose("Connection closed", !0);
|
|
803
|
-
}).catch((
|
|
804
|
-
y.error("WebTransport connection closed with error:",
|
|
805
|
-
}), this.stream = await this.transport.createBidirectionalStream(), this.reader = this.stream.readable.getReader(), this.writer = this.stream.writable.getWriter(), await this.writer.write(
|
|
806
|
-
} catch (
|
|
807
|
-
throw this.cleanup(), new L(`Failed to connect WebTransport: ${
|
|
803
|
+
}).catch((s) => {
|
|
804
|
+
y.error("WebTransport connection closed with error:", s), this.handleClose(s.message || "Connection error", !1);
|
|
805
|
+
}), this.stream = await this.transport.createBidirectionalStream(), this.reader = this.stream.readable.getReader(), this.writer = this.stream.writable.getWriter(), await this.writer.write(r), this.resetKeepaliveTimeout(), this.startReadLoop();
|
|
806
|
+
} catch (s) {
|
|
807
|
+
throw this.cleanup(), new L(`Failed to connect WebTransport: ${s}`, s instanceof Error ? s : void 0);
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
810
|
send(e) {
|
|
@@ -812,8 +812,8 @@ class St {
|
|
|
812
812
|
y.warn("Cannot send: WebTransport not connected");
|
|
813
813
|
return;
|
|
814
814
|
}
|
|
815
|
-
this.writer.write(e).catch((
|
|
816
|
-
y.error("Failed to send protocol message:",
|
|
815
|
+
this.writer.write(e).catch((r) => {
|
|
816
|
+
y.error("Failed to send protocol message:", r), this.callbacks.onError(r instanceof Error ? r : new Error(String(r)));
|
|
817
817
|
});
|
|
818
818
|
}
|
|
819
819
|
close() {
|
|
@@ -827,8 +827,8 @@ class St {
|
|
|
827
827
|
this.readLoopActive = !0;
|
|
828
828
|
try {
|
|
829
829
|
for (; this.readLoopActive && this.reader; ) {
|
|
830
|
-
const { value: e, done:
|
|
831
|
-
if (
|
|
830
|
+
const { value: e, done: r } = await this.reader.read();
|
|
831
|
+
if (r)
|
|
832
832
|
break;
|
|
833
833
|
e && (this.appendToBuffer(e), this.processBufferedMessages());
|
|
834
834
|
}
|
|
@@ -843,13 +843,13 @@ class St {
|
|
|
843
843
|
* Compacts when offset exceeds half capacity and data is sparse.
|
|
844
844
|
*/
|
|
845
845
|
appendToBuffer(e) {
|
|
846
|
-
const
|
|
847
|
-
if (
|
|
848
|
-
if (
|
|
849
|
-
const i = Math.max(
|
|
850
|
-
n.set(this.receiveBuffer.subarray(this.receiveBufferOffset,
|
|
846
|
+
const r = this.receiveBufferLength + e.length, s = this.receiveBufferOffset + this.receiveBufferLength;
|
|
847
|
+
if (s + e.length > this.receiveBuffer.length)
|
|
848
|
+
if (r > this.receiveBuffer.length) {
|
|
849
|
+
const i = Math.max(r, this.receiveBuffer.length * 2), n = new Uint8Array(i);
|
|
850
|
+
n.set(this.receiveBuffer.subarray(this.receiveBufferOffset, s)), this.receiveBuffer = n, this.receiveBufferOffset = 0, this.receiveDataViewBuffer = null;
|
|
851
851
|
} else
|
|
852
|
-
this.receiveBuffer.copyWithin(0, this.receiveBufferOffset,
|
|
852
|
+
this.receiveBuffer.copyWithin(0, this.receiveBufferOffset, s), this.receiveBufferOffset = 0;
|
|
853
853
|
this.receiveBuffer.set(e, this.receiveBufferOffset + this.receiveBufferLength), this.receiveBufferLength += e.length;
|
|
854
854
|
}
|
|
855
855
|
/**
|
|
@@ -873,15 +873,15 @@ class St {
|
|
|
873
873
|
processBufferedMessages() {
|
|
874
874
|
const e = this.getReceiveDataView();
|
|
875
875
|
for (; this.receiveBufferLength >= q; ) {
|
|
876
|
-
const
|
|
877
|
-
if (
|
|
878
|
-
y.error(`Invalid message length: ${
|
|
876
|
+
const r = e.getUint32(this.receiveBufferOffset, !0);
|
|
877
|
+
if (r < q) {
|
|
878
|
+
y.error(`Invalid message length: ${r}`), this.callbacks.onError(new Error(`Invalid protocol message length: ${r}`)), this.receiveBufferOffset = 0, this.receiveBufferLength = 0;
|
|
879
879
|
return;
|
|
880
880
|
}
|
|
881
|
-
if (this.receiveBufferLength <
|
|
881
|
+
if (this.receiveBufferLength < r)
|
|
882
882
|
return;
|
|
883
|
-
const
|
|
884
|
-
this.receiveBufferOffset +=
|
|
883
|
+
const s = this.receiveBuffer.subarray(this.receiveBufferOffset, this.receiveBufferOffset + r);
|
|
884
|
+
this.receiveBufferOffset += r, this.receiveBufferLength -= r, this.handleProtocolMessage(s);
|
|
885
885
|
}
|
|
886
886
|
this.receiveBufferLength === 0 && (this.receiveBufferOffset = 0);
|
|
887
887
|
}
|
|
@@ -895,15 +895,15 @@ class St {
|
|
|
895
895
|
return;
|
|
896
896
|
}
|
|
897
897
|
this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
|
|
898
|
-
} catch (
|
|
899
|
-
y.error("Failed to process protocol message:",
|
|
898
|
+
} catch (r) {
|
|
899
|
+
y.error("Failed to process protocol message:", r), this.callbacks.onError(r instanceof Error ? r : new Error(String(r)));
|
|
900
900
|
}
|
|
901
901
|
}
|
|
902
902
|
/**
|
|
903
903
|
* Handle connection close.
|
|
904
904
|
*/
|
|
905
|
-
handleClose(e,
|
|
906
|
-
this.isClosed || (this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup(), this.callbacks.onClose(e,
|
|
905
|
+
handleClose(e, r) {
|
|
906
|
+
this.isClosed || (this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup(), this.callbacks.onClose(e, r, !1));
|
|
907
907
|
}
|
|
908
908
|
/**
|
|
909
909
|
* Reset the keepalive timeout.
|
|
@@ -1005,25 +1005,25 @@ class Ut {
|
|
|
1005
1005
|
* Connect the transport to the entrypoint.
|
|
1006
1006
|
*/
|
|
1007
1007
|
async connectTransport() {
|
|
1008
|
-
const e = this.entrypoint,
|
|
1008
|
+
const e = this.entrypoint, r = {
|
|
1009
1009
|
sessionId: this.config.sessionId,
|
|
1010
1010
|
keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
|
|
1011
1011
|
callbacks: {
|
|
1012
|
-
onProtocolMessage: (
|
|
1013
|
-
onClose: (
|
|
1014
|
-
onError: (
|
|
1012
|
+
onProtocolMessage: (s) => this.handleProtocolMessage(s),
|
|
1013
|
+
onClose: (s, i, n) => this.handleClose(s, i, n),
|
|
1014
|
+
onError: (s) => this.handleError(s)
|
|
1015
1015
|
}
|
|
1016
1016
|
};
|
|
1017
1017
|
switch (e.Type) {
|
|
1018
1018
|
case R.WebSocket:
|
|
1019
1019
|
case R.WebSocketProxy:
|
|
1020
|
-
this.transport = new Rt(
|
|
1020
|
+
this.transport = new Rt(r);
|
|
1021
1021
|
break;
|
|
1022
1022
|
case R.WebTransport:
|
|
1023
1023
|
case R.WebTransportProxy:
|
|
1024
|
-
if (!
|
|
1024
|
+
if (!rt())
|
|
1025
1025
|
throw new Error("WebTransport is not supported in this browser");
|
|
1026
|
-
this.transport = new St(
|
|
1026
|
+
this.transport = new St(r);
|
|
1027
1027
|
break;
|
|
1028
1028
|
default:
|
|
1029
1029
|
throw new Error(`Unsupported entrypoint type: ${R[e.Type]}`);
|
|
@@ -1035,21 +1035,21 @@ class Ut {
|
|
|
1035
1035
|
*/
|
|
1036
1036
|
handleProtocolMessage(e) {
|
|
1037
1037
|
try {
|
|
1038
|
-
const
|
|
1039
|
-
if ($(
|
|
1038
|
+
const r = e;
|
|
1039
|
+
if ($(r) === d.CORE_ON_SERVER_STOPPING) {
|
|
1040
1040
|
D.debug("Received server stopping message"), this.setState("stopped"), this.transport?.close();
|
|
1041
1041
|
return;
|
|
1042
1042
|
}
|
|
1043
|
-
this.config.onProtocolMessage?.(
|
|
1044
|
-
} catch (
|
|
1045
|
-
D.error("Failed to handle protocol message:",
|
|
1043
|
+
this.config.onProtocolMessage?.(r);
|
|
1044
|
+
} catch (r) {
|
|
1045
|
+
D.error("Failed to handle protocol message:", r), this.config.onError?.(r instanceof Error ? r : new Error(String(r)));
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
1048
|
/**
|
|
1049
1049
|
* Handle transport close.
|
|
1050
1050
|
*/
|
|
1051
|
-
handleClose(e,
|
|
1052
|
-
this.transport = null, this.config.onClose?.(e,
|
|
1051
|
+
handleClose(e, r, s) {
|
|
1052
|
+
this.transport = null, this.config.onClose?.(e, r, s);
|
|
1053
1053
|
}
|
|
1054
1054
|
/**
|
|
1055
1055
|
* Handle transport error.
|
|
@@ -1096,10 +1096,14 @@ class wt {
|
|
|
1096
1096
|
/**
|
|
1097
1097
|
* Connect to the server using the provided entrypoints.
|
|
1098
1098
|
*/
|
|
1099
|
-
async connect(e) {
|
|
1099
|
+
async connect(e, r) {
|
|
1100
1100
|
if (this.state !== "idle" && this.state !== "offline")
|
|
1101
1101
|
throw new Error(`Cannot connect: already in state ${this.state}`);
|
|
1102
|
-
this.entrypoints = e, this.shouldReconnect = !0, this.reconnectAttempts = 0, this.demotedTypes.clear(), this.connectionStable = !1, this.abortController = new AbortController(),
|
|
1102
|
+
if (this.entrypoints = e, this.shouldReconnect = !0, this.reconnectAttempts = 0, this.demotedTypes.clear(), this.connectionStable = !1, this.abortController = new AbortController(), r?.retry) {
|
|
1103
|
+
this.attemptReconnect();
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
await this.connectInternal();
|
|
1103
1107
|
}
|
|
1104
1108
|
/**
|
|
1105
1109
|
* Disconnect all channels.
|
|
@@ -1112,9 +1116,9 @@ class wt {
|
|
|
1112
1116
|
* The opcode group is extracted from the message automatically.
|
|
1113
1117
|
*/
|
|
1114
1118
|
sendProtocolMessage(e) {
|
|
1115
|
-
const
|
|
1116
|
-
for (const [
|
|
1117
|
-
if (
|
|
1119
|
+
const r = W(e);
|
|
1120
|
+
for (const [s, i] of this.channels)
|
|
1121
|
+
if (s & r) {
|
|
1118
1122
|
i.send(e);
|
|
1119
1123
|
return;
|
|
1120
1124
|
}
|
|
@@ -1124,8 +1128,8 @@ class wt {
|
|
|
1124
1128
|
* Send a protocol message to all channels (for broadcast messages).
|
|
1125
1129
|
*/
|
|
1126
1130
|
sendToAll(e) {
|
|
1127
|
-
for (const
|
|
1128
|
-
|
|
1131
|
+
for (const r of this.channels.values())
|
|
1132
|
+
r.send(e);
|
|
1129
1133
|
}
|
|
1130
1134
|
/**
|
|
1131
1135
|
* Check health of all channels.
|
|
@@ -1144,27 +1148,27 @@ class wt {
|
|
|
1144
1148
|
*/
|
|
1145
1149
|
async connectInternal(e = !1) {
|
|
1146
1150
|
this.setState("connecting");
|
|
1147
|
-
let
|
|
1151
|
+
let r = this.entrypoints;
|
|
1148
1152
|
if (this.config.webRtcEnabled) {
|
|
1149
1153
|
T.debug(`WebRTC enabled, filtering entrypoints (total: ${this.entrypoints.length})`);
|
|
1150
1154
|
for (const a of this.entrypoints)
|
|
1151
1155
|
T.debug(` Entrypoint: type=${a.Type} fromServer=0x${a.OpcodeGroupsFromServer.toString(16)} toServer=0x${a.OpcodeGroupsToServer.toString(16)} uri=${a.Uri}`);
|
|
1152
1156
|
const n = d.GROUP_AUDIO | d.GROUP_VIDEO;
|
|
1153
|
-
|
|
1157
|
+
r = this.entrypoints.filter((a) => {
|
|
1154
1158
|
if (a.Type === R.WebRTC)
|
|
1155
1159
|
return T.debug(` Filtered out WebRTC entrypoint (type=${a.Type})`), !1;
|
|
1156
1160
|
const o = a.OpcodeGroupsFromServer | a.OpcodeGroupsToServer;
|
|
1157
1161
|
return (o & ~n) === 0 ? (T.debug(` Filtered out audio/video-only entrypoint (type=${a.Type}, groups=0x${o.toString(16)})`), !1) : !0;
|
|
1158
|
-
}), T.debug(`After filtering: ${
|
|
1162
|
+
}), T.debug(`After filtering: ${r.length} entrypoints remain for WS/WT channels`);
|
|
1159
1163
|
}
|
|
1160
|
-
const
|
|
1161
|
-
if (
|
|
1164
|
+
const s = this.groupByType(r);
|
|
1165
|
+
if (s.size === 0)
|
|
1162
1166
|
throw this.setState("offline"), new Error("No entrypoints available");
|
|
1163
1167
|
let i;
|
|
1164
1168
|
if (this.config.orderedEndpointTypes && this.config.orderedEndpointTypes.length > 0) {
|
|
1165
|
-
const n = new Set(
|
|
1169
|
+
const n = new Set(s.keys());
|
|
1166
1170
|
i = this.config.orderedEndpointTypes.filter((a) => n.has(a));
|
|
1167
|
-
} else this.config.endpointSelector ? i = this.config.endpointSelector.getOrderedTypes(
|
|
1171
|
+
} else this.config.endpointSelector ? i = this.config.endpointSelector.getOrderedTypes(s) : i = Array.from(s.keys());
|
|
1168
1172
|
if (this.demotedTypes.size > 0) {
|
|
1169
1173
|
const n = i.filter((o) => !this.demotedTypes.has(o)), a = i.filter((o) => this.demotedTypes.has(o));
|
|
1170
1174
|
i = [...n, ...a];
|
|
@@ -1172,7 +1176,7 @@ class wt {
|
|
|
1172
1176
|
for (const n of i) {
|
|
1173
1177
|
if (!this.shouldReconnect)
|
|
1174
1178
|
return;
|
|
1175
|
-
const a =
|
|
1179
|
+
const a = s.get(n);
|
|
1176
1180
|
try {
|
|
1177
1181
|
await this.connectAllChannels(a), this.config.endpointSelector?.rememberWorkingType(n), this.config.onRememberWorkingType?.(n), this.activeType = n, this.startStabilityTimer(), this.setState("connected");
|
|
1178
1182
|
return;
|
|
@@ -1188,56 +1192,56 @@ class wt {
|
|
|
1188
1192
|
async connectAllChannels(e) {
|
|
1189
1193
|
if (e.length === 0)
|
|
1190
1194
|
throw new Error("No entrypoints to connect");
|
|
1191
|
-
const
|
|
1192
|
-
if (
|
|
1193
|
-
const i =
|
|
1194
|
-
throw new Error(`${
|
|
1195
|
+
const s = (await Promise.allSettled(e.map((i) => this.connectChannel(i)))).filter((i) => i.status === "rejected");
|
|
1196
|
+
if (s.length > 0) {
|
|
1197
|
+
const i = s.map((n) => n.reason);
|
|
1198
|
+
throw new Error(`${s.length} channel(s) failed: ${i.join(", ")}`);
|
|
1195
1199
|
}
|
|
1196
1200
|
}
|
|
1197
1201
|
/**
|
|
1198
1202
|
* Connect a single channel.
|
|
1199
1203
|
*/
|
|
1200
1204
|
async connectChannel(e) {
|
|
1201
|
-
const
|
|
1205
|
+
const r = new Ut({
|
|
1202
1206
|
entrypoint: e,
|
|
1203
1207
|
sessionId: this.config.sessionId,
|
|
1204
1208
|
keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
|
|
1205
|
-
onProtocolMessage: (
|
|
1206
|
-
this.config.onProtocolMessage?.(
|
|
1209
|
+
onProtocolMessage: (s) => {
|
|
1210
|
+
this.config.onProtocolMessage?.(s);
|
|
1207
1211
|
},
|
|
1208
|
-
onStateChange: (
|
|
1209
|
-
this.handleChannelStateChange(e.OpcodeGroupsFromServer,
|
|
1212
|
+
onStateChange: (s) => {
|
|
1213
|
+
this.handleChannelStateChange(e.OpcodeGroupsFromServer, s);
|
|
1210
1214
|
},
|
|
1211
|
-
onClose: (
|
|
1212
|
-
this.handleChannelClose(e.OpcodeGroupsFromServer,
|
|
1215
|
+
onClose: (s, i, n) => {
|
|
1216
|
+
this.handleChannelClose(e.OpcodeGroupsFromServer, s, i, n);
|
|
1213
1217
|
},
|
|
1214
|
-
onError: (
|
|
1215
|
-
this.config.onError?.(
|
|
1218
|
+
onError: (s) => {
|
|
1219
|
+
this.config.onError?.(s);
|
|
1216
1220
|
}
|
|
1217
1221
|
});
|
|
1218
|
-
await
|
|
1222
|
+
await r.connect(), this.channels.set(e.OpcodeGroupsFromServer, r);
|
|
1219
1223
|
}
|
|
1220
1224
|
/**
|
|
1221
1225
|
* Group entrypoints by type.
|
|
1222
1226
|
*/
|
|
1223
1227
|
groupByType(e) {
|
|
1224
|
-
const
|
|
1225
|
-
for (const
|
|
1226
|
-
const i =
|
|
1227
|
-
i.push(
|
|
1228
|
+
const r = /* @__PURE__ */ new Map();
|
|
1229
|
+
for (const s of e) {
|
|
1230
|
+
const i = r.get(s.Type) ?? [];
|
|
1231
|
+
i.push(s), r.set(s.Type, i);
|
|
1228
1232
|
}
|
|
1229
|
-
return
|
|
1233
|
+
return r;
|
|
1230
1234
|
}
|
|
1231
1235
|
/**
|
|
1232
1236
|
* Handle channel state change.
|
|
1233
1237
|
*/
|
|
1234
|
-
handleChannelStateChange(e,
|
|
1235
|
-
|
|
1238
|
+
handleChannelStateChange(e, r) {
|
|
1239
|
+
r === "stopped" && (this.shouldReconnect = !1, this.disconnectAll(), this.setState("stopped"));
|
|
1236
1240
|
}
|
|
1237
1241
|
/**
|
|
1238
1242
|
* Handle channel close.
|
|
1239
1243
|
*/
|
|
1240
|
-
handleChannelClose(e,
|
|
1244
|
+
handleChannelClose(e, r, s, i) {
|
|
1241
1245
|
if (!(this.state === "idle" || this.state === "stopped" || this.state === "offline") && this.channels.has(e)) {
|
|
1242
1246
|
if (i) {
|
|
1243
1247
|
T.debug("Channel closed by server"), this.shouldReconnect = !1, this.disconnectAll(), this.setState("stopped");
|
|
@@ -1295,7 +1299,7 @@ class wt {
|
|
|
1295
1299
|
this.state !== e && (this.state = e, this.config.onStateChange?.(e));
|
|
1296
1300
|
}
|
|
1297
1301
|
}
|
|
1298
|
-
const
|
|
1302
|
+
const st = F("ProtocolWorker"), w = (t, e) => {
|
|
1299
1303
|
self.postMessage(t, e ?? []);
|
|
1300
1304
|
};
|
|
1301
1305
|
let A = null, H, u = null;
|
|
@@ -1304,7 +1308,7 @@ function Y() {
|
|
|
1304
1308
|
try {
|
|
1305
1309
|
A?.disconnect();
|
|
1306
1310
|
} catch (t) {
|
|
1307
|
-
|
|
1311
|
+
st.warn(`Failed to disconnect channel manager: ${t}`);
|
|
1308
1312
|
}
|
|
1309
1313
|
A = null;
|
|
1310
1314
|
for (let t = 0; t < C.length; t++)
|
|
@@ -1336,14 +1340,14 @@ function Lt(t) {
|
|
|
1336
1340
|
const e = W(t);
|
|
1337
1341
|
if ((e & H) !== 0)
|
|
1338
1342
|
return !0;
|
|
1339
|
-
const
|
|
1340
|
-
return (e &
|
|
1343
|
+
const r = gt();
|
|
1344
|
+
return (e & r) !== 0;
|
|
1341
1345
|
}
|
|
1342
1346
|
function mt(t) {
|
|
1343
1347
|
x.length = 0;
|
|
1344
1348
|
for (let e = 0; e < C.length; e++) {
|
|
1345
|
-
const
|
|
1346
|
-
(
|
|
1349
|
+
const r = C[e];
|
|
1350
|
+
(r.opcodeGroupsMask & t) !== 0 && x.push(r.port);
|
|
1347
1351
|
}
|
|
1348
1352
|
return x;
|
|
1349
1353
|
}
|
|
@@ -1353,15 +1357,15 @@ function dt(t, e) {
|
|
|
1353
1357
|
function Pt(t, e) {
|
|
1354
1358
|
if (!A || !e || typeof e != "object")
|
|
1355
1359
|
return;
|
|
1356
|
-
const
|
|
1357
|
-
if (!(
|
|
1360
|
+
const r = e;
|
|
1361
|
+
if (!(r.type !== "send" || !(r.message instanceof ArrayBuffer)))
|
|
1358
1362
|
try {
|
|
1359
|
-
const
|
|
1360
|
-
if (!dt(
|
|
1363
|
+
const s = new Uint8Array(r.message);
|
|
1364
|
+
if (!dt(s, t))
|
|
1361
1365
|
return;
|
|
1362
|
-
A.sendProtocolMessage(
|
|
1363
|
-
} catch (
|
|
1364
|
-
B(
|
|
1366
|
+
A.sendProtocolMessage(s), u && u.postMessage({ direction: "sent", message: Array.from(s) });
|
|
1367
|
+
} catch (s) {
|
|
1368
|
+
B(s);
|
|
1365
1369
|
}
|
|
1366
1370
|
}
|
|
1367
1371
|
async function bt(t) {
|
|
@@ -1383,16 +1387,16 @@ async function bt(t) {
|
|
|
1383
1387
|
},
|
|
1384
1388
|
onProtocolMessage: (e) => {
|
|
1385
1389
|
u && (u.postMessage({ direction: "received", message: Array.from(e) }), $(e) === d.ANALYTICS_LOGS && u.postMessage({ type: "serverLogs", message: Array.from(e) }));
|
|
1386
|
-
const
|
|
1387
|
-
if (!(!
|
|
1390
|
+
const r = W(e), s = Lt(e), i = mt(r);
|
|
1391
|
+
if (!(!s && i.length === 0))
|
|
1388
1392
|
try {
|
|
1389
1393
|
const n = X(e), a = e.buffer instanceof ArrayBuffer && e.byteOffset === 0 && e.byteLength === e.buffer.byteLength, o = i.length > 0;
|
|
1390
|
-
if (o && !
|
|
1394
|
+
if (o && !s && i.length === 1 && a) {
|
|
1391
1395
|
const l = e.buffer;
|
|
1392
1396
|
i[0].postMessage({ type: "protocol", message: l, headers: n }, [l]);
|
|
1393
1397
|
return;
|
|
1394
1398
|
}
|
|
1395
|
-
if (!o &&
|
|
1399
|
+
if (!o && s && a) {
|
|
1396
1400
|
const l = e.buffer;
|
|
1397
1401
|
w({ type: "protocol", message: l, headers: n }, [l]);
|
|
1398
1402
|
return;
|
|
@@ -1401,7 +1405,7 @@ async function bt(t) {
|
|
|
1401
1405
|
const l = [];
|
|
1402
1406
|
for (let _ = 1; _ < i.length; _++)
|
|
1403
1407
|
l.push(e.slice().buffer);
|
|
1404
|
-
const h =
|
|
1408
|
+
const h = s ? e.slice().buffer : null, N = e.buffer;
|
|
1405
1409
|
i[0].postMessage({ type: "protocol", message: N, headers: n }, [N]);
|
|
1406
1410
|
for (let _ = 1; _ < i.length; _++)
|
|
1407
1411
|
i[_].postMessage({ type: "protocol", message: l[_ - 1], headers: n }, [l[_ - 1]]);
|
|
@@ -1413,7 +1417,7 @@ async function bt(t) {
|
|
|
1413
1417
|
const h = e.slice().buffer;
|
|
1414
1418
|
l.postMessage({ type: "protocol", message: h, headers: n }, [h]);
|
|
1415
1419
|
}
|
|
1416
|
-
if (
|
|
1420
|
+
if (s) {
|
|
1417
1421
|
const l = e.slice().buffer;
|
|
1418
1422
|
w({ type: "protocol", message: l, headers: n }, [l]);
|
|
1419
1423
|
}
|
|
@@ -1421,13 +1425,13 @@ async function bt(t) {
|
|
|
1421
1425
|
B(n);
|
|
1422
1426
|
}
|
|
1423
1427
|
}
|
|
1424
|
-
}), await A.connect(t.entrypoints);
|
|
1428
|
+
}), await A.connect(t.entrypoints, { retry: t.retry });
|
|
1425
1429
|
}
|
|
1426
1430
|
self.addEventListener("message", (t) => {
|
|
1427
1431
|
const e = t.data;
|
|
1428
1432
|
if (e.type === "connect") {
|
|
1429
|
-
bt(e).catch((
|
|
1430
|
-
|
|
1433
|
+
bt(e).catch((r) => {
|
|
1434
|
+
st.error(`Failed to connect: ${r}`), B(r), Y();
|
|
1431
1435
|
});
|
|
1432
1436
|
return;
|
|
1433
1437
|
}
|
|
@@ -1439,10 +1443,10 @@ self.addEventListener("message", (t) => {
|
|
|
1439
1443
|
if (!A)
|
|
1440
1444
|
return;
|
|
1441
1445
|
try {
|
|
1442
|
-
const
|
|
1443
|
-
A.sendProtocolMessage(
|
|
1444
|
-
} catch (
|
|
1445
|
-
B(
|
|
1446
|
+
const r = new Uint8Array(e.message);
|
|
1447
|
+
A.sendProtocolMessage(r), u && u.postMessage({ direction: "sent", message: Array.from(r) });
|
|
1448
|
+
} catch (r) {
|
|
1449
|
+
B(r);
|
|
1446
1450
|
}
|
|
1447
1451
|
return;
|
|
1448
1452
|
}
|
|
@@ -1463,65 +1467,65 @@ self.addEventListener("message", (t) => {
|
|
|
1463
1467
|
e.port.start?.();
|
|
1464
1468
|
} catch {
|
|
1465
1469
|
}
|
|
1466
|
-
const
|
|
1467
|
-
U.push(e.portId), C.push({ port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }), v.set(e.portId,
|
|
1470
|
+
const r = U.length;
|
|
1471
|
+
U.push(e.portId), C.push({ port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }), v.set(e.portId, r);
|
|
1468
1472
|
return;
|
|
1469
1473
|
}
|
|
1470
1474
|
if (e.type === "detachPort") {
|
|
1471
|
-
const
|
|
1472
|
-
if (
|
|
1473
|
-
const
|
|
1475
|
+
const r = v.get(e.portId);
|
|
1476
|
+
if (r !== void 0) {
|
|
1477
|
+
const s = C[r];
|
|
1474
1478
|
try {
|
|
1475
|
-
|
|
1479
|
+
s.port.close();
|
|
1476
1480
|
} catch {
|
|
1477
1481
|
}
|
|
1478
1482
|
const i = U.length - 1;
|
|
1479
|
-
if (
|
|
1483
|
+
if (r !== i) {
|
|
1480
1484
|
const n = U[i];
|
|
1481
|
-
U[
|
|
1485
|
+
U[r] = n, C[r] = C[i], v.set(n, r);
|
|
1482
1486
|
}
|
|
1483
1487
|
U.length--, C.length--, v.delete(e.portId);
|
|
1484
1488
|
}
|
|
1485
1489
|
return;
|
|
1486
1490
|
}
|
|
1487
1491
|
if (e.type === "attachSendPort") {
|
|
1488
|
-
const
|
|
1489
|
-
if (
|
|
1490
|
-
const n = I[
|
|
1492
|
+
const r = S.get(e.portId);
|
|
1493
|
+
if (r !== void 0) {
|
|
1494
|
+
const n = I[r];
|
|
1491
1495
|
try {
|
|
1492
1496
|
n.port.close();
|
|
1493
1497
|
} catch {
|
|
1494
1498
|
}
|
|
1495
1499
|
const a = f.length - 1;
|
|
1496
|
-
if (
|
|
1500
|
+
if (r !== a) {
|
|
1497
1501
|
const o = f[a];
|
|
1498
|
-
f[
|
|
1502
|
+
f[r] = o, I[r] = I[a], S.set(o, r);
|
|
1499
1503
|
}
|
|
1500
1504
|
f.length--, I.length--, S.delete(e.portId);
|
|
1501
1505
|
}
|
|
1502
|
-
const
|
|
1503
|
-
f.push(e.portId), I.push(
|
|
1506
|
+
const s = { port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }, i = f.length;
|
|
1507
|
+
f.push(e.portId), I.push(s), S.set(e.portId, i);
|
|
1504
1508
|
try {
|
|
1505
|
-
|
|
1509
|
+
s.port.start?.();
|
|
1506
1510
|
} catch {
|
|
1507
1511
|
}
|
|
1508
|
-
|
|
1509
|
-
Pt(
|
|
1512
|
+
s.port.addEventListener("message", (n) => {
|
|
1513
|
+
Pt(s.opcodeGroupsMask, n.data);
|
|
1510
1514
|
});
|
|
1511
1515
|
return;
|
|
1512
1516
|
}
|
|
1513
1517
|
if (e.type === "detachSendPort") {
|
|
1514
|
-
const
|
|
1515
|
-
if (
|
|
1516
|
-
const
|
|
1518
|
+
const r = S.get(e.portId);
|
|
1519
|
+
if (r !== void 0) {
|
|
1520
|
+
const s = I[r];
|
|
1517
1521
|
try {
|
|
1518
|
-
|
|
1522
|
+
s.port.close();
|
|
1519
1523
|
} catch {
|
|
1520
1524
|
}
|
|
1521
1525
|
const i = f.length - 1;
|
|
1522
|
-
if (
|
|
1526
|
+
if (r !== i) {
|
|
1523
1527
|
const n = f[i];
|
|
1524
|
-
f[
|
|
1528
|
+
f[r] = n, I[r] = I[i], S.set(n, r);
|
|
1525
1529
|
}
|
|
1526
1530
|
f.length--, I.length--, S.delete(e.portId);
|
|
1527
1531
|
}
|