@ikonai/sdk 1.0.49 → 1.0.51

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.
@@ -1,122 +1,122 @@
1
- function j(t) {
1
+ function Q(t) {
2
2
  if (t.length < 8)
3
3
  throw new Error("Protocol message too short");
4
4
  return (t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24) >>> 0;
5
5
  }
6
- function v(t) {
7
- return j(t) & 4294901760;
6
+ function F(t) {
7
+ return Q(t) & 4294901760;
8
8
  }
9
9
  function H(t) {
10
- const e = It(t), n = new DataView(e.buffer, e.byteOffset, e.byteLength);
10
+ const e = ut(t), s = 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 r = n.getUint32(0, !0), s = n.getUint32(4, !0), i = n.getUint32(8, !0), o = n.getUint32(12, !0), a = n.getUint32(16, !0), E = n.getUint32(20, !0), _ = n.getUint8(24), l = n.getUint8(25), T = n.getUint8(26);
14
- if (27 + E * 4 > e.length)
13
+ const r = s.getUint32(0, !0), n = s.getUint32(4, !0), i = s.getUint32(8, !0), a = s.getUint32(12, !0), o = s.getUint32(16, !0), l = s.getUint32(20, !0), I = s.getUint8(24), E = s.getUint8(25), h = s.getUint8(26);
14
+ if (27 + l * 4 > e.length)
15
15
  throw new Error("Protocol header exceeds payload length");
16
16
  const c = [];
17
- let g = 27;
18
- for (let O = 0; O < E; O++)
19
- c.push(n.getUint32(g, !0)), g += 4;
17
+ let w = 27;
18
+ for (let g = 0; g < l; g++)
19
+ c.push(s.getUint32(w, !0)), w += 4;
20
20
  return {
21
21
  length: r,
22
- opcode: s,
22
+ opcode: n,
23
23
  senderId: i,
24
- trackId: o,
25
- sequenceId: a,
24
+ trackId: a,
25
+ sequenceId: o,
26
26
  targetIds: c,
27
- payloadVersion: _,
28
- payloadType: l,
29
- flags: T
27
+ payloadVersion: I,
28
+ payloadType: E,
29
+ flags: h
30
30
  };
31
31
  }
32
- function Et(t, e, n, r, s) {
33
- const E = [], l = 27 + E.length * 4, T = l + e.length, S = new Uint8Array(T), c = new DataView(S.buffer);
34
- c.setUint32(0, T, !0), c.setUint32(4, t >>> 0, !0), c.setUint32(8, r >>> 0, !0), c.setUint32(12, 0, !0), c.setUint32(16, 0, !0), c.setUint32(20, E.length >>> 0, !0), c.setUint8(24, n & 255), c.setUint8(25, 8), c.setUint8(26, 0);
35
- let g = 27;
36
- for (let O = 0; O < E.length; O++)
37
- c.setUint32(g, E[O] >>> 0, !0), g += 4;
38
- return S.set(e, l), S;
32
+ function Et(t, e, s, r, n) {
33
+ const l = [], E = 27 + l.length * 4, h = E + e.length, T = new Uint8Array(h), c = new DataView(T.buffer);
34
+ c.setUint32(0, h, !0), c.setUint32(4, t >>> 0, !0), c.setUint32(8, r >>> 0, !0), c.setUint32(12, 0, !0), c.setUint32(16, 0, !0), c.setUint32(20, l.length >>> 0, !0), c.setUint8(24, s & 255), c.setUint8(25, 8), c.setUint8(26, 0);
35
+ let w = 27;
36
+ for (let g = 0; g < l.length; g++)
37
+ c.setUint32(w, l[g] >>> 0, !0), w += 4;
38
+ return T.set(e, E), T;
39
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 lt = 161, ht = 162, W = new TextEncoder();
40
+ var D = /* @__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))(D || {});
41
+ const ht = 161, _t = 162, W = new TextEncoder();
42
42
  new TextDecoder("utf-8", { fatal: !0 });
43
43
  class G {
44
44
  constructor(e = 1) {
45
- this.version = e, this.buffer.writeByte(lt), this.buffer.writeVarUInt(e >>> 0);
45
+ this.version = e, this.buffer.writeByte(ht), this.buffer.writeVarUInt(e >>> 0);
46
46
  }
47
- buffer = new D();
47
+ buffer = new O();
48
48
  closed = !1;
49
49
  cached;
50
- writeInt32Field(e, n) {
51
- this.writeFixedField(e, 3, () => this.buffer.writeInt32(n | 0));
50
+ writeInt32Field(e, s) {
51
+ this.writeFixedField(e, 3, () => this.buffer.writeInt32(s | 0));
52
52
  }
53
- writeUInt32Field(e, n) {
54
- this.writeFixedField(e, 5, () => this.buffer.writeUInt32(n >>> 0));
53
+ writeUInt32Field(e, s) {
54
+ this.writeFixedField(e, 5, () => this.buffer.writeUInt32(s >>> 0));
55
55
  }
56
- writeInt64Field(e, n) {
57
- this.writeFixedField(e, 4, () => this.buffer.writeBigInt64(n));
56
+ writeInt64Field(e, s) {
57
+ this.writeFixedField(e, 4, () => this.buffer.writeBigInt64(s));
58
58
  }
59
- writeUInt64Field(e, n) {
60
- this.writeFixedField(e, 6, () => this.buffer.writeBigUInt64(n));
59
+ writeUInt64Field(e, s) {
60
+ this.writeFixedField(e, 6, () => this.buffer.writeBigUInt64(s));
61
61
  }
62
- writeFloat32Field(e, n) {
63
- this.writeFixedField(e, 7, () => this.buffer.writeFloat32(n));
62
+ writeFloat32Field(e, s) {
63
+ this.writeFixedField(e, 7, () => this.buffer.writeFloat32(s));
64
64
  }
65
- writeFloat64Field(e, n) {
66
- this.writeFixedField(e, 8, () => this.buffer.writeFloat64(n));
65
+ writeFloat64Field(e, s) {
66
+ this.writeFixedField(e, 8, () => this.buffer.writeFloat64(s));
67
67
  }
68
- writeBoolField(e, n) {
69
- this.writeFixedField(e, 2, () => this.buffer.writeByte(n ? 1 : 0));
68
+ writeBoolField(e, s) {
69
+ this.writeFixedField(e, 2, () => this.buffer.writeByte(s ? 1 : 0));
70
70
  }
71
- writeGuidField(e, n) {
72
- const r = n instanceof h ? n.asBytes() : n;
71
+ writeGuidField(e, s) {
72
+ const r = s instanceof _ ? s.asBytes() : s;
73
73
  if (r.length !== 16)
74
74
  throw new Error("Guid payload must be 16 bytes");
75
75
  this.writeFixedField(e, 14, () => this.buffer.writeBytes(r));
76
76
  }
77
- writeStringField(e, n) {
78
- const r = W.encode(n ?? "");
77
+ writeStringField(e, s) {
78
+ const r = W.encode(s ?? "");
79
79
  this.writeVariableField(e, 12, r);
80
80
  }
81
- writeBinaryField(e, n) {
82
- this.writeVariableField(e, 13, n);
81
+ writeBinaryField(e, s) {
82
+ this.writeVariableField(e, 13, s);
83
83
  }
84
- writeObjectField(e, n, r) {
85
- const s = new G(n);
86
- r(s);
87
- const i = s.finish();
84
+ writeObjectField(e, s, r) {
85
+ const n = new G(s);
86
+ r(n);
87
+ const i = n.finish();
88
88
  this.writeVariableField(e, 11, i);
89
89
  }
90
- writeArrayField(e, n, r) {
91
- const s = new Y(n);
92
- r(s);
93
- const i = s.finish();
90
+ writeArrayField(e, s, r) {
91
+ const n = new Y(s);
92
+ r(n);
93
+ const i = n.finish();
94
94
  this.writeVariableField(e, 9, i);
95
95
  }
96
- writeDictionaryField(e, n, r, s) {
97
- const i = new z(n, r);
98
- s(i);
99
- const o = i.finish();
100
- this.writeVariableField(e, 10, o);
96
+ writeDictionaryField(e, s, r, n) {
97
+ const i = new z(s, r);
98
+ n(i);
99
+ const a = i.finish();
100
+ this.writeVariableField(e, 10, a);
101
101
  }
102
102
  finish() {
103
- return this.closed || (this.buffer.writeByte(ht), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
103
+ return this.closed || (this.buffer.writeByte(_t), this.closed = !0, this.cached = this.buffer.toUint8Array()), this.cached;
104
104
  }
105
- writeFixedField(e, n, r) {
106
- this.writeFieldHeader(e, n, 0), r();
105
+ writeFixedField(e, s, r) {
106
+ this.writeFieldHeader(e, s, 0), r();
107
107
  }
108
- writeVariableField(e, n, r) {
109
- this.writeFieldHeader(e, n, r.length), this.buffer.writeBytes(r);
108
+ writeVariableField(e, s, r) {
109
+ this.writeFieldHeader(e, s, r.length), this.buffer.writeBytes(r);
110
110
  }
111
- writeFieldHeader(e, n, r) {
112
- this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(K(n)), Tt(n) && this.buffer.writeVarUInt(r >>> 0);
111
+ writeFieldHeader(e, s, r) {
112
+ this.buffer.writeUInt32(e >>> 0), this.buffer.writeByte(K(s)), ct(s) && this.buffer.writeVarUInt(r >>> 0);
113
113
  }
114
114
  }
115
115
  class Y {
116
116
  constructor(e) {
117
117
  this.elementType = e;
118
118
  }
119
- payload = new D();
119
+ payload = new O();
120
120
  count = 0;
121
121
  writeInt32(e) {
122
122
  this.ensureElementType(
@@ -165,18 +165,18 @@ class Y {
165
165
  14
166
166
  /* Guid */
167
167
  ), this.count++;
168
- const n = e instanceof h ? e.asBytes() : e;
169
- if (n.length !== 16)
168
+ const s = e instanceof _ ? e.asBytes() : e;
169
+ if (s.length !== 16)
170
170
  throw new Error("Guid payload must be 16 bytes");
171
- this.payload.writeBytes(n);
171
+ this.payload.writeBytes(s);
172
172
  }
173
173
  writeString(e) {
174
174
  this.ensureElementType(
175
175
  12
176
176
  /* String */
177
177
  ), this.count++;
178
- const n = W.encode(e ?? "");
179
- this.payload.writeVarUInt(n.length), this.payload.writeBytes(n);
178
+ const s = W.encode(e ?? "");
179
+ this.payload.writeVarUInt(s.length), this.payload.writeBytes(s);
180
180
  }
181
181
  writeBinary(e) {
182
182
  this.ensureElementType(
@@ -184,69 +184,69 @@ class Y {
184
184
  /* Binary */
185
185
  ), this.count++, this.payload.writeVarUInt(e.length), this.payload.writeBytes(e);
186
186
  }
187
- writeObject(e, n) {
187
+ writeObject(e, s) {
188
188
  this.ensureElementType(
189
189
  11
190
190
  /* Object */
191
191
  ), this.count++;
192
192
  const r = new G(e);
193
- n(r);
194
- const s = r.finish();
195
- this.payload.writeVarUInt(s.length), this.payload.writeBytes(s);
193
+ s(r);
194
+ const n = r.finish();
195
+ this.payload.writeVarUInt(n.length), this.payload.writeBytes(n);
196
196
  }
197
- writeArray(e, n) {
197
+ writeArray(e, s) {
198
198
  this.ensureElementType(
199
199
  9
200
200
  /* Array */
201
201
  ), this.count++;
202
202
  const r = new Y(e);
203
- n(r);
204
- const s = r.finish();
205
- this.payload.writeBytes(s);
203
+ s(r);
204
+ const n = r.finish();
205
+ this.payload.writeBytes(n);
206
206
  }
207
- writeDictionary(e, n, r) {
207
+ writeDictionary(e, s, r) {
208
208
  this.ensureElementType(
209
209
  10
210
210
  /* Dict */
211
211
  ), this.count++;
212
- const s = new z(e, n);
213
- r(s);
214
- const i = s.finish();
212
+ const n = new z(e, s);
213
+ r(n);
214
+ const i = n.finish();
215
215
  this.payload.writeBytes(i);
216
216
  }
217
217
  finish() {
218
- const e = new D();
218
+ const e = new O();
219
219
  return e.writeByte(K(this.elementType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
220
220
  }
221
221
  ensureElementType(e) {
222
222
  if (this.elementType !== e)
223
- throw new Error(`Array element type is ${m[this.elementType]}, expected ${m[e]}`);
223
+ throw new Error(`Array element type is ${D[this.elementType]}, expected ${D[e]}`);
224
224
  }
225
225
  }
226
226
  class z {
227
- constructor(e, n) {
228
- this.keyType = e, this.valueType = n, ct(e);
227
+ constructor(e, s) {
228
+ this.keyType = e, this.valueType = s, It(e);
229
229
  }
230
- payload = new D();
230
+ payload = new O();
231
231
  count = 0;
232
232
  entryOpen = !1;
233
233
  beginEntry() {
234
234
  if (this.entryOpen)
235
235
  throw new Error("Previous dictionary entry not completed");
236
- return this.count++, this.entryOpen = !0, new _t(this.keyType, this.valueType, this.payload, () => {
236
+ return this.count++, this.entryOpen = !0, new Tt(this.keyType, this.valueType, this.payload, () => {
237
237
  this.entryOpen = !1;
238
238
  });
239
239
  }
240
240
  finish() {
241
241
  if (this.entryOpen)
242
242
  throw new Error("Dictionary entry not completed");
243
- const e = new D();
243
+ const e = new O();
244
244
  return e.writeByte(K(this.keyType)), e.writeByte(K(this.valueType)), e.writeVarUInt(this.count), e.writeBytes(this.payload.toUint8Array()), e.toUint8Array();
245
245
  }
246
246
  }
247
- class _t {
248
- constructor(e, n, r, s) {
249
- this.keyType = e, this.valueType = n, this.payload = r, this.onComplete = s;
247
+ class Tt {
248
+ constructor(e, s, r, n) {
249
+ this.keyType = e, this.valueType = s, this.payload = r, this.onComplete = n;
250
250
  }
251
251
  keyWritten = !1;
252
252
  valueWritten = !1;
@@ -298,18 +298,18 @@ class _t {
298
298
  14
299
299
  /* Guid */
300
300
  );
301
- const n = e instanceof h ? e.asBytes() : e;
302
- if (n.length !== 16)
301
+ const s = e instanceof _ ? e.asBytes() : e;
302
+ if (s.length !== 16)
303
303
  throw new Error("Guid payload must be 16 bytes");
304
- this.payload.writeBytes(n), this.keyWritten = !0;
304
+ this.payload.writeBytes(s), this.keyWritten = !0;
305
305
  }
306
306
  writeKeyString(e) {
307
307
  this.ensureKeyType(
308
308
  12
309
309
  /* String */
310
310
  );
311
- const n = W.encode(e ?? "");
312
- this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.keyWritten = !0;
311
+ const s = W.encode(e ?? "");
312
+ this.payload.writeVarUInt(s.length), this.payload.writeBytes(s), this.keyWritten = !0;
313
313
  }
314
314
  writeKeyBinary(e) {
315
315
  this.ensureKeyType(
@@ -364,10 +364,10 @@ class _t {
364
364
  14
365
365
  /* Guid */
366
366
  );
367
- const n = e instanceof h ? e.asBytes() : e;
368
- if (n.length !== 16)
367
+ const s = e instanceof _ ? e.asBytes() : e;
368
+ if (s.length !== 16)
369
369
  throw new Error("Guid payload must be 16 bytes");
370
- this.payload.writeBytes(n), this.valueWritten = !0;
370
+ this.payload.writeBytes(s), this.valueWritten = !0;
371
371
  }
372
372
  writeNullValue() {
373
373
  this.ensureValueType(
@@ -386,37 +386,37 @@ class _t {
386
386
  12
387
387
  /* String */
388
388
  );
389
- const n = W.encode(e ?? "");
390
- this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.valueWritten = !0;
389
+ const s = W.encode(e ?? "");
390
+ this.payload.writeVarUInt(s.length), this.payload.writeBytes(s), this.valueWritten = !0;
391
391
  }
392
- writeValueObject(e, n) {
392
+ writeValueObject(e, s) {
393
393
  this.ensureValueType(
394
394
  11
395
395
  /* Object */
396
396
  );
397
397
  const r = new G(e);
398
- n(r);
399
- const s = r.finish();
400
- this.payload.writeVarUInt(s.length), this.payload.writeBytes(s), this.valueWritten = !0;
398
+ s(r);
399
+ const n = r.finish();
400
+ this.payload.writeVarUInt(n.length), this.payload.writeBytes(n), this.valueWritten = !0;
401
401
  }
402
- writeValueArray(e, n) {
402
+ writeValueArray(e, s) {
403
403
  this.ensureValueType(
404
404
  9
405
405
  /* Array */
406
406
  );
407
407
  const r = new Y(e);
408
- n(r);
409
- const s = r.finish();
410
- this.payload.writeBytes(s), this.valueWritten = !0;
408
+ s(r);
409
+ const n = r.finish();
410
+ this.payload.writeBytes(n), this.valueWritten = !0;
411
411
  }
412
- writeValueDictionary(e, n, r) {
412
+ writeValueDictionary(e, s, r) {
413
413
  this.ensureValueType(
414
414
  10
415
415
  /* Dict */
416
416
  );
417
- const s = new z(e, n);
418
- r(s);
419
- const i = s.finish();
417
+ const n = new z(e, s);
418
+ r(n);
419
+ const i = n.finish();
420
420
  this.payload.writeBytes(i), this.valueWritten = !0;
421
421
  }
422
422
  complete() {
@@ -428,52 +428,52 @@ class _t {
428
428
  }
429
429
  ensureKeyType(e) {
430
430
  if (this.keyType !== e)
431
- throw new Error(`Dictionary key type is ${m[this.keyType]}, expected ${m[e]}`);
431
+ throw new Error(`Dictionary key type is ${D[this.keyType]}, expected ${D[e]}`);
432
432
  }
433
433
  ensureValueType(e) {
434
434
  if (this.valueType !== e)
435
- throw new Error(`Dictionary value type is ${m[this.valueType]}, expected ${m[e]}`);
435
+ throw new Error(`Dictionary value type is ${D[this.valueType]}, expected ${D[e]}`);
436
436
  }
437
437
  }
438
- class h {
438
+ class _ {
439
439
  constructor(e) {
440
440
  this.bytes = e;
441
441
  }
442
442
  static fromString(e) {
443
443
  if (!e)
444
444
  throw new Error("Guid string is empty");
445
- const n = e.replace(/-/g, "");
446
- if (n.length !== 32)
445
+ const s = e.replace(/-/g, "");
446
+ if (s.length !== 32)
447
447
  throw new Error("Guid string must be 32 hex characters");
448
- const r = new Uint8Array(16), s = h.parseHexSlice(n, 0, 8), i = h.parseHexSlice(n, 8, 4), o = h.parseHexSlice(n, 12, 4);
449
- h.writeUInt32LE(r, 0, s), h.writeUInt16LE(r, 4, i), h.writeUInt16LE(r, 6, o);
450
- for (let a = 0; a < 8; a++)
451
- r[8 + a] = h.parseHexSlice(n, 16 + a * 2, 2);
452
- return new h(r);
448
+ const r = new Uint8Array(16), n = _.parseHexSlice(s, 0, 8), i = _.parseHexSlice(s, 8, 4), a = _.parseHexSlice(s, 12, 4);
449
+ _.writeUInt32LE(r, 0, n), _.writeUInt16LE(r, 4, i), _.writeUInt16LE(r, 6, a);
450
+ for (let o = 0; o < 8; o++)
451
+ r[8 + o] = _.parseHexSlice(s, 16 + o * 2, 2);
452
+ return new _(r);
453
453
  }
454
454
  static fromBytes(e) {
455
455
  if (e.length !== 16)
456
456
  throw new Error("Guid byte array must be 16 bytes");
457
- return new h(Uint8Array.from(e));
457
+ return new _(Uint8Array.from(e));
458
458
  }
459
459
  static createZero() {
460
- return new h(new Uint8Array(16));
460
+ return new _(new Uint8Array(16));
461
461
  }
462
462
  static createRandom() {
463
- const e = new Uint8Array(16), n = globalThis.crypto;
464
- if (n?.getRandomValues)
465
- n.getRandomValues(e);
463
+ const e = new Uint8Array(16), s = globalThis.crypto;
464
+ if (s?.getRandomValues)
465
+ s.getRandomValues(e);
466
466
  else
467
467
  for (let r = 0; r < e.length; r++)
468
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);
469
+ return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, new _(e);
470
470
  }
471
471
  toString() {
472
472
  const e = this.bytes;
473
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),
474
+ _.toHex(_.readUInt32LE(e, 0), 8),
475
+ _.toHex(_.readUInt16LE(e, 4), 4),
476
+ _.toHex(_.readUInt16LE(e, 6), 4),
477
477
  J(e.subarray(8, 10)),
478
478
  J(e.subarray(10, 16))
479
479
  ].join("-");
@@ -481,47 +481,47 @@ class h {
481
481
  asBytes() {
482
482
  return this.bytes.slice();
483
483
  }
484
- static parseHexSlice(e, n, r) {
485
- const s = e.substr(n, r), i = Number.parseInt(s, 16);
484
+ static parseHexSlice(e, s, r) {
485
+ const n = e.substr(s, r), i = Number.parseInt(n, 16);
486
486
  if (Number.isNaN(i))
487
487
  throw new Error("Guid string contains invalid characters");
488
488
  return i >>> 0;
489
489
  }
490
- static writeUInt32LE(e, n, r) {
491
- const s = r >>> 0;
492
- e[n] = s & 255, e[n + 1] = s >>> 8 & 255, e[n + 2] = s >>> 16 & 255, e[n + 3] = s >>> 24 & 255;
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
493
  }
494
- static writeUInt16LE(e, n, r) {
495
- const s = r & 65535;
496
- e[n] = s & 255, e[n + 1] = s >>> 8 & 255;
494
+ static writeUInt16LE(e, s, r) {
495
+ const n = r & 65535;
496
+ e[s] = n & 255, e[s + 1] = n >>> 8 & 255;
497
497
  }
498
- static readUInt32LE(e, n) {
499
- return (e[n] | e[n + 1] << 8 | e[n + 2] << 16 | e[n + 3] << 24) >>> 0;
498
+ static readUInt32LE(e, s) {
499
+ return (e[s] | e[s + 1] << 8 | e[s + 2] << 16 | e[s + 3] << 24) >>> 0;
500
500
  }
501
- static readUInt16LE(e, n) {
502
- return (e[n] | e[n + 1] << 8) & 65535;
501
+ static readUInt16LE(e, s) {
502
+ return (e[s] | e[s + 1] << 8) & 65535;
503
503
  }
504
- static toHex(e, n) {
505
- return (e >>> 0).toString(16).padStart(n, "0");
504
+ static toHex(e, s) {
505
+ return (e >>> 0).toString(16).padStart(s, "0");
506
506
  }
507
507
  }
508
- class D {
508
+ class O {
509
509
  static INITIAL_CAPACITY = 256;
510
510
  buffer;
511
511
  dataView;
512
512
  length = 0;
513
513
  constructor() {
514
- this.buffer = new Uint8Array(D.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
514
+ this.buffer = new Uint8Array(O.INITIAL_CAPACITY), this.dataView = new DataView(this.buffer.buffer);
515
515
  }
516
516
  ensureCapacity(e) {
517
- const n = this.length + e;
518
- if (n <= this.buffer.length)
517
+ const s = this.length + e;
518
+ if (s <= this.buffer.length)
519
519
  return;
520
520
  let r = this.buffer.length;
521
- for (; r < n; )
521
+ for (; r < s; )
522
522
  r *= 2;
523
- const s = new Uint8Array(r);
524
- s.set(this.buffer.subarray(0, this.length)), this.buffer = s, this.dataView = new DataView(this.buffer.buffer);
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
525
  }
526
526
  writeByte(e) {
527
527
  this.ensureCapacity(1), this.buffer[this.length++] = e & 255;
@@ -548,10 +548,10 @@ class D {
548
548
  this.ensureCapacity(8), this.dataView.setBigUint64(this.length, e, !0), this.length += 8;
549
549
  }
550
550
  writeVarUInt(e) {
551
- let n = e >>> 0;
552
- for (; n >= 128; )
553
- this.ensureCapacity(1), this.buffer[this.length++] = n & 127 | 128, n >>>= 7;
554
- this.ensureCapacity(1), this.buffer[this.length++] = n & 127;
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
555
  }
556
556
  toUint8Array() {
557
557
  return this.buffer.slice(0, this.length);
@@ -562,67 +562,71 @@ function K(t, e = 0) {
562
562
  throw new Error("Teleport flags must fit into 4 bits");
563
563
  return (t & 15) << 4 | e & 15;
564
564
  }
565
- function Tt(t) {
565
+ function ct(t) {
566
566
  return t === 12 || t === 13 || t === 9 || t === 11 || t === 10;
567
567
  }
568
- function ct(t) {
568
+ function It(t) {
569
569
  if (t === 9 || t === 11 || t === 10 || t === 1)
570
570
  throw new Error("Dictionary keys must be primitive Teleport types");
571
571
  }
572
572
  function J(t) {
573
573
  return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
574
574
  }
575
- function It(t) {
575
+ function ut(t) {
576
576
  return t instanceof Uint8Array ? t : new Uint8Array(t);
577
577
  }
578
578
  var N = /* @__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))(N || {}), V = /* @__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_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.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.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))(V || {});
579
579
  const et = 1, At = 131074;
580
- function nt(t) {
580
+ function st(t) {
581
581
  return {};
582
582
  }
583
- function ut(t) {
583
+ function ft(t) {
584
584
  return new G(et).finish();
585
585
  }
586
- function rt(t, e, n) {
587
- const r = ut();
586
+ function rt(t, e, s) {
587
+ const r = ft();
588
588
  return Et(At, r, et, e);
589
589
  }
590
- class st extends Error {
591
- constructor(e, n) {
592
- super(e), this.cause = n, this.name = "ConnectionError";
590
+ class nt extends Error {
591
+ constructor(e, s) {
592
+ super(e), this.cause = s, this.name = "ConnectionError";
593
593
  }
594
594
  }
595
- class y extends st {
596
- constructor(e, n) {
597
- super(e, n), this.name = "TransportError";
595
+ class U extends nt {
596
+ constructor(e, s) {
597
+ super(e, s), this.name = "TransportError";
598
598
  }
599
599
  }
600
- class q extends y {
600
+ class q extends U {
601
601
  constructor(e) {
602
602
  super(`No keepalive received within ${e}ms`), this.name = "KeepaliveTimeoutError";
603
603
  }
604
604
  }
605
- class Z extends st {
605
+ class Z extends nt {
606
606
  constructor(e) {
607
607
  super(`Maximum reconnection attempts (${e}) exceeded`), this.name = "MaxRetriesExceededError";
608
608
  }
609
609
  }
610
610
  function Ct(t, e) {
611
- return new Promise((n, r) => {
612
- const s = () => {
611
+ return new Promise((s, r) => {
612
+ const n = () => {
613
613
  clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
614
614
  }, i = setTimeout(() => {
615
- e?.removeEventListener("abort", s), n();
615
+ e?.removeEventListener("abort", n), s();
616
616
  }, t);
617
617
  if (e?.aborted) {
618
618
  clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
619
619
  return;
620
620
  }
621
- e?.addEventListener("abort", s, { once: !0 });
621
+ e?.addEventListener("abort", n, { once: !0 });
622
622
  });
623
623
  }
624
- let Nt = 1;
625
- const ft = /* @__PURE__ */ new Map(), Rt = {
624
+ let it = 1;
625
+ const Nt = /* @__PURE__ */ new Map();
626
+ function Rt(t) {
627
+ it = t;
628
+ }
629
+ const yt = {
626
630
  0: "DEBUG",
627
631
  1: "INFO",
628
632
  2: "WARN",
@@ -632,127 +636,137 @@ const ft = /* @__PURE__ */ new Map(), Rt = {
632
636
  function Ut(t, e) {
633
637
  return `[${t}] ${e}`;
634
638
  }
635
- function k(t, e, n, r) {
636
- const s = (/* @__PURE__ */ new Date()).toISOString(), i = Rt[t], o = {
637
- timestamp: s,
639
+ function k(t, e, s, r) {
640
+ const n = (/* @__PURE__ */ new Date()).toISOString(), i = yt[t], a = {
641
+ timestamp: n,
638
642
  level: t,
639
643
  levelName: i,
640
644
  component: e,
641
- message: n,
645
+ message: s,
642
646
  args: r
643
647
  };
644
- for (const [a, E] of ft) {
645
- const _ = E?.minLevel ?? 2;
646
- if (t >= _)
648
+ for (const [o, l] of Nt) {
649
+ const I = l?.minLevel ?? 2;
650
+ if (t >= I)
647
651
  try {
648
- a(o);
652
+ o(a);
649
653
  } catch {
650
654
  }
651
655
  }
652
- if (Nt <= t) {
653
- const a = Ut(e, n);
656
+ if (it <= t) {
657
+ const o = Ut(e, s);
654
658
  switch (t) {
655
659
  case 0:
656
- console.debug(a, ...r);
660
+ console.debug(o, ...r);
657
661
  break;
658
662
  case 1:
659
- console.info(a, ...r);
663
+ console.info(o, ...r);
660
664
  break;
661
665
  case 2:
662
- console.warn(a, ...r);
666
+ console.warn(o, ...r);
663
667
  break;
664
668
  case 3:
665
- console.error(a, ...r);
669
+ console.error(o, ...r);
666
670
  break;
667
671
  }
668
672
  }
669
673
  }
670
674
  function p(t) {
671
675
  return {
672
- debug(e, ...n) {
673
- k(0, t, e, n);
676
+ debug(e, ...s) {
677
+ k(0, t, e, s);
674
678
  },
675
- info(e, ...n) {
676
- k(1, t, e, n);
679
+ info(e, ...s) {
680
+ k(1, t, e, s);
677
681
  },
678
- warn(e, ...n) {
679
- k(2, t, e, n);
682
+ warn(e, ...s) {
683
+ k(2, t, e, s);
680
684
  },
681
- error(e, ...n) {
682
- k(3, t, e, n);
685
+ error(e, ...s) {
686
+ k(3, t, e, s);
683
687
  }
684
688
  };
685
689
  }
686
- const yt = "ikon-retry";
687
- function St(t, e) {
690
+ const St = "ikon-retry";
691
+ function wt(t, e) {
688
692
  if (typeof window > "u")
689
693
  return null;
690
- const n = new URLSearchParams(window.location.search), r = n.get(t);
694
+ const s = new URLSearchParams(window.location.search), r = s.get(t);
691
695
  if (r !== null)
692
696
  return r;
693
- const s = n.get(t.replace(/-/g, "_"));
694
- return s !== null ? s : null;
697
+ const n = s.get(t.replace(/-/g, "_"));
698
+ return n !== null ? n : null;
695
699
  }
696
- function wt(t, e) {
697
- const n = St(t);
698
- return n === "true" ? !0 : n === "false" ? !1 : null;
700
+ function gt(t, e) {
701
+ const s = wt(t);
702
+ return s === "true" ? !0 : s === "false" ? !1 : null;
699
703
  }
700
704
  function Lt() {
701
- return wt(yt) !== !1;
705
+ return gt(St) !== !1;
702
706
  }
703
- const b = p("WebSocketTransport"), gt = 1e4;
704
- class Pt {
707
+ const M = p("WebSocketTransport"), Pt = 1e4;
708
+ class mt {
705
709
  ws = null;
706
710
  keepaliveTimeout = null;
707
711
  isClosed = !1;
708
712
  // Pre-allocated keepalive response message to avoid allocation per keepalive
709
713
  keepaliveResponseMessage = null;
714
+ // Released on the first server-originated message; gates connect() resolution.
715
+ // null once connect() has settled (success or failure) — see connect()/handleProtocolMessage.
716
+ firstMessageResolver = null;
710
717
  keepaliveTimeoutMs;
711
718
  connectionTimeoutMs;
712
719
  callbacks;
713
720
  sessionId;
714
721
  constructor(e) {
715
- this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? gt;
722
+ this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? Pt;
716
723
  }
717
724
  get isConnected() {
718
725
  return this.ws?.readyState === WebSocket.OPEN;
719
726
  }
720
- async connect(e, n) {
727
+ async connect(e, s) {
721
728
  this.isClosed = !1;
722
729
  const r = Date.now();
723
- return new Promise((s, i) => {
730
+ return new Promise((n, i) => {
724
731
  try {
725
732
  this.ws = new WebSocket(e), this.ws.binaryType = "arraybuffer";
726
- } catch (l) {
727
- i(new y(`Failed to create WebSocket: ${l}`, l instanceof Error ? l : void 0));
733
+ } catch (T) {
734
+ i(new U(`Failed to create WebSocket: ${T}`, T instanceof Error ? T : void 0));
728
735
  return;
729
736
  }
730
- let o = !1, a = !1;
731
- const E = () => {
732
- clearTimeout(_), this.ws && (this.ws.onopen = null, this.ws.onerror = null, this.ws.onclose = null, this.ws.onmessage = null);
733
- }, _ = setTimeout(() => {
734
- a || (a = !0, E(), this.ws?.close(), b.warn(`WebSocket connection timeout after ${this.connectionTimeoutMs}ms`), i(new y("WebSocket connection timeout")));
737
+ let a = !1, o = !1;
738
+ const l = () => {
739
+ clearTimeout(h), this.ws && (this.ws.onopen = null, this.ws.onerror = null, this.ws.onclose = null, this.ws.onmessage = null);
740
+ }, I = () => {
741
+ o || (o = !0, clearTimeout(h), this.firstMessageResolver = null, M.debug(`WebSocket connected in ${Date.now() - r}ms`), n());
742
+ }, E = (T) => {
743
+ o || (o = !0, this.firstMessageResolver = null, l(), i(T));
744
+ };
745
+ this.firstMessageResolver = I;
746
+ const h = setTimeout(() => {
747
+ this.ws?.close(), M.warn(`WebSocket connection timeout after ${this.connectionTimeoutMs}ms`), E(new U("WebSocket connection timeout"));
735
748
  }, this.connectionTimeoutMs);
736
749
  this.ws.onopen = () => {
737
- o = !0, clearTimeout(_), this.ws.send(n), this.resetKeepaliveTimeout(), a || (a = !0, b.info(`WebSocket connected in ${Date.now() - r}ms`), s());
750
+ a = !0, this.ws.send(s), this.resetKeepaliveTimeout();
738
751
  }, this.ws.onerror = () => {
739
- clearTimeout(_), a || (a = !0, E(), b.debug(`WebSocket connection failed after ${Date.now() - r}ms`), i(new y("WebSocket connection failed")));
740
- }, this.ws.onclose = (l) => {
741
- if (this.clearKeepaliveTimeout(), !o && !a) {
742
- a = !0, E(), i(new y("WebSocket connection closed before opening"));
752
+ M.debug(`WebSocket connection failed after ${Date.now() - r}ms`), E(new U("WebSocket connection failed"));
753
+ }, this.ws.onclose = (T) => {
754
+ if (this.clearKeepaliveTimeout(), !o) {
755
+ const g = a ? "WebSocket closed before first server message" : "WebSocket connection closed before opening";
756
+ E(new U(g));
743
757
  return;
744
758
  }
745
759
  if (this.isClosed)
746
760
  return;
747
- const T = l.wasClean && (l.code === 1e3 || l.code === 1001), S = l.reason || `code=${l.code}`;
748
- this.callbacks.onClose(S, T);
749
- }, this.ws.onmessage = (l) => {
750
- this.handleProtocolMessage(new Uint8Array(l.data));
761
+ const c = T.wasClean && (T.code === 1e3 || T.code === 1001), w = T.reason || `code=${T.code}`;
762
+ this.callbacks.onClose(w, c);
763
+ }, this.ws.onmessage = (T) => {
764
+ this.handleProtocolMessage(new Uint8Array(T.data));
751
765
  };
752
766
  });
753
767
  }
754
768
  send(e) {
755
- this.ws?.readyState === WebSocket.OPEN ? this.ws.send(e) : b.warn("Cannot send: WebSocket not connected");
769
+ this.ws?.readyState === WebSocket.OPEN ? this.ws.send(e) : M.warn("Cannot send: WebSocket not connected");
756
770
  }
757
771
  close() {
758
772
  this.isClosed = !0, this.clearKeepaliveTimeout(), this.ws && (this.ws.close(1e3, "Client closing"), this.ws = null);
@@ -761,33 +775,34 @@ class Pt {
761
775
  * Get or create a cached keepalive response message.
762
776
  */
763
777
  getKeepaliveResponse() {
764
- return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = rt(nt(), this.sessionId)), this.keepaliveResponseMessage;
778
+ return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = rt(st(), this.sessionId)), this.keepaliveResponseMessage;
765
779
  }
766
780
  handleProtocolMessage(e) {
767
781
  try {
768
- if (H(e).opcode === V.KEEPALIVE_REQUEST) {
782
+ const r = H(e).opcode;
783
+ if (this.firstMessageResolver && this.firstMessageResolver(), r === V.KEEPALIVE_REQUEST) {
769
784
  this.send(this.getKeepaliveResponse()), this.resetKeepaliveTimeout();
770
785
  return;
771
786
  }
772
787
  this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
773
- } catch (n) {
774
- b.error("Failed to process protocol message:", n), this.callbacks.onError(n instanceof Error ? n : new Error(String(n)));
788
+ } catch (s) {
789
+ M.error("Failed to process protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
775
790
  }
776
791
  }
777
792
  resetKeepaliveTimeout() {
778
793
  this.clearKeepaliveTimeout(), this.keepaliveTimeout = setTimeout(() => {
779
- b.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
794
+ M.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
780
795
  }, this.keepaliveTimeoutMs);
781
796
  }
782
797
  clearKeepaliveTimeout() {
783
798
  this.keepaliveTimeout && (clearTimeout(this.keepaliveTimeout), this.keepaliveTimeout = null);
784
799
  }
785
800
  }
786
- const U = p("WebTransportTransport"), mt = 1e4, tt = 4, Dt = 65536;
787
- function it() {
801
+ const S = p("WebTransportTransport"), Dt = 1e4, tt = 4, Ot = 65536;
802
+ function at() {
788
803
  return typeof WebTransport < "u";
789
804
  }
790
- class Ot {
805
+ class Mt {
791
806
  transport = null;
792
807
  stream = null;
793
808
  reader = null;
@@ -796,7 +811,7 @@ class Ot {
796
811
  readLoopActive = !1;
797
812
  isClosed = !1;
798
813
  // Grow-only receive buffer with offset/length tracking to minimize allocations
799
- receiveBuffer = new Uint8Array(Dt);
814
+ receiveBuffer = new Uint8Array(Ot);
800
815
  receiveBufferOffset = 0;
801
816
  receiveBufferLength = 0;
802
817
  // Cached DataView to avoid allocation per message
@@ -804,53 +819,75 @@ class Ot {
804
819
  receiveDataViewBuffer = null;
805
820
  // Pre-allocated keepalive response message
806
821
  keepaliveResponseMessage = null;
822
+ // Released on the first server-originated message; gates connect() resolution.
823
+ // Both are nulled once connect() has settled — see connect()/handleProtocolMessage/handleClose.
824
+ firstMessageResolver = null;
825
+ firstMessageRejecter = null;
807
826
  keepaliveTimeoutMs;
808
827
  connectionTimeoutMs;
809
828
  callbacks;
810
829
  sessionId;
811
830
  constructor(e) {
812
- this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? mt;
831
+ this.callbacks = e.callbacks, this.sessionId = e.sessionId, this.keepaliveTimeoutMs = e.keepaliveTimeoutMs, this.connectionTimeoutMs = e.connectionTimeoutMs ?? Dt;
813
832
  }
814
833
  get isConnected() {
815
834
  return this.transport !== null && this.writer !== null;
816
835
  }
817
- async connect(e, n) {
818
- if (!it())
819
- throw new y("WebTransport is not supported in this browser");
836
+ async connect(e, s) {
837
+ if (!at())
838
+ throw new U("WebTransport is not supported in this browser");
820
839
  this.isClosed = !1;
821
- const r = Date.now();
840
+ const r = Date.now(), n = new Promise((i, a) => {
841
+ this.firstMessageResolver = i, this.firstMessageRejecter = a;
842
+ });
822
843
  try {
823
844
  this.transport = new WebTransport(e);
824
- let s;
825
- const i = new Promise((o, a) => {
826
- s = setTimeout(
827
- () => a(new y("WebTransport connection timeout")),
845
+ let i;
846
+ const a = new Promise((E, h) => {
847
+ i = setTimeout(
848
+ () => h(new U("WebTransport connection timeout")),
828
849
  this.connectionTimeoutMs
829
850
  );
830
851
  });
831
852
  try {
832
- await Promise.race([this.transport.ready, i]), clearTimeout(s);
833
- } catch (o) {
834
- throw clearTimeout(s), o instanceof y && U.warn(`WebTransport connection timeout after ${this.connectionTimeoutMs}ms`), o;
853
+ await Promise.race([this.transport.ready, a]);
854
+ } catch (E) {
855
+ throw E instanceof U && S.warn(`WebTransport connection timeout after ${this.connectionTimeoutMs}ms`), E;
856
+ } finally {
857
+ clearTimeout(i);
835
858
  }
836
- U.info(`WebTransport connected in ${Date.now() - r}ms`), this.transport.closed.then(() => {
859
+ this.transport.closed.then(() => {
837
860
  this.handleClose("Connection closed", !0);
838
- }).catch((o) => {
839
- U.error("WebTransport connection closed with error:", o), this.handleClose(o.message || "Connection error", !1);
840
- }), this.stream = await this.transport.createBidirectionalStream(), this.reader = this.stream.readable.getReader(), this.writer = this.stream.writable.getWriter(), await this.writer.write(n), this.resetKeepaliveTimeout(), this.startReadLoop();
841
- } catch (s) {
842
- this.cleanup();
843
- const i = Date.now() - r;
844
- throw U.warn(`WebTransport connection failed after ${i}ms: ${s}`), new y(`Failed to connect WebTransport: ${s}`, s instanceof Error ? s : void 0);
861
+ }).catch((E) => {
862
+ S.error("WebTransport connection closed with error:", E), this.handleClose(E.message || "Connection error", !1);
863
+ }), 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();
864
+ const o = Math.max(this.connectionTimeoutMs - (Date.now() - r), 1);
865
+ let l;
866
+ const I = new Promise((E, h) => {
867
+ l = setTimeout(
868
+ () => h(new U("WebTransport closed before first server message")),
869
+ o
870
+ );
871
+ });
872
+ try {
873
+ await Promise.race([n, I]);
874
+ } finally {
875
+ clearTimeout(l);
876
+ }
877
+ this.firstMessageResolver = null, this.firstMessageRejecter = null, S.info(`WebTransport connected in ${Date.now() - r}ms`);
878
+ } catch (i) {
879
+ this.firstMessageResolver = null, this.firstMessageRejecter = null, this.cleanup();
880
+ const a = Date.now() - r;
881
+ throw S.warn(`WebTransport connection failed after ${a}ms: ${i}`), new U(`Failed to connect WebTransport: ${i}`, i instanceof Error ? i : void 0);
845
882
  }
846
883
  }
847
884
  send(e) {
848
885
  if (!this.writer) {
849
- U.warn("Cannot send: WebTransport not connected");
886
+ S.warn("Cannot send: WebTransport not connected");
850
887
  return;
851
888
  }
852
- this.writer.write(e).catch((n) => {
853
- U.error("Failed to send protocol message:", n), this.callbacks.onError(n instanceof Error ? n : new Error(String(n)));
889
+ this.writer.write(e).catch((s) => {
890
+ S.error("Failed to send protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
854
891
  });
855
892
  }
856
893
  close() {
@@ -864,14 +901,14 @@ class Ot {
864
901
  this.readLoopActive = !0;
865
902
  try {
866
903
  for (; this.readLoopActive && this.reader; ) {
867
- const { value: e, done: n } = await this.reader.read();
868
- if (n)
904
+ const { value: e, done: s } = await this.reader.read();
905
+ if (s)
869
906
  break;
870
907
  e && (this.appendToBuffer(e), this.processBufferedMessages());
871
908
  }
872
909
  this.readLoopActive && this.handleClose("Stream ended", !1);
873
910
  } catch (e) {
874
- this.readLoopActive && (U.error("Read loop error:", e), this.callbacks.onError(e instanceof Error ? e : new Error(String(e))));
911
+ this.readLoopActive && (S.error("Read loop error:", e), this.callbacks.onError(e instanceof Error ? e : new Error(String(e))));
875
912
  }
876
913
  }
877
914
  }
@@ -880,10 +917,10 @@ class Ot {
880
917
  * Compacts when offset exceeds half capacity and data is sparse.
881
918
  */
882
919
  appendToBuffer(e) {
883
- const n = this.receiveBufferLength + e.length, r = this.receiveBufferOffset + this.receiveBufferLength;
920
+ const s = this.receiveBufferLength + e.length, r = this.receiveBufferOffset + this.receiveBufferLength;
884
921
  if (r + e.length > this.receiveBuffer.length)
885
- if (n > this.receiveBuffer.length) {
886
- const s = Math.max(n, this.receiveBuffer.length * 2), i = new Uint8Array(s);
922
+ if (s > this.receiveBuffer.length) {
923
+ const n = Math.max(s, this.receiveBuffer.length * 2), i = new Uint8Array(n);
887
924
  i.set(this.receiveBuffer.subarray(this.receiveBufferOffset, r)), this.receiveBuffer = i, this.receiveBufferOffset = 0, this.receiveDataViewBuffer = null;
888
925
  } else
889
926
  this.receiveBuffer.copyWithin(0, this.receiveBufferOffset, r), this.receiveBufferOffset = 0;
@@ -900,7 +937,7 @@ class Ot {
900
937
  * Get or create a cached keepalive response message.
901
938
  */
902
939
  getKeepaliveResponse() {
903
- return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = rt(nt(), this.sessionId)), this.keepaliveResponseMessage;
940
+ return this.keepaliveResponseMessage || (this.keepaliveResponseMessage = rt(st(), this.sessionId)), this.keepaliveResponseMessage;
904
941
  }
905
942
  /**
906
943
  * Process complete messages from the receive buffer.
@@ -910,15 +947,15 @@ class Ot {
910
947
  processBufferedMessages() {
911
948
  const e = this.getReceiveDataView();
912
949
  for (; this.receiveBufferLength >= tt; ) {
913
- const n = e.getUint32(this.receiveBufferOffset, !0);
914
- if (n < tt) {
915
- U.error(`Invalid message length: ${n}`), this.callbacks.onError(new Error(`Invalid protocol message length: ${n}`)), this.receiveBufferOffset = 0, this.receiveBufferLength = 0;
950
+ const s = e.getUint32(this.receiveBufferOffset, !0);
951
+ if (s < tt) {
952
+ S.error(`Invalid message length: ${s}`), this.callbacks.onError(new Error(`Invalid protocol message length: ${s}`)), this.receiveBufferOffset = 0, this.receiveBufferLength = 0;
916
953
  return;
917
954
  }
918
- if (this.receiveBufferLength < n)
955
+ if (this.receiveBufferLength < s)
919
956
  return;
920
- const r = this.receiveBuffer.subarray(this.receiveBufferOffset, this.receiveBufferOffset + n);
921
- this.receiveBufferOffset += n, this.receiveBufferLength -= n, this.handleProtocolMessage(r);
957
+ const r = this.receiveBuffer.subarray(this.receiveBufferOffset, this.receiveBufferOffset + s);
958
+ this.receiveBufferOffset += s, this.receiveBufferLength -= s, this.handleProtocolMessage(r);
922
959
  }
923
960
  this.receiveBufferLength === 0 && (this.receiveBufferOffset = 0);
924
961
  }
@@ -927,27 +964,34 @@ class Ot {
927
964
  */
928
965
  handleProtocolMessage(e) {
929
966
  try {
930
- if (H(e).opcode === V.KEEPALIVE_REQUEST) {
967
+ const r = H(e).opcode;
968
+ if (this.firstMessageResolver && this.firstMessageResolver(), r === V.KEEPALIVE_REQUEST) {
931
969
  this.send(this.getKeepaliveResponse()), this.resetKeepaliveTimeout();
932
970
  return;
933
971
  }
934
972
  this.resetKeepaliveTimeout(), this.callbacks.onProtocolMessage(e);
935
- } catch (n) {
936
- U.error("Failed to process protocol message:", n), this.callbacks.onError(n instanceof Error ? n : new Error(String(n)));
973
+ } catch (s) {
974
+ S.error("Failed to process protocol message:", s), this.callbacks.onError(s instanceof Error ? s : new Error(String(s)));
937
975
  }
938
976
  }
939
977
  /**
940
978
  * Handle connection close.
941
979
  */
942
- handleClose(e, n) {
943
- this.isClosed || (this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup(), this.callbacks.onClose(e, n));
980
+ handleClose(e, s) {
981
+ if (!this.isClosed) {
982
+ if (this.isClosed = !0, this.clearKeepaliveTimeout(), this.readLoopActive = !1, this.cleanup(), this.firstMessageRejecter) {
983
+ this.firstMessageRejecter(new U(`WebTransport closed before first server message: ${e}`)), this.firstMessageResolver = null, this.firstMessageRejecter = null;
984
+ return;
985
+ }
986
+ this.callbacks.onClose(e, s);
987
+ }
944
988
  }
945
989
  /**
946
990
  * Reset the keepalive timeout.
947
991
  */
948
992
  resetKeepaliveTimeout() {
949
993
  this.clearKeepaliveTimeout(), this.keepaliveTimeout = setTimeout(() => {
950
- U.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
994
+ S.error(`No keepalive received in ${this.keepaliveTimeoutMs}ms, closing connection`), this.callbacks.onError(new q(this.keepaliveTimeoutMs)), this.close();
951
995
  }, this.keepaliveTimeoutMs);
952
996
  }
953
997
  /**
@@ -1051,26 +1095,26 @@ class bt {
1051
1095
  * Connect the transport to the entrypoint.
1052
1096
  */
1053
1097
  async connectTransport() {
1054
- const e = this.entrypoint, n = {
1098
+ const e = this.entrypoint, s = {
1055
1099
  sessionId: this.config.sessionId,
1056
1100
  keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
1057
1101
  connectionTimeoutMs: this.config.connectionTimeoutMs,
1058
1102
  callbacks: {
1059
1103
  onProtocolMessage: (r) => this.handleProtocolMessage(r),
1060
- onClose: (r, s) => this.handleClose(r, s),
1104
+ onClose: (r, n) => this.handleClose(r, n),
1061
1105
  onError: (r) => this.handleError(r)
1062
1106
  }
1063
1107
  };
1064
1108
  switch (e.Type) {
1065
1109
  case N.WebSocket:
1066
1110
  case N.WebSocketProxy:
1067
- this.transport = new Pt(n);
1111
+ this.transport = new mt(s);
1068
1112
  break;
1069
1113
  case N.WebTransport:
1070
1114
  case N.WebTransportProxy:
1071
- if (!it())
1115
+ if (!at())
1072
1116
  throw new Error("WebTransport is not supported in this browser");
1073
- this.transport = new Ot(n);
1117
+ this.transport = new Mt(s);
1074
1118
  break;
1075
1119
  default:
1076
1120
  throw new Error(`Unsupported entrypoint type: ${N[e.Type]}`);
@@ -1082,21 +1126,21 @@ class bt {
1082
1126
  */
1083
1127
  handleProtocolMessage(e) {
1084
1128
  try {
1085
- const n = e;
1086
- if (j(n) === V.CORE_ON_SERVER_STOPPING) {
1129
+ const s = e;
1130
+ if (Q(s) === V.CORE_ON_SERVER_STOPPING) {
1087
1131
  x.debug("Received server stopping message"), this.setState("stopped"), this.transport?.close();
1088
1132
  return;
1089
1133
  }
1090
- this.config.onProtocolMessage?.(n);
1091
- } catch (n) {
1092
- x.error("Failed to handle protocol message:", n), this.config.onError?.(n instanceof Error ? n : new Error(String(n)));
1134
+ this.config.onProtocolMessage?.(s);
1135
+ } catch (s) {
1136
+ x.error("Failed to handle protocol message:", s), this.config.onError?.(s instanceof Error ? s : new Error(String(s)));
1093
1137
  }
1094
1138
  }
1095
1139
  /**
1096
1140
  * Handle transport close.
1097
1141
  */
1098
- handleClose(e, n) {
1099
- this.transport = null, this.config.onClose?.(e, n);
1142
+ handleClose(e, s) {
1143
+ this.transport = null, this.config.onClose?.(e, s);
1100
1144
  }
1101
1145
  /**
1102
1146
  * Handle transport error.
@@ -1111,8 +1155,8 @@ class bt {
1111
1155
  this.state !== e && (this.state = e, this.config.onStateChange?.(e));
1112
1156
  }
1113
1157
  }
1114
- const I = p("ChannelManager");
1115
- class Mt {
1158
+ const u = p("ChannelManager"), vt = 5e3;
1159
+ class dt {
1116
1160
  channels = /* @__PURE__ */ new Map();
1117
1161
  // keyed by opcode group
1118
1162
  activeType = null;
@@ -1122,6 +1166,7 @@ class Mt {
1122
1166
  entrypoints = [];
1123
1167
  abortController = null;
1124
1168
  connectionTimeoutMs;
1169
+ stabilityTimer = null;
1125
1170
  config;
1126
1171
  constructor(e) {
1127
1172
  this.config = e;
@@ -1141,10 +1186,10 @@ class Mt {
1141
1186
  /**
1142
1187
  * Connect to the server using the provided entrypoints.
1143
1188
  */
1144
- async connect(e, n) {
1189
+ async connect(e, s) {
1145
1190
  if (this.state !== "idle" && this.state !== "offline")
1146
1191
  throw new Error(`Cannot connect: already in state ${this.state}`);
1147
- if (this.entrypoints = e, this.shouldReconnect = !0, this.reconnectAttempts = 0, this.abortController = new AbortController(), n?.retry) {
1192
+ if (this.entrypoints = e, this.shouldReconnect = !0, this.reconnectAttempts = 0, this.abortController = new AbortController(), s?.retry) {
1148
1193
  this.attemptReconnect();
1149
1194
  return;
1150
1195
  }
@@ -1161,20 +1206,20 @@ class Mt {
1161
1206
  * The opcode group is extracted from the message automatically.
1162
1207
  */
1163
1208
  sendProtocolMessage(e) {
1164
- const n = v(e);
1165
- for (const [r, s] of this.channels)
1166
- if (r & n) {
1167
- s.send(e);
1209
+ const s = F(e);
1210
+ for (const [r, n] of this.channels)
1211
+ if (r & s) {
1212
+ n.send(e);
1168
1213
  return;
1169
1214
  }
1170
- this.state === "connected" && I.warn("No channel found for message");
1215
+ this.state === "connected" && u.warn("No channel found for message");
1171
1216
  }
1172
1217
  /**
1173
1218
  * Send a protocol message to all channels (for broadcast messages).
1174
1219
  */
1175
1220
  sendToAll(e) {
1176
- for (const n of this.channels.values())
1177
- n.send(e);
1221
+ for (const s of this.channels.values())
1222
+ s.send(e);
1178
1223
  }
1179
1224
  /**
1180
1225
  * Check health of all channels.
@@ -1195,9 +1240,9 @@ class Mt {
1195
1240
  */
1196
1241
  triggerReconnect(e) {
1197
1242
  if (this.state === "connected") {
1198
- I.debug(`Forcing reconnect: ${e}`);
1199
- for (const n of this.channels.values())
1200
- n.triggerReconnect(e);
1243
+ u.debug(`Forcing reconnect: ${e}`);
1244
+ for (const s of this.channels.values())
1245
+ s.triggerReconnect(e);
1201
1246
  }
1202
1247
  }
1203
1248
  /**
@@ -1206,43 +1251,43 @@ class Mt {
1206
1251
  */
1207
1252
  async connectInternal(e = !1) {
1208
1253
  this.setState("connecting");
1209
- let n = this.entrypoints;
1254
+ let s = this.entrypoints;
1210
1255
  if (this.config.webRtcEnabled) {
1211
- I.debug(`WebRTC enabled, filtering entrypoints (total: ${this.entrypoints.length})`);
1256
+ u.debug(`WebRTC enabled, filtering entrypoints (total: ${this.entrypoints.length})`);
1212
1257
  for (const i of this.entrypoints)
1213
- I.debug(` Entrypoint: type=${i.Type} fromServer=0x${i.OpcodeGroupsFromServer.toString(16)} toServer=0x${i.OpcodeGroupsToServer.toString(16)} uri=${i.Uri}`);
1214
- n = this.entrypoints.filter((i) => i.Type === N.WebRTC ? (I.debug(` Filtered out WebRTC entrypoint (type=${i.Type})`), !1) : !0), I.debug(`After filtering: ${n.length} entrypoints remain for WS/WT channels`);
1258
+ u.debug(` Entrypoint: type=${i.Type} fromServer=0x${i.OpcodeGroupsFromServer.toString(16)} toServer=0x${i.OpcodeGroupsToServer.toString(16)} uri=${i.Uri}`);
1259
+ s = this.entrypoints.filter((i) => i.Type === N.WebRTC ? (u.debug(` Filtered out WebRTC entrypoint (type=${i.Type})`), !1) : !0), u.debug(`After filtering: ${s.length} entrypoints remain for WS/WT channels`);
1215
1260
  }
1216
- const r = this.groupByType(n);
1261
+ const r = this.groupByType(s);
1217
1262
  if (r.size === 0)
1218
1263
  throw this.setState("offline"), new Error("No entrypoints available");
1219
- let s;
1264
+ let n;
1220
1265
  if (this.config.orderedEndpointTypes && this.config.orderedEndpointTypes.length > 0) {
1221
1266
  const i = new Set(r.keys());
1222
- s = this.config.orderedEndpointTypes.filter((o) => i.has(o));
1223
- } else this.config.endpointSelector ? s = this.config.endpointSelector.getOrderedTypes(r) : s = Array.from(r.keys());
1224
- this.connectionTimeoutMs = s.length > 1 ? 5e3 : 1e4, I.info(`Endpoint types to try: [${s.map((i) => N[i]).join(", ")}], transport timeout: ${this.connectionTimeoutMs}ms`);
1225
- for (const i of s) {
1267
+ n = this.config.orderedEndpointTypes.filter((a) => i.has(a));
1268
+ } else this.config.endpointSelector ? n = this.config.endpointSelector.getOrderedTypes(r) : n = Array.from(r.keys());
1269
+ this.connectionTimeoutMs = n.length > 1 ? 5e3 : 1e4, u.debug(`Endpoint types to try: [${n.map((i) => N[i]).join(", ")}], transport timeout: ${this.connectionTimeoutMs}ms`);
1270
+ for (const i of n) {
1226
1271
  if (!this.shouldReconnect)
1227
1272
  return;
1228
- const o = r.get(i), a = Date.now();
1229
- I.info(`Trying ${N[i]} (${o.length} channel(s))`);
1273
+ const a = r.get(i), o = Date.now();
1274
+ u.debug(`Trying ${N[i]} (${a.length} channel(s))`);
1230
1275
  try {
1231
- await this.connectAllChannels(o), this.config.endpointSelector?.rememberWorkingType(i), this.config.onRememberWorkingType?.(i), this.activeType = i, this.reconnectAttempts = 0, I.info(`Connected via ${N[i]} in ${Date.now() - a}ms`), this.setState("connected");
1276
+ await this.connectAllChannels(a), this.config.endpointSelector?.rememberWorkingType(i), this.config.onRememberWorkingType?.(i), this.activeType = i, u.debug(`Connected via ${N[i]} in ${Date.now() - o}ms`), this.setState("connected"), this.startStabilityTimer();
1232
1277
  return;
1233
- } catch (E) {
1234
- I.warn(`Failed to connect using ${N[i]} after ${Date.now() - a}ms: ${E instanceof Error ? E.message : E}`);
1235
- const _ = this.channels.size > 0;
1236
- if (this.disconnectAll(), _ && this.config.onRefreshEntrypoints)
1278
+ } catch (l) {
1279
+ u.warn(`Failed to connect using ${N[i]} after ${Date.now() - o}ms: ${l instanceof Error ? l.message : l}`);
1280
+ const I = this.channels.size > 0;
1281
+ if (this.disconnectAll(), I && this.config.onRefreshEntrypoints)
1237
1282
  try {
1238
- I.info("Partial connection detected, refreshing entrypoints");
1239
- const l = await this.config.onRefreshEntrypoints();
1240
- this.entrypoints = l.entrypoints, this.config.sessionId = l.sessionId;
1241
- const T = this.config.webRtcEnabled ? l.entrypoints.filter((c) => c.Type !== N.WebRTC) : l.entrypoints, S = this.groupByType(T);
1242
- for (const [c, g] of S)
1243
- r.set(c, g);
1244
- } catch (l) {
1245
- I.warn(`Failed to refresh entrypoints: ${l}`);
1283
+ u.info("Partial connection detected, refreshing entrypoints");
1284
+ const E = await this.config.onRefreshEntrypoints();
1285
+ this.entrypoints = E.entrypoints, this.config.sessionId = E.sessionId;
1286
+ const h = this.config.webRtcEnabled ? E.entrypoints.filter((c) => c.Type !== N.WebRTC) : E.entrypoints, T = this.groupByType(h);
1287
+ for (const [c, w] of T)
1288
+ r.set(c, w);
1289
+ } catch (E) {
1290
+ u.warn(`Failed to refresh entrypoints: ${E}`);
1246
1291
  }
1247
1292
  }
1248
1293
  }
@@ -1254,20 +1299,20 @@ class Mt {
1254
1299
  async connectAllChannels(e) {
1255
1300
  if (e.length === 0)
1256
1301
  throw new Error("No entrypoints to connect");
1257
- const r = (await Promise.allSettled(e.map((s) => this.connectChannel(s)))).filter((s) => s.status === "rejected");
1302
+ const r = (await Promise.allSettled(e.map((n) => this.connectChannel(n)))).filter((n) => n.status === "rejected");
1258
1303
  if (r.length > 0) {
1259
- const s = r.map((i) => {
1260
- const o = i.reason;
1261
- return o instanceof Error ? o.message : String(o);
1304
+ const n = r.map((i) => {
1305
+ const a = i.reason;
1306
+ return a instanceof Error ? a.message : String(a);
1262
1307
  });
1263
- throw new Error(s.join(", "));
1308
+ throw new Error(n.join(", "));
1264
1309
  }
1265
1310
  }
1266
1311
  /**
1267
1312
  * Connect a single channel.
1268
1313
  */
1269
1314
  async connectChannel(e) {
1270
- const n = new bt({
1315
+ const s = new bt({
1271
1316
  entrypoint: e,
1272
1317
  sessionId: this.config.sessionId,
1273
1318
  keepaliveTimeoutMs: this.config.keepaliveTimeoutMs,
@@ -1278,31 +1323,31 @@ class Mt {
1278
1323
  onStateChange: (r) => {
1279
1324
  this.handleChannelStateChange(e.OpcodeGroupsFromServer, r);
1280
1325
  },
1281
- onClose: (r, s) => {
1282
- this.handleChannelClose(e.OpcodeGroupsFromServer, r, s);
1326
+ onClose: (r, n) => {
1327
+ this.handleChannelClose(e.OpcodeGroupsFromServer, r, n);
1283
1328
  },
1284
1329
  onError: (r) => {
1285
1330
  this.config.onError?.(r);
1286
1331
  }
1287
1332
  });
1288
- await n.connect(), this.channels.set(e.OpcodeGroupsFromServer, n);
1333
+ await s.connect(), this.channels.set(e.OpcodeGroupsFromServer, s);
1289
1334
  }
1290
1335
  /**
1291
1336
  * Group entrypoints by type.
1292
1337
  */
1293
1338
  groupByType(e) {
1294
- const n = /* @__PURE__ */ new Map();
1339
+ const s = /* @__PURE__ */ new Map();
1295
1340
  for (const r of e) {
1296
- const s = n.get(r.Type) ?? [];
1297
- s.push(r), n.set(r.Type, s);
1341
+ const n = s.get(r.Type) ?? [];
1342
+ n.push(r), s.set(r.Type, n);
1298
1343
  }
1299
- return n;
1344
+ return s;
1300
1345
  }
1301
1346
  /**
1302
1347
  * Handle channel state change.
1303
1348
  */
1304
- handleChannelStateChange(e, n) {
1305
- n === "stopped" && (this.shouldReconnect = !1, this.disconnectAll(), this.setState("stopped"));
1349
+ handleChannelStateChange(e, s) {
1350
+ s === "stopped" && (this.shouldReconnect = !1, this.disconnectAll(), this.setState("stopped"));
1306
1351
  }
1307
1352
  /**
1308
1353
  * Handle channel close.
@@ -1312,8 +1357,8 @@ class Mt {
1312
1357
  * close — including a clean WebSocket code 1000 — just means this transport
1313
1358
  * dropped, and we reconnect.
1314
1359
  */
1315
- handleChannelClose(e, n, r) {
1316
- this.state === "idle" || this.state === "stopped" || this.state === "offline" || this.channels.has(e) && this.state === "connected" && (I.warn("Channel closed unexpectedly, attempting reconnect"), this.disconnectAll(), this.attemptReconnect());
1360
+ handleChannelClose(e, s, r) {
1361
+ this.state === "idle" || this.state === "stopped" || this.state === "offline" || this.channels.has(e) && this.state === "connected" && (u.warn("Channel closed unexpectedly, attempting reconnect"), this.disconnectAll(), this.attemptReconnect());
1317
1362
  }
1318
1363
  /**
1319
1364
  * Attempt to reconnect with fixed-interval retry.
@@ -1322,14 +1367,14 @@ class Mt {
1322
1367
  async attemptReconnect() {
1323
1368
  if (this.shouldReconnect) {
1324
1369
  if (!Lt()) {
1325
- I.warn("Retry disabled via ikon-retry=false, skipping reconnect"), this.setState("offline"), this.config.onError?.(new Z(0));
1370
+ u.warn("Retry disabled via ikon-retry=false, skipping reconnect"), this.setState("offline"), this.config.onError?.(new Z(0));
1326
1371
  return;
1327
1372
  }
1328
1373
  if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
1329
- I.warn(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached`), this.setState("offline"), this.config.onError?.(new Z(this.config.maxReconnectAttempts));
1374
+ u.warn(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached`), this.setState("offline"), this.config.onError?.(new Z(this.config.maxReconnectAttempts));
1330
1375
  return;
1331
1376
  }
1332
- if (this.setState("reconnecting"), this.reconnectAttempts++, this.reconnectAttempts > 1 ? (I.info(`Reconnecting in ${this.config.reconnectBackoffMs}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), await Ct(this.config.reconnectBackoffMs, this.abortController?.signal)) : I.info(`Reconnecting immediately (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), !!this.shouldReconnect)
1377
+ if (this.setState("reconnecting"), this.reconnectAttempts++, this.reconnectAttempts > 1 ? (u.info(`Reconnecting in ${this.config.reconnectBackoffMs}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), await Ct(this.config.reconnectBackoffMs, this.abortController?.signal)) : u.info(`Reconnecting immediately (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), !!this.shouldReconnect)
1333
1378
  try {
1334
1379
  await this.connectInternal(!0);
1335
1380
  } catch {
@@ -1349,80 +1394,88 @@ class Mt {
1349
1394
  * Update and notify state change.
1350
1395
  */
1351
1396
  setState(e) {
1352
- this.state !== e && (this.state = e, this.config.onStateChange?.(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
+ }, vt);
1403
+ }
1404
+ clearStabilityTimer() {
1405
+ this.stabilityTimer && (clearTimeout(this.stabilityTimer), this.stabilityTimer = null);
1353
1406
  }
1354
1407
  }
1355
- const at = p("ProtocolWorker"), L = (t, e) => {
1408
+ const ot = p("ProtocolWorker"), P = (t, e) => {
1356
1409
  self.postMessage(t, e ?? []);
1357
1410
  };
1358
- let A = null, B = null, d = null, X, C = null;
1359
- const P = [], f = [], F = /* @__PURE__ */ new Map(), R = [], u = [], w = /* @__PURE__ */ new Map(), $ = [];
1360
- function Q() {
1411
+ let A = null, v = null, d = null, X, C = null;
1412
+ const m = [], R = [], B = /* @__PURE__ */ new Map(), y = [], f = [], L = /* @__PURE__ */ new Map(), $ = [];
1413
+ function j() {
1361
1414
  try {
1362
1415
  A?.disconnect();
1363
1416
  } catch (t) {
1364
- at.warn(`Failed to disconnect channel manager: ${t}`);
1417
+ ot.warn(`Failed to disconnect channel manager: ${t}`);
1365
1418
  }
1366
1419
  A = null;
1367
- for (let t = 0; t < f.length; t++)
1420
+ for (let t = 0; t < R.length; t++)
1368
1421
  try {
1369
- f[t].port.close();
1422
+ R[t].port.close();
1370
1423
  } catch {
1371
1424
  }
1372
- P.length = 0, f.length = 0, F.clear();
1373
- for (let t = 0; t < u.length; t++)
1425
+ m.length = 0, R.length = 0, B.clear();
1426
+ for (let t = 0; t < f.length; t++)
1374
1427
  try {
1375
- u[t].port.close();
1428
+ f[t].port.close();
1376
1429
  } catch {
1377
1430
  }
1378
- R.length = 0, u.length = 0, w.clear();
1431
+ y.length = 0, f.length = 0, L.clear();
1379
1432
  }
1380
- function M(t) {
1433
+ function b(t) {
1381
1434
  const e = t instanceof Error ? t : new Error(String(t));
1382
- L({ type: "error", error: { name: e.name, message: e.message, stack: e.stack } });
1435
+ P({ type: "error", error: { name: e.name, message: e.message, stack: e.stack } });
1383
1436
  }
1384
1437
  function Bt() {
1385
1438
  let t = 0;
1386
- for (let e = 0; e < f.length; e++)
1387
- t |= f[e].opcodeGroupsMask;
1439
+ for (let e = 0; e < R.length; e++)
1440
+ t |= R[e].opcodeGroupsMask;
1388
1441
  return t;
1389
1442
  }
1390
- function dt(t) {
1443
+ function Ft(t) {
1391
1444
  if (X === void 0)
1392
1445
  return !0;
1393
- const e = v(t);
1446
+ const e = F(t);
1394
1447
  if ((e & X) !== 0)
1395
1448
  return !0;
1396
- const n = Bt();
1397
- return (e & n) !== 0;
1449
+ const s = Bt();
1450
+ return (e & s) !== 0;
1398
1451
  }
1399
- function ot(t) {
1452
+ function lt(t) {
1400
1453
  $.length = 0;
1401
- for (let e = 0; e < f.length; e++) {
1402
- const n = f[e];
1403
- (n.opcodeGroupsMask & t) !== 0 && $.push(n.port);
1454
+ for (let e = 0; e < R.length; e++) {
1455
+ const s = R[e];
1456
+ (s.opcodeGroupsMask & t) !== 0 && $.push(s.port);
1404
1457
  }
1405
1458
  return $;
1406
1459
  }
1407
- function Ft(t, e) {
1408
- return (v(t) & e) !== 0;
1460
+ function Gt(t, e) {
1461
+ return (F(t) & e) !== 0;
1409
1462
  }
1410
- function vt(t, e) {
1463
+ function Vt(t, e) {
1411
1464
  if (!A || !e || typeof e != "object")
1412
1465
  return;
1413
- const n = e;
1414
- if (!(n.type !== "send" || !(n.message instanceof ArrayBuffer)))
1466
+ const s = e;
1467
+ if (!(s.type !== "send" || !(s.message instanceof ArrayBuffer)))
1415
1468
  try {
1416
- const r = new Uint8Array(n.message);
1417
- if (!Ft(r, t))
1469
+ const r = new Uint8Array(s.message);
1470
+ if (!Gt(r, t))
1418
1471
  return;
1419
1472
  A.sendProtocolMessage(r), C && C.postMessage({ direction: "sent", message: Array.from(r) });
1420
1473
  } catch (r) {
1421
- M(r);
1474
+ b(r);
1422
1475
  }
1423
1476
  }
1424
- async function Gt(t) {
1425
- Q(), A = new Mt({
1477
+ async function pt(t) {
1478
+ j(), A = new dt({
1426
1479
  sessionId: t.sessionId,
1427
1480
  keepaliveTimeoutMs: t.keepaliveTimeoutMs,
1428
1481
  reconnectBackoffMs: t.reconnectBackoffMs,
@@ -1430,55 +1483,55 @@ async function Gt(t) {
1430
1483
  orderedEndpointTypes: t.orderedEndpointTypes,
1431
1484
  webRtcEnabled: t.webRtcEnabled,
1432
1485
  onStateChange: (e) => {
1433
- L({ type: "state", state: e, activeType: A?.activeEndpointType ?? void 0 });
1486
+ P({ type: "state", state: e, activeType: A?.activeEndpointType ?? void 0 });
1434
1487
  },
1435
1488
  onRememberWorkingType: () => {
1436
- L({ type: "state", state: A?.managerState ?? "idle", activeType: A?.activeEndpointType ?? void 0 });
1489
+ P({ type: "state", state: A?.managerState ?? "idle", activeType: A?.activeEndpointType ?? void 0 });
1437
1490
  },
1438
1491
  onError: (e) => {
1439
- M(e);
1492
+ b(e);
1440
1493
  },
1441
- onRefreshEntrypoints: () => new Promise((e, n) => {
1442
- B = e, d = n, L({ type: "refreshEntrypoints" });
1494
+ onRefreshEntrypoints: () => new Promise((e, s) => {
1495
+ v = e, d = s, P({ type: "refreshEntrypoints" });
1443
1496
  }),
1444
1497
  onProtocolMessage: (e) => {
1445
- C && (C.postMessage({ direction: "received", message: Array.from(e) }), j(e) === V.ANALYTICS_LOGS && C.postMessage({ type: "serverLogs", message: Array.from(e) }));
1446
- const n = v(e), r = dt(e), s = ot(n);
1447
- if (!(!r && s.length === 0))
1498
+ C && (C.postMessage({ direction: "received", message: Array.from(e) }), Q(e) === V.ANALYTICS_LOGS && C.postMessage({ type: "serverLogs", message: Array.from(e) }));
1499
+ const s = F(e), r = Ft(e), n = lt(s);
1500
+ if (!(!r && n.length === 0))
1448
1501
  try {
1449
- const i = H(e), o = e.buffer instanceof ArrayBuffer && e.byteOffset === 0 && e.byteLength === e.buffer.byteLength, a = s.length > 0;
1450
- if (a && !r && s.length === 1 && o) {
1451
- const E = e.buffer;
1452
- s[0].postMessage({ type: "protocol", message: E, headers: i }, [E]);
1502
+ const i = H(e), a = e.buffer instanceof ArrayBuffer && e.byteOffset === 0 && e.byteLength === e.buffer.byteLength, o = n.length > 0;
1503
+ if (o && !r && n.length === 1 && a) {
1504
+ const l = e.buffer;
1505
+ n[0].postMessage({ type: "protocol", message: l, headers: i }, [l]);
1453
1506
  return;
1454
1507
  }
1455
- if (!a && r && o) {
1456
- const E = e.buffer;
1457
- L({ type: "protocol", message: E, headers: i }, [E]);
1508
+ if (!o && r && a) {
1509
+ const l = e.buffer;
1510
+ P({ type: "protocol", message: l, headers: i }, [l]);
1458
1511
  return;
1459
1512
  }
1460
- if (a && o) {
1461
- const E = [];
1462
- for (let T = 1; T < s.length; T++)
1463
- E.push(e.slice().buffer);
1464
- const _ = r ? e.slice().buffer : null, l = e.buffer;
1465
- s[0].postMessage({ type: "protocol", message: l, headers: i }, [l]);
1466
- for (let T = 1; T < s.length; T++)
1467
- s[T].postMessage({ type: "protocol", message: E[T - 1], headers: i }, [E[T - 1]]);
1468
- _ && L({ type: "protocol", message: _, headers: i }, [_]);
1513
+ if (o && a) {
1514
+ const l = [];
1515
+ for (let h = 1; h < n.length; h++)
1516
+ l.push(e.slice().buffer);
1517
+ const I = r ? e.slice().buffer : null, E = e.buffer;
1518
+ n[0].postMessage({ type: "protocol", message: E, headers: i }, [E]);
1519
+ for (let h = 1; h < n.length; h++)
1520
+ n[h].postMessage({ type: "protocol", message: l[h - 1], headers: i }, [l[h - 1]]);
1521
+ I && P({ type: "protocol", message: I, headers: i }, [I]);
1469
1522
  return;
1470
1523
  }
1471
- if (a)
1472
- for (const E of s) {
1473
- const _ = e.slice().buffer;
1474
- E.postMessage({ type: "protocol", message: _, headers: i }, [_]);
1524
+ if (o)
1525
+ for (const l of n) {
1526
+ const I = e.slice().buffer;
1527
+ l.postMessage({ type: "protocol", message: I, headers: i }, [I]);
1475
1528
  }
1476
1529
  if (r) {
1477
- const E = e.slice().buffer;
1478
- L({ type: "protocol", message: E, headers: i }, [E]);
1530
+ const l = e.slice().buffer;
1531
+ P({ type: "protocol", message: l, headers: i }, [l]);
1479
1532
  }
1480
1533
  } catch (i) {
1481
- M(i);
1534
+ b(i);
1482
1535
  }
1483
1536
  }
1484
1537
  }), await A.connect(t.entrypoints, { retry: t.retry });
@@ -1486,23 +1539,23 @@ async function Gt(t) {
1486
1539
  self.addEventListener("message", (t) => {
1487
1540
  const e = t.data;
1488
1541
  if (e.type === "connect") {
1489
- Gt(e).catch((n) => {
1490
- at.error(`Failed to connect: ${n}`), M(n), Q();
1542
+ pt(e).catch((s) => {
1543
+ ot.error(`Failed to connect: ${s}`), b(s), j();
1491
1544
  });
1492
1545
  return;
1493
1546
  }
1494
1547
  if (e.type === "disconnect") {
1495
- Q(), L({ type: "state", state: "idle" });
1548
+ j(), P({ type: "state", state: "idle" });
1496
1549
  return;
1497
1550
  }
1498
1551
  if (e.type === "send") {
1499
1552
  if (!A)
1500
1553
  return;
1501
1554
  try {
1502
- const n = new Uint8Array(e.message);
1503
- A.sendProtocolMessage(n), C && C.postMessage({ direction: "sent", message: Array.from(n) });
1504
- } catch (n) {
1505
- M(n);
1555
+ const s = new Uint8Array(e.message);
1556
+ A.sendProtocolMessage(s), C && C.postMessage({ direction: "sent", message: Array.from(s) });
1557
+ } catch (s) {
1558
+ b(s);
1506
1559
  }
1507
1560
  return;
1508
1561
  }
@@ -1514,6 +1567,10 @@ self.addEventListener("message", (t) => {
1514
1567
  e.enabled && !C ? C = new BroadcastChannel("ikon:devtools") : !e.enabled && C && (C.close(), C = null);
1515
1568
  return;
1516
1569
  }
1570
+ if (e.type === "setLogLevel") {
1571
+ Rt(e.level);
1572
+ return;
1573
+ }
1517
1574
  if (e.type === "checkHealth") {
1518
1575
  A?.checkHealth();
1519
1576
  return;
@@ -1523,25 +1580,25 @@ self.addEventListener("message", (t) => {
1523
1580
  return;
1524
1581
  }
1525
1582
  if (e.type === "refreshedEntrypoints") {
1526
- B && (B({ entrypoints: e.entrypoints, sessionId: e.sessionId }), B = null, d = null);
1583
+ v && (v({ entrypoints: e.entrypoints, sessionId: e.sessionId }), v = null, d = null);
1527
1584
  return;
1528
1585
  }
1529
1586
  if (e.type === "refreshEntrypointsFailed") {
1530
- d && (d(new Error("Failed to refresh entrypoints")), B = null, d = null);
1587
+ d && (d(new Error("Failed to refresh entrypoints")), v = null, d = null);
1531
1588
  return;
1532
1589
  }
1533
1590
  if (e.type === "forwardToPorts") {
1534
1591
  try {
1535
- const n = new Uint8Array(e.message), r = v(n), s = ot(r);
1536
- if (s.length > 0) {
1537
- const i = H(n);
1538
- for (const o of s) {
1539
- const a = n.slice().buffer;
1540
- o.postMessage({ type: "protocol", message: a, headers: i }, [a]);
1592
+ const s = new Uint8Array(e.message), r = F(s), n = lt(r);
1593
+ if (n.length > 0) {
1594
+ const i = H(s);
1595
+ for (const a of n) {
1596
+ const o = s.slice().buffer;
1597
+ a.postMessage({ type: "protocol", message: o, headers: i }, [o]);
1541
1598
  }
1542
1599
  }
1543
- } catch (n) {
1544
- M(n);
1600
+ } catch (s) {
1601
+ b(s);
1545
1602
  }
1546
1603
  return;
1547
1604
  }
@@ -1550,67 +1607,67 @@ self.addEventListener("message", (t) => {
1550
1607
  e.port.start?.();
1551
1608
  } catch {
1552
1609
  }
1553
- const n = P.length;
1554
- P.push(e.portId), f.push({ port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }), F.set(e.portId, n);
1610
+ const s = m.length;
1611
+ m.push(e.portId), R.push({ port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }), B.set(e.portId, s);
1555
1612
  return;
1556
1613
  }
1557
1614
  if (e.type === "detachPort") {
1558
- const n = F.get(e.portId);
1559
- if (n !== void 0) {
1560
- const r = f[n];
1615
+ const s = B.get(e.portId);
1616
+ if (s !== void 0) {
1617
+ const r = R[s];
1561
1618
  try {
1562
1619
  r.port.close();
1563
1620
  } catch {
1564
1621
  }
1565
- const s = P.length - 1;
1566
- if (n !== s) {
1567
- const i = P[s];
1568
- P[n] = i, f[n] = f[s], F.set(i, n);
1622
+ const n = m.length - 1;
1623
+ if (s !== n) {
1624
+ const i = m[n];
1625
+ m[s] = i, R[s] = R[n], B.set(i, s);
1569
1626
  }
1570
- P.length--, f.length--, F.delete(e.portId);
1627
+ m.length--, R.length--, B.delete(e.portId);
1571
1628
  }
1572
1629
  return;
1573
1630
  }
1574
1631
  if (e.type === "attachSendPort") {
1575
- const n = w.get(e.portId);
1576
- if (n !== void 0) {
1577
- const i = u[n];
1632
+ const s = L.get(e.portId);
1633
+ if (s !== void 0) {
1634
+ const i = f[s];
1578
1635
  try {
1579
1636
  i.port.close();
1580
1637
  } catch {
1581
1638
  }
1582
- const o = R.length - 1;
1583
- if (n !== o) {
1584
- const a = R[o];
1585
- R[n] = a, u[n] = u[o], w.set(a, n);
1639
+ const a = y.length - 1;
1640
+ if (s !== a) {
1641
+ const o = y[a];
1642
+ y[s] = o, f[s] = f[a], L.set(o, s);
1586
1643
  }
1587
- R.length--, u.length--, w.delete(e.portId);
1644
+ y.length--, f.length--, L.delete(e.portId);
1588
1645
  }
1589
- const r = { port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }, s = R.length;
1590
- R.push(e.portId), u.push(r), w.set(e.portId, s);
1646
+ const r = { port: e.port, opcodeGroupsMask: e.opcodeGroupsMask }, n = y.length;
1647
+ y.push(e.portId), f.push(r), L.set(e.portId, n);
1591
1648
  try {
1592
1649
  r.port.start?.();
1593
1650
  } catch {
1594
1651
  }
1595
1652
  r.port.addEventListener("message", (i) => {
1596
- vt(r.opcodeGroupsMask, i.data);
1653
+ Vt(r.opcodeGroupsMask, i.data);
1597
1654
  });
1598
1655
  return;
1599
1656
  }
1600
1657
  if (e.type === "detachSendPort") {
1601
- const n = w.get(e.portId);
1602
- if (n !== void 0) {
1603
- const r = u[n];
1658
+ const s = L.get(e.portId);
1659
+ if (s !== void 0) {
1660
+ const r = f[s];
1604
1661
  try {
1605
1662
  r.port.close();
1606
1663
  } catch {
1607
1664
  }
1608
- const s = R.length - 1;
1609
- if (n !== s) {
1610
- const i = R[s];
1611
- R[n] = i, u[n] = u[s], w.set(i, n);
1665
+ const n = y.length - 1;
1666
+ if (s !== n) {
1667
+ const i = y[n];
1668
+ y[s] = i, f[s] = f[n], L.set(i, s);
1612
1669
  }
1613
- R.length--, u.length--, w.delete(e.portId);
1670
+ y.length--, f.length--, L.delete(e.portId);
1614
1671
  }
1615
1672
  return;
1616
1673
  }