@limrun/ui 0.22.5 → 0.22.7

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.
@@ -19,11 +19,11 @@ const ee = {
19
19
  INJECT_MAC_KEY: 41,
20
20
  // macOS: wheel and trackpad scrolling, as pixel deltas.
21
21
  INJECT_MAC_SCROLL: 42
22
- }, Ge = {
22
+ }, Qe = {
23
23
  DOWN: 0,
24
24
  UP: 1,
25
25
  MOVE: 2
26
- }, je = {
26
+ }, ze = {
27
27
  ACTION_DOWN: 0,
28
28
  ACTION_UP: 1,
29
29
  ACTION_MOVE: 2,
@@ -33,7 +33,7 @@ const ee = {
33
33
  BUTTON_PRIMARY: 1,
34
34
  BUTTON_SECONDARY: 2,
35
35
  BUTTON_TERTIARY: 4
36
- }, o = {
36
+ }, a = {
37
37
  // Actions
38
38
  ACTION_DOWN: 0,
39
39
  ACTION_UP: 1,
@@ -259,113 +259,113 @@ const ee = {
259
259
  KEYCODE_SLEEP: 223,
260
260
  KEYCODE_WAKEUP: 224,
261
261
  KEYCODE_SOFT_SLEEP: 276
262
- }, Ht = {
263
- KeyA: o.KEYCODE_A,
264
- KeyB: o.KEYCODE_B,
265
- KeyC: o.KEYCODE_C,
266
- KeyD: o.KEYCODE_D,
267
- KeyE: o.KEYCODE_E,
268
- KeyF: o.KEYCODE_F,
269
- KeyG: o.KEYCODE_G,
270
- KeyH: o.KEYCODE_H,
271
- KeyI: o.KEYCODE_I,
272
- KeyJ: o.KEYCODE_J,
273
- KeyK: o.KEYCODE_K,
274
- KeyL: o.KEYCODE_L,
275
- KeyM: o.KEYCODE_M,
276
- KeyN: o.KEYCODE_N,
277
- KeyO: o.KEYCODE_O,
278
- KeyP: o.KEYCODE_P,
279
- KeyQ: o.KEYCODE_Q,
280
- KeyR: o.KEYCODE_R,
281
- KeyS: o.KEYCODE_S,
282
- KeyT: o.KEYCODE_T,
283
- KeyU: o.KEYCODE_U,
284
- KeyV: o.KEYCODE_V,
285
- KeyW: o.KEYCODE_W,
286
- KeyX: o.KEYCODE_X,
287
- KeyY: o.KEYCODE_Y,
288
- KeyZ: o.KEYCODE_Z,
289
- Digit0: o.KEYCODE_0,
290
- Digit1: o.KEYCODE_1,
291
- Digit2: o.KEYCODE_2,
292
- Digit3: o.KEYCODE_3,
293
- Digit4: o.KEYCODE_4,
294
- Digit5: o.KEYCODE_5,
295
- Digit6: o.KEYCODE_6,
296
- Digit7: o.KEYCODE_7,
297
- Digit8: o.KEYCODE_8,
298
- Digit9: o.KEYCODE_9,
299
- Backquote: o.KEYCODE_GRAVE,
300
- Minus: o.KEYCODE_MINUS,
301
- Equal: o.KEYCODE_EQUALS,
302
- BracketLeft: o.KEYCODE_LEFT_BRACKET,
303
- BracketRight: o.KEYCODE_RIGHT_BRACKET,
304
- Backslash: o.KEYCODE_BACKSLASH,
305
- Semicolon: o.KEYCODE_SEMICOLON,
306
- Quote: o.KEYCODE_APOSTROPHE,
307
- Comma: o.KEYCODE_COMMA,
308
- Period: o.KEYCODE_PERIOD,
309
- Slash: o.KEYCODE_SLASH,
310
- Space: o.KEYCODE_SPACE,
311
- Tab: o.KEYCODE_TAB,
312
- Escape: o.KEYCODE_ESCAPE,
313
- ArrowUp: o.DPAD_UP,
314
- ArrowDown: o.DPAD_DOWN,
315
- ArrowLeft: o.DPAD_LEFT,
316
- ArrowRight: o.DPAD_RIGHT,
317
- Enter: o.ENTER,
318
- Backspace: o.DEL,
319
- Delete: o.FORWARD_DEL,
320
- Home: o.KEYCODE_MOVE_HOME,
321
- End: o.KEYCODE_MOVE_END,
322
- PageUp: o.KEYCODE_PAGE_UP,
323
- PageDown: o.KEYCODE_PAGE_DOWN,
324
- Insert: o.KEYCODE_INSERT,
325
- F1: o.KEYCODE_F1,
326
- F2: o.KEYCODE_F2,
327
- F3: o.KEYCODE_F3,
328
- F4: o.KEYCODE_F4,
329
- F5: o.KEYCODE_F5,
330
- F6: o.KEYCODE_F6,
331
- F7: o.KEYCODE_F7,
332
- F8: o.KEYCODE_F8,
333
- F9: o.KEYCODE_F9,
334
- F10: o.KEYCODE_F10,
335
- F11: o.KEYCODE_F11,
336
- F12: o.KEYCODE_F12,
337
- ShiftLeft: o.KEYCODE_SHIFT_LEFT,
338
- ShiftRight: o.KEYCODE_SHIFT_RIGHT,
339
- ControlLeft: o.KEYCODE_CTRL_LEFT,
340
- ControlRight: o.KEYCODE_CTRL_RIGHT,
341
- AltLeft: o.KEYCODE_ALT_LEFT,
342
- AltRight: o.KEYCODE_ALT_RIGHT,
343
- MetaLeft: o.KEYCODE_META_LEFT,
344
- MetaRight: o.KEYCODE_META_RIGHT,
262
+ }, tr = {
263
+ KeyA: a.KEYCODE_A,
264
+ KeyB: a.KEYCODE_B,
265
+ KeyC: a.KEYCODE_C,
266
+ KeyD: a.KEYCODE_D,
267
+ KeyE: a.KEYCODE_E,
268
+ KeyF: a.KEYCODE_F,
269
+ KeyG: a.KEYCODE_G,
270
+ KeyH: a.KEYCODE_H,
271
+ KeyI: a.KEYCODE_I,
272
+ KeyJ: a.KEYCODE_J,
273
+ KeyK: a.KEYCODE_K,
274
+ KeyL: a.KEYCODE_L,
275
+ KeyM: a.KEYCODE_M,
276
+ KeyN: a.KEYCODE_N,
277
+ KeyO: a.KEYCODE_O,
278
+ KeyP: a.KEYCODE_P,
279
+ KeyQ: a.KEYCODE_Q,
280
+ KeyR: a.KEYCODE_R,
281
+ KeyS: a.KEYCODE_S,
282
+ KeyT: a.KEYCODE_T,
283
+ KeyU: a.KEYCODE_U,
284
+ KeyV: a.KEYCODE_V,
285
+ KeyW: a.KEYCODE_W,
286
+ KeyX: a.KEYCODE_X,
287
+ KeyY: a.KEYCODE_Y,
288
+ KeyZ: a.KEYCODE_Z,
289
+ Digit0: a.KEYCODE_0,
290
+ Digit1: a.KEYCODE_1,
291
+ Digit2: a.KEYCODE_2,
292
+ Digit3: a.KEYCODE_3,
293
+ Digit4: a.KEYCODE_4,
294
+ Digit5: a.KEYCODE_5,
295
+ Digit6: a.KEYCODE_6,
296
+ Digit7: a.KEYCODE_7,
297
+ Digit8: a.KEYCODE_8,
298
+ Digit9: a.KEYCODE_9,
299
+ Backquote: a.KEYCODE_GRAVE,
300
+ Minus: a.KEYCODE_MINUS,
301
+ Equal: a.KEYCODE_EQUALS,
302
+ BracketLeft: a.KEYCODE_LEFT_BRACKET,
303
+ BracketRight: a.KEYCODE_RIGHT_BRACKET,
304
+ Backslash: a.KEYCODE_BACKSLASH,
305
+ Semicolon: a.KEYCODE_SEMICOLON,
306
+ Quote: a.KEYCODE_APOSTROPHE,
307
+ Comma: a.KEYCODE_COMMA,
308
+ Period: a.KEYCODE_PERIOD,
309
+ Slash: a.KEYCODE_SLASH,
310
+ Space: a.KEYCODE_SPACE,
311
+ Tab: a.KEYCODE_TAB,
312
+ Escape: a.KEYCODE_ESCAPE,
313
+ ArrowUp: a.DPAD_UP,
314
+ ArrowDown: a.DPAD_DOWN,
315
+ ArrowLeft: a.DPAD_LEFT,
316
+ ArrowRight: a.DPAD_RIGHT,
317
+ Enter: a.ENTER,
318
+ Backspace: a.DEL,
319
+ Delete: a.FORWARD_DEL,
320
+ Home: a.KEYCODE_MOVE_HOME,
321
+ End: a.KEYCODE_MOVE_END,
322
+ PageUp: a.KEYCODE_PAGE_UP,
323
+ PageDown: a.KEYCODE_PAGE_DOWN,
324
+ Insert: a.KEYCODE_INSERT,
325
+ F1: a.KEYCODE_F1,
326
+ F2: a.KEYCODE_F2,
327
+ F3: a.KEYCODE_F3,
328
+ F4: a.KEYCODE_F4,
329
+ F5: a.KEYCODE_F5,
330
+ F6: a.KEYCODE_F6,
331
+ F7: a.KEYCODE_F7,
332
+ F8: a.KEYCODE_F8,
333
+ F9: a.KEYCODE_F9,
334
+ F10: a.KEYCODE_F10,
335
+ F11: a.KEYCODE_F11,
336
+ F12: a.KEYCODE_F12,
337
+ ShiftLeft: a.KEYCODE_SHIFT_LEFT,
338
+ ShiftRight: a.KEYCODE_SHIFT_RIGHT,
339
+ ControlLeft: a.KEYCODE_CTRL_LEFT,
340
+ ControlRight: a.KEYCODE_CTRL_RIGHT,
341
+ AltLeft: a.KEYCODE_ALT_LEFT,
342
+ AltRight: a.KEYCODE_ALT_RIGHT,
343
+ MetaLeft: a.KEYCODE_META_LEFT,
344
+ MetaRight: a.KEYCODE_META_RIGHT,
345
345
  // Windows/Command key
346
- ContextMenu: o.MENU,
346
+ ContextMenu: a.MENU,
347
347
  // Often the Menu key
348
348
  // Numpad mappings
349
- Numpad0: o.KEYCODE_NUMPAD_0,
350
- Numpad1: o.KEYCODE_NUMPAD_1,
351
- Numpad2: o.KEYCODE_NUMPAD_2,
352
- Numpad3: o.KEYCODE_NUMPAD_3,
353
- Numpad4: o.KEYCODE_NUMPAD_4,
354
- Numpad5: o.KEYCODE_NUMPAD_5,
355
- Numpad6: o.KEYCODE_NUMPAD_6,
356
- Numpad7: o.KEYCODE_NUMPAD_7,
357
- Numpad8: o.KEYCODE_NUMPAD_8,
358
- Numpad9: o.KEYCODE_NUMPAD_9,
359
- NumpadDivide: o.KEYCODE_NUMPAD_DIVIDE,
360
- NumpadMultiply: o.KEYCODE_NUMPAD_MULTIPLY,
361
- NumpadSubtract: o.KEYCODE_NUMPAD_SUBTRACT,
362
- NumpadAdd: o.KEYCODE_NUMPAD_ADD,
363
- NumpadDecimal: o.KEYCODE_NUMPAD_DOT,
364
- NumpadComma: o.KEYCODE_NUMPAD_COMMA,
349
+ Numpad0: a.KEYCODE_NUMPAD_0,
350
+ Numpad1: a.KEYCODE_NUMPAD_1,
351
+ Numpad2: a.KEYCODE_NUMPAD_2,
352
+ Numpad3: a.KEYCODE_NUMPAD_3,
353
+ Numpad4: a.KEYCODE_NUMPAD_4,
354
+ Numpad5: a.KEYCODE_NUMPAD_5,
355
+ Numpad6: a.KEYCODE_NUMPAD_6,
356
+ Numpad7: a.KEYCODE_NUMPAD_7,
357
+ Numpad8: a.KEYCODE_NUMPAD_8,
358
+ Numpad9: a.KEYCODE_NUMPAD_9,
359
+ NumpadDivide: a.KEYCODE_NUMPAD_DIVIDE,
360
+ NumpadMultiply: a.KEYCODE_NUMPAD_MULTIPLY,
361
+ NumpadSubtract: a.KEYCODE_NUMPAD_SUBTRACT,
362
+ NumpadAdd: a.KEYCODE_NUMPAD_ADD,
363
+ NumpadDecimal: a.KEYCODE_NUMPAD_DOT,
364
+ NumpadComma: a.KEYCODE_NUMPAD_COMMA,
365
365
  // Some numpads have comma
366
- NumpadEnter: o.KEYCODE_NUMPAD_ENTER,
367
- NumpadEqual: o.KEYCODE_NUMPAD_EQUALS
368
- }, Jt = {
366
+ NumpadEnter: a.KEYCODE_NUMPAD_ENTER,
367
+ NumpadEqual: a.KEYCODE_NUMPAD_EQUALS
368
+ }, rr = {
369
369
  KeyA: 0,
370
370
  KeyS: 1,
371
371
  KeyD: 2,
@@ -480,50 +480,50 @@ const ee = {
480
480
  ArrowDown: 125,
481
481
  ArrowUp: 126
482
482
  };
483
- function Tt(t) {
484
- return Jt[t];
483
+ function Mt(t) {
484
+ return rr[t];
485
485
  }
486
- function Gt(t, e, n, a, u, l, i = 1, E = 0, O = 0) {
487
- const m = new ArrayBuffer(32), S = new DataView(m);
486
+ function nr(t, e, r, o, u, l, i = 1, h = 0, D = 0) {
487
+ const p = new ArrayBuffer(32), S = new DataView(p);
488
488
  let w = 0;
489
489
  S.setUint8(w, ee.INJECT_TOUCH_EVENT), w += 1;
490
- const N = t === je.ACTION_POINTER_DOWN ? je.ACTION_DOWN : t === je.ACTION_POINTER_UP ? je.ACTION_UP : t;
491
- return S.setUint8(w, N), w += 1, S.setBigInt64(w, BigInt(e), !0), w += 8, S.setInt32(w, Math.round(u), !0), w += 4, S.setInt32(w, Math.round(l), !0), w += 4, S.setUint16(w, n, !0), w += 2, S.setUint16(w, a, !0), w += 2, S.setInt16(w, Math.round(i * 65535), !0), w += 2, S.setInt32(w, E, !0), w += 4, S.setInt32(w, O, !0), m;
490
+ const N = t === ze.ACTION_POINTER_DOWN ? ze.ACTION_DOWN : t === ze.ACTION_POINTER_UP ? ze.ACTION_UP : t;
491
+ return S.setUint8(w, N), w += 1, S.setBigInt64(w, BigInt(e), !0), w += 8, S.setInt32(w, Math.round(u), !0), w += 4, S.setInt32(w, Math.round(l), !0), w += 4, S.setUint16(w, r, !0), w += 2, S.setUint16(w, o, !0), w += 2, S.setInt16(w, Math.round(i * 65535), !0), w += 2, S.setInt32(w, h, !0), w += 4, S.setInt32(w, D, !0), p;
492
492
  }
493
- function Bn(t, e, n, a, u, l, i) {
494
- const E = new ArrayBuffer(24), O = new DataView(E);
495
- let m = 0;
496
- return O.setUint8(m, ee.INJECT_TWO_FINGER_TOUCH_EVENT), m += 1, O.setUint8(m, t), m += 1, O.setInt32(m, Math.round(a), !0), m += 4, O.setInt32(m, Math.round(u), !0), m += 4, O.setInt32(m, Math.round(l), !0), m += 4, O.setInt32(m, Math.round(i), !0), m += 4, O.setUint16(m, e, !0), m += 2, O.setUint16(m, n, !0), m += 2, O.setUint16(m, 0, !0), E;
493
+ function jr(t, e, r, o, u, l, i) {
494
+ const h = new ArrayBuffer(24), D = new DataView(h);
495
+ let p = 0;
496
+ return D.setUint8(p, ee.INJECT_TWO_FINGER_TOUCH_EVENT), p += 1, D.setUint8(p, t), p += 1, D.setInt32(p, Math.round(o), !0), p += 4, D.setInt32(p, Math.round(u), !0), p += 4, D.setInt32(p, Math.round(l), !0), p += 4, D.setInt32(p, Math.round(i), !0), p += 4, D.setUint16(p, e, !0), p += 2, D.setUint16(p, r, !0), p += 2, D.setUint16(p, 0, !0), h;
497
497
  }
498
- function jt(t, e = !0) {
499
- const a = new TextEncoder().encode(t), u = new ArrayBuffer(14 + a.length), l = new DataView(u);
498
+ function ir(t, e = !0) {
499
+ const o = new TextEncoder().encode(t), u = new ArrayBuffer(14 + o.length), l = new DataView(u);
500
500
  let i = 0;
501
- return l.setUint8(i, ee.SET_CLIPBOARD), i += 1, l.setBigInt64(i, BigInt(0), !1), i += 8, l.setUint8(i, e ? 1 : 0), i += 1, l.setUint32(i, a.length, !1), i += 4, new Uint8Array(u, i).set(a), u;
501
+ return l.setUint8(i, ee.SET_CLIPBOARD), i += 1, l.setBigInt64(i, BigInt(0), !1), i += 8, l.setUint8(i, e ? 1 : 0), i += 1, l.setUint32(i, o.length, !1), i += 4, new Uint8Array(u, i).set(o), u;
502
502
  }
503
- function it(t, e, n = 0, a = 0) {
503
+ function ct(t, e, r = 0, o = 0) {
504
504
  const u = new ArrayBuffer(14), l = new DataView(u);
505
505
  let i = 0;
506
- return l.setUint8(i, ee.INJECT_KEYCODE), i += 1, l.setUint8(i, t), i += 1, l.setInt32(i, e, !0), i += 4, l.setInt32(i, n, !0), i += 4, l.setInt32(i, a, !0), u;
506
+ return l.setUint8(i, ee.INJECT_KEYCODE), i += 1, l.setUint8(i, t), i += 1, l.setInt32(i, e, !0), i += 4, l.setInt32(i, r, !0), i += 4, l.setInt32(i, o, !0), u;
507
507
  }
508
- function xn(t, e, n, a, u, l) {
509
- const i = new ArrayBuffer(18), E = new DataView(i);
510
- return E.setUint8(0, ee.INJECT_MOUSE_EVENT), E.setUint8(1, t), E.setInt32(2, Math.round(a), !0), E.setInt32(6, Math.round(u), !0), E.setUint16(10, e, !0), E.setUint16(12, n, !0), E.setInt32(14, l, !0), i;
508
+ function Xr(t, e, r, o, u, l) {
509
+ const i = new ArrayBuffer(18), h = new DataView(i);
510
+ return h.setUint8(0, ee.INJECT_MOUSE_EVENT), h.setUint8(1, t), h.setInt32(2, Math.round(o), !0), h.setInt32(6, Math.round(u), !0), h.setUint16(10, e, !0), h.setUint16(12, r, !0), h.setInt32(14, l, !0), i;
511
511
  }
512
- function Xt(t, e) {
513
- const n = new ArrayBuffer(4), a = new DataView(n);
514
- return a.setUint8(0, ee.INJECT_MAC_KEY), a.setUint8(1, t), a.setUint16(2, e, !0), n;
512
+ function or(t, e) {
513
+ const r = new ArrayBuffer(4), o = new DataView(r);
514
+ return o.setUint8(0, ee.INJECT_MAC_KEY), o.setUint8(1, t), o.setUint16(2, e, !0), r;
515
515
  }
516
- function Wn(t, e, n, a, u, l) {
517
- const i = new ArrayBuffer(21), E = new DataView(i);
518
- return E.setUint8(0, ee.INJECT_MAC_SCROLL), E.setInt32(1, Math.round(n), !0), E.setInt32(5, Math.round(a), !0), E.setUint16(9, t, !0), E.setUint16(11, e, !0), E.setFloat32(13, u, !0), E.setFloat32(17, l, !0), i;
516
+ function Qr(t, e, r, o, u, l) {
517
+ const i = new ArrayBuffer(21), h = new DataView(i);
518
+ return h.setUint8(0, ee.INJECT_MAC_SCROLL), h.setInt32(1, Math.round(r), !0), h.setInt32(5, Math.round(o), !0), h.setUint16(9, t, !0), h.setUint16(11, e, !0), h.setFloat32(13, u, !0), h.setFloat32(17, l, !0), i;
519
519
  }
520
- function qn(t) {
520
+ function zr(t) {
521
521
  return t?.displays.find((e) => e.id === (t.angleDegrees < 90 ? "outer" : "inner"));
522
522
  }
523
- function Qt(t) {
523
+ function ar(t) {
524
524
  return t === 2 ? 2 : t === 3 ? 1 : t === 4 ? 3 : 0;
525
525
  }
526
- class Vn {
526
+ class Zr {
527
527
  constructor(e) {
528
528
  this.send = e;
529
529
  }
@@ -534,44 +534,44 @@ class Vn {
534
534
  get active() {
535
535
  return this.held !== void 0;
536
536
  }
537
- setDisplay(e, n = Qt(e?.orientation)) {
538
- (this.screenId !== e?.screenId || this.turns !== n) && this.release(), this.screenId = e?.screenId, this.turns = n;
537
+ setDisplay(e, r = ar(e?.orientation)) {
538
+ (this.screenId !== e?.screenId || this.turns !== r) && this.release(), this.screenId = e?.screenId, this.turns = r;
539
539
  }
540
540
  /** Coordinates are normalized; native input already accounts for the viewer's rotation. */
541
- touch(e, n, a, u = !1) {
541
+ touch(e, r, o, u = !1) {
542
542
  if (this.screenId === void 0) return;
543
- const l = zt(n, a, u ? 0 : this.turns);
543
+ const l = sr(r, o, u ? 0 : this.turns);
544
544
  e === "begin" && (this.release(), this.held = { screenId: this.screenId, ...l }), this.held && (Object.assign(this.held, l), e === "end" ? this.release() : this.send(e === "begin" ? 0 : 2, this.held.screenId, l.x, l.y));
545
545
  }
546
546
  /** Call on pointer cancellation, lost capture, disconnect, and viewer disposal. */
547
547
  release() {
548
548
  if (!this.held) return;
549
- const { screenId: e, x: n, y: a } = this.held;
550
- this.held = void 0, this.send(1, e, n, a);
549
+ const { screenId: e, x: r, y: o } = this.held;
550
+ this.held = void 0, this.send(1, e, r, o);
551
551
  }
552
552
  }
553
- const $n = { width: 164.6, height: 117.8, depth: 5.2 };
554
- function zt(t, e, n) {
555
- return t = Math.max(0, Math.min(1, t)), e = Math.max(0, Math.min(1, e)), n === 1 ? { x: e, y: 1 - t } : n === 2 ? { x: 1 - t, y: 1 - e } : n === 3 ? { x: 1 - e, y: t } : { x: t, y: e };
553
+ const en = { width: 164.6, height: 117.8, depth: 5.2 };
554
+ function sr(t, e, r) {
555
+ return t = Math.max(0, Math.min(1, t)), e = Math.max(0, Math.min(1, e)), r === 1 ? { x: e, y: 1 - t } : r === 2 ? { x: 1 - t, y: 1 - e } : r === 3 ? { x: 1 - e, y: t } : { x: t, y: e };
556
556
  }
557
- function Zt(t) {
557
+ function cr(t) {
558
558
  return Number.isFinite(t) && t >= 0 && t <= 180;
559
559
  }
560
- function Hn(t, e) {
560
+ function tn(t, e) {
561
561
  return { x: Math.max(0, Math.min(1, t)), y: Math.max(0, Math.min(1, 1 - e)) };
562
562
  }
563
- function Jn(t, e, n) {
564
- return e && (t || !n) ? "touch" : t ? "ignore" : "orbit";
563
+ function rn(t, e, r) {
564
+ return e && (t || !r) ? "touch" : t ? "ignore" : "orbit";
565
565
  }
566
- function en(t, e, n, a) {
567
- if (!Number.isInteger(t) || t < 0 || t > 3 || !Number.isInteger(e) || e < 1 || e > 255 || !Number.isFinite(n) || !Number.isFinite(a) || n < 0 || n > 1 || a < 0 || a > 1)
566
+ function lr(t, e, r, o) {
567
+ if (!Number.isInteger(t) || t < 0 || t > 3 || !Number.isInteger(e) || e < 1 || e > 255 || !Number.isFinite(r) || !Number.isFinite(o) || r < 0 || r > 1 || o < 0 || o > 1)
568
568
  throw new RangeError("Invalid display touch coordinates");
569
569
  const u = new ArrayBuffer(12), l = new DataView(u);
570
- return l.setUint8(0, 19), l.setUint8(1, t), l.setUint8(2, e), l.setFloat32(4, n, !0), l.setFloat32(8, a, !0), u;
570
+ return l.setUint8(0, 19), l.setUint8(1, t), l.setUint8(2, e), l.setFloat32(4, r, !0), l.setFloat32(8, o, !0), u;
571
571
  }
572
- class Gn {
573
- constructor(e, n) {
574
- this.send = e, this.failed = n;
572
+ class nn {
573
+ constructor(e, r) {
574
+ this.send = e, this.failed = r;
575
575
  }
576
576
  send;
577
577
  failed;
@@ -579,7 +579,7 @@ class Gn {
579
579
  running = !1;
580
580
  stopped = !1;
581
581
  set(e) {
582
- this.stopped || !Zt(e) || (this.latest = e, this.flush());
582
+ this.stopped || !cr(e) || (this.latest = e, this.flush());
583
583
  }
584
584
  stop() {
585
585
  this.stopped = !0, this.latest = void 0;
@@ -600,14 +600,14 @@ class Gn {
600
600
  }
601
601
  }
602
602
  }
603
- const jn = {
603
+ const on = {
604
604
  side: "Sleep/Wake",
605
605
  volumeUp: "Volume Up",
606
606
  volumeDown: "Volume Down"
607
607
  };
608
- class Xn {
609
- constructor(e, n) {
610
- this.send = e, this.failed = n;
608
+ class an {
609
+ constructor(e, r) {
610
+ this.send = e, this.failed = r;
611
611
  }
612
612
  send;
613
613
  failed;
@@ -623,155 +623,155 @@ class Xn {
623
623
  const e = this.held;
624
624
  this.held = void 0, this.enqueue(e, !1);
625
625
  }
626
- enqueue(e, n) {
627
- this.tail = this.tail.then(() => this.send(e, n)).catch(this.failed);
626
+ enqueue(e, r) {
627
+ this.tail = this.tail.then(() => this.send(e, r)).catch(this.failed);
628
628
  }
629
629
  }
630
- const ot = "Accessibility unavailable on this device.", Xe = 500, wt = (t, e) => Math.abs(t.x - e.x) < 0.5 && Math.abs(t.y - e.y) < 0.5 && Math.abs(t.width - e.width) < 0.5 && Math.abs(t.height - e.height) < 0.5, tn = (t) => Math.max(0, t.width) * Math.max(0, t.height), nn = (t) => {
631
- const e = t.find((n) => n.frame && n.frame.width > 0 && n.frame.height > 0);
630
+ const lt = "Accessibility unavailable on this device.", Ze = 500, Ut = (t, e) => Math.abs(t.x - e.x) < 0.5 && Math.abs(t.y - e.y) < 0.5 && Math.abs(t.width - e.width) < 0.5 && Math.abs(t.height - e.height) < 0.5, dr = (t) => Math.max(0, t.width) * Math.max(0, t.height), ur = (t) => {
631
+ const e = t.find((r) => r.frame && r.frame.width > 0 && r.frame.height > 0);
632
632
  return e?.frame ? ((Math.abs(e.frame.x) > 0.5 || Math.abs(e.frame.y) > 0.5) && console.warn(
633
633
  `[ax-tree] iOS root frame is not anchored at (0,0): (${e.frame.x},${e.frame.y}). Element positions may be slightly off from the rendered video.`
634
634
  ), { x: 0, y: 0, width: e.frame.width, height: e.frame.height }) : { x: 0, y: 0, width: 1, height: 1 };
635
- }, rn = (t) => {
635
+ }, fr = (t) => {
636
636
  const e = {};
637
637
  return typeof t.AXUniqueId == "string" && t.AXUniqueId.length > 0 && (e.AXUniqueId = t.AXUniqueId), typeof t.AXLabel == "string" && t.AXLabel.length > 0 && (e.AXLabel = t.AXLabel), typeof t.type == "string" && t.type.length > 0 && (e.className = t.type), e;
638
- }, on = (t) => {
638
+ }, Er = (t) => {
639
639
  const e = {};
640
- for (const [n, a] of Object.entries(t))
641
- n !== "children" && (e[n] = a);
640
+ for (const [r, o] of Object.entries(t))
641
+ r !== "children" && (e[r] = o);
642
642
  return e;
643
643
  };
644
- function an(t) {
645
- const e = Array.isArray(t) ? t : [t], n = nn(e), a = [], u = (l, i) => {
646
- if (a.length >= Xe) return;
647
- const E = l.frame;
648
- if (E && E.width > 0 && E.height > 0 && !wt(E, n)) {
649
- const m = l.role_description || l.role || "", S = (typeof l.AXLabel == "string" ? l.AXLabel : "") || (typeof l.title == "string" ? l.title : "") || "";
650
- a.push({
644
+ function hr(t) {
645
+ const e = Array.isArray(t) ? t : [t], r = ur(e), o = [], u = (l, i) => {
646
+ if (o.length >= Ze) return;
647
+ const h = l.frame;
648
+ if (h && h.width > 0 && h.height > 0 && !Ut(h, r)) {
649
+ const p = l.role_description || l.role || "", S = (typeof l.AXLabel == "string" ? l.AXLabel : "") || (typeof l.title == "string" ? l.title : "") || "";
650
+ o.push({
651
651
  id: typeof l.AXUniqueId == "string" && l.AXUniqueId.length > 0 ? l.AXUniqueId : i,
652
652
  path: i,
653
653
  label: S,
654
654
  value: typeof l.AXValue == "string" ? l.AXValue : "",
655
- role: m,
655
+ role: p,
656
656
  type: typeof l.type == "string" ? l.type : "",
657
657
  enabled: l.enabled !== !1,
658
658
  focused: l.focused === !0,
659
- frame: { x: E.x, y: E.y, width: E.width, height: E.height },
660
- selectors: rn(l),
661
- raw: on(l)
659
+ frame: { x: h.x, y: h.y, width: h.width, height: h.height },
660
+ selectors: fr(l),
661
+ raw: Er(l)
662
662
  });
663
663
  }
664
- const O = Array.isArray(l.children) ? l.children : [];
665
- for (let m = 0; m < O.length && a.length < Xe; m++)
666
- u(O[m], `${i}.${m}`);
664
+ const D = Array.isArray(l.children) ? l.children : [];
665
+ for (let p = 0; p < D.length && o.length < Ze; p++)
666
+ u(D[p], `${i}.${p}`);
667
667
  };
668
- for (let l = 0; l < e.length && a.length < Xe; l++)
668
+ for (let l = 0; l < e.length && o.length < Ze; l++)
669
669
  u(e[l], String(l));
670
670
  return {
671
671
  platform: "ios",
672
- screen: { width: n.width, height: n.height },
673
- elements: a,
672
+ screen: { width: r.width, height: r.height },
673
+ elements: o,
674
674
  capturedAt: Date.now()
675
675
  };
676
676
  }
677
- const sn = (t) => {
678
- let e = { x: 0, y: 0, width: 1, height: 1 }, n = 0;
679
- for (const a of t) {
680
- const u = a.parsedBounds;
677
+ const pr = (t) => {
678
+ let e = { x: 0, y: 0, width: 1, height: 1 }, r = 0;
679
+ for (const o of t) {
680
+ const u = o.parsedBounds;
681
681
  if (!u) continue;
682
- const l = u.right - u.left, i = u.bottom - u.top, E = Math.max(0, l) * Math.max(0, i);
683
- E > n && (n = E, e = { x: 0, y: 0, width: l, height: i });
682
+ const l = u.right - u.left, i = u.bottom - u.top, h = Math.max(0, l) * Math.max(0, i);
683
+ h > r && (r = h, e = { x: 0, y: 0, width: l, height: i });
684
684
  }
685
685
  return e;
686
- }, cn = (t) => {
686
+ }, mr = (t) => {
687
687
  const e = {};
688
688
  return typeof t.resourceId == "string" && t.resourceId.length > 0 && (e.resourceId = t.resourceId), typeof t.contentDesc == "string" && t.contentDesc.length > 0 && (e.contentDesc = t.contentDesc), typeof t.text == "string" && t.text.length > 0 && (e.text = t.text), typeof t.className == "string" && t.className.length > 0 && (e.className = t.className), e;
689
689
  };
690
- function ln(t) {
691
- const e = sn(t), n = [];
692
- for (let a = 0; a < t.length && n.length < Xe; a++) {
693
- const u = t[a], l = u.parsedBounds;
690
+ function Cr(t) {
691
+ const e = pr(t), r = [];
692
+ for (let o = 0; o < t.length && r.length < Ze; o++) {
693
+ const u = t[o], l = u.parsedBounds;
694
694
  if (!l) continue;
695
- const i = Math.max(0, l.right - l.left), E = Math.max(0, l.bottom - l.top);
696
- if (i <= 0 || E <= 0) continue;
697
- const O = { x: l.left, y: l.top, width: i, height: E };
698
- if (wt(O, { x: 0, y: 0, width: e.width, height: e.height })) continue;
699
- const m = u.contentDesc || u.text || "", S = u.className || "";
700
- n.push({
701
- id: u.resourceId && u.resourceId.length > 0 ? u.resourceId : u.contentDesc && u.contentDesc.length > 0 ? `cd:${u.contentDesc}` : String(a),
702
- path: String(a),
703
- label: m,
695
+ const i = Math.max(0, l.right - l.left), h = Math.max(0, l.bottom - l.top);
696
+ if (i <= 0 || h <= 0) continue;
697
+ const D = { x: l.left, y: l.top, width: i, height: h };
698
+ if (Ut(D, { x: 0, y: 0, width: e.width, height: e.height })) continue;
699
+ const p = u.contentDesc || u.text || "", S = u.className || "";
700
+ r.push({
701
+ id: u.resourceId && u.resourceId.length > 0 ? u.resourceId : u.contentDesc && u.contentDesc.length > 0 ? `cd:${u.contentDesc}` : String(o),
702
+ path: String(o),
703
+ label: p,
704
704
  value: typeof u.text == "string" ? u.text : "",
705
705
  role: S,
706
706
  type: S,
707
707
  enabled: u.enabled !== !1,
708
708
  focused: u.focused === !0,
709
- frame: O,
710
- selectors: cn(u),
709
+ frame: D,
710
+ selectors: mr(u),
711
711
  raw: { ...u }
712
712
  });
713
713
  }
714
714
  return {
715
715
  platform: "android",
716
716
  screen: { width: e.width, height: e.height },
717
- elements: n,
717
+ elements: r,
718
718
  capturedAt: Date.now()
719
719
  };
720
720
  }
721
- function Qn(t, e) {
722
- const n = Math.max(0, t.x), a = Math.max(0, t.y), u = Math.min(e.width, t.x + t.width), l = Math.min(e.height, t.y + t.height), i = Math.max(0, u - n), E = Math.max(0, l - a);
723
- return i > 0 && E > 0 ? { x: n, y: a, width: i, height: E } : null;
721
+ function sn(t, e) {
722
+ const r = Math.max(0, t.x), o = Math.max(0, t.y), u = Math.min(e.width, t.x + t.width), l = Math.min(e.height, t.y + t.height), i = Math.max(0, u - r), h = Math.max(0, l - o);
723
+ return i > 0 && h > 0 ? { x: r, y: o, width: i, height: h } : null;
724
724
  }
725
- function dn(t, e) {
725
+ function Or(t, e) {
726
726
  if (t === e) return !0;
727
727
  if (t.id !== e.id || t.path !== e.path || t.label !== e.label || t.value !== e.value || t.role !== e.role || t.type !== e.type || t.enabled !== e.enabled || t.focused !== e.focused) return !1;
728
- const n = t.frame, a = e.frame;
729
- return n.x === a.x && n.y === a.y && n.width === a.width && n.height === a.height;
728
+ const r = t.frame, o = e.frame;
729
+ return r.x === o.x && r.y === o.y && r.width === o.width && r.height === o.height;
730
730
  }
731
- function un(t, e) {
731
+ function Dr(t, e) {
732
732
  if (t === e) return !0;
733
733
  if (!t || !e || t.platform !== e.platform || t.screen.width !== e.screen.width || t.screen.height !== e.screen.height || t.elements.length !== e.elements.length) return !1;
734
- for (let n = 0; n < t.elements.length; n++)
735
- if (!dn(t.elements[n], e.elements[n])) return !1;
734
+ for (let r = 0; r < t.elements.length; r++)
735
+ if (!Or(t.elements[r], e.elements[r])) return !1;
736
736
  return !0;
737
737
  }
738
- function zn(t, e, n) {
739
- let a = null, u = 1 / 0;
738
+ function cn(t, e, r) {
739
+ let o = null, u = 1 / 0;
740
740
  for (const l of t.elements) {
741
741
  const i = l.frame;
742
- if (e < i.x || n < i.y || e > i.x + i.width || n > i.y + i.height) continue;
743
- const E = tn(i);
744
- E < u && (u = E, a = l);
742
+ if (e < i.x || r < i.y || e > i.x + i.width || r > i.y + i.height) continue;
743
+ const h = dr(i);
744
+ h < u && (u = h, o = l);
745
745
  }
746
- return a;
746
+ return o;
747
747
  }
748
- function Zn(t, e) {
748
+ function ln(t, e) {
749
749
  if (e === "ios") {
750
750
  if (t.selectors.AXUniqueId)
751
751
  return `client.tapElement({ AXUniqueId: ${JSON.stringify(t.selectors.AXUniqueId)} })`;
752
752
  if (t.selectors.AXLabel) {
753
- const n = t.selectors.className ? `, type: ${JSON.stringify(t.selectors.className)}` : "";
754
- return `client.tapElement({ AXLabel: ${JSON.stringify(t.selectors.AXLabel)}${n} })`;
753
+ const r = t.selectors.className ? `, type: ${JSON.stringify(t.selectors.className)}` : "";
754
+ return `client.tapElement({ AXLabel: ${JSON.stringify(t.selectors.AXLabel)}${r} })`;
755
755
  }
756
756
  return null;
757
757
  }
758
758
  return t.selectors.resourceId ? `client.tap({ selector: { resourceId: ${JSON.stringify(t.selectors.resourceId)} } })` : t.selectors.contentDesc ? `client.tap({ selector: { contentDesc: ${JSON.stringify(t.selectors.contentDesc)} } })` : t.selectors.text ? `client.tap({ selector: { text: ${JSON.stringify(t.selectors.text)} } })` : null;
759
759
  }
760
- function fn(t) {
760
+ function _r(t) {
761
761
  const e = t.role || t.type || "";
762
762
  if (!e) return "element";
763
- let n = e.replace(/^AX/, "");
764
- return n.includes(".") && (n = n.split(".").pop()), n === "GenericElement" ? "Element" : (n = n.replace(/([a-z])([A-Z])/g, "$1 $2"), n);
763
+ let r = e.replace(/^AX/, "");
764
+ return r.includes(".") && (r = r.split(".").pop()), r === "GenericElement" ? "Element" : (r = r.replace(/([a-z])([A-Z])/g, "$1 $2"), r);
765
765
  }
766
- const yt = 80;
767
- function er(t) {
768
- const e = fn(t), n = t.label || t.value || "";
769
- if (!n) return e;
770
- const a = n.length > yt ? n.slice(0, yt).trimEnd() + "…" : n;
771
- return `${e} · ${a}`;
766
+ const wt = 80;
767
+ function dn(t) {
768
+ const e = _r(t), r = t.label || t.value || "";
769
+ if (!r) return e;
770
+ const o = r.length > wt ? r.slice(0, wt).trimEnd() + "…" : r;
771
+ return `${e} · ${o}`;
772
772
  }
773
- const En = 500, hn = 2e3, St = 5e3, mn = 8e3, pn = 1200, Cn = 250, On = () => `ax-rc-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
774
- class Dn {
773
+ const gr = 500, Tr = 2e3, Nt = 5e3, yr = 8e3, Sr = 1200, Kr = 250, Ar = () => `ax-rc-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
774
+ class vr {
775
775
  platform;
776
776
  send;
777
777
  onSnapshot;
@@ -798,7 +798,7 @@ class Dn {
798
798
  // identical-to-current transitions are no-ops.
799
799
  status = "idle";
800
800
  constructor(e) {
801
- this.platform = e.platform, this.send = e.send, this.onSnapshot = e.onSnapshot, this.onStatusChange = e.onStatusChange, this.baseIntervalMs = e.baseIntervalMs ?? En, this.maxBackoffMs = e.maxBackoffMs ?? hn, this.androidElementTreeOptions = e.androidElementTreeOptions, this.currentInterval = this.baseIntervalMs;
801
+ this.platform = e.platform, this.send = e.send, this.onSnapshot = e.onSnapshot, this.onStatusChange = e.onStatusChange, this.baseIntervalMs = e.baseIntervalMs ?? gr, this.maxBackoffMs = e.maxBackoffMs ?? Tr, this.androidElementTreeOptions = e.androidElementTreeOptions, this.currentInterval = this.baseIntervalMs;
802
802
  }
803
803
  start() {
804
804
  this.running || (this.running = !0, this.currentInterval = this.baseIntervalMs, this.boostUntilMs = 0, this.setStatus("starting"), this.runOnce());
@@ -809,12 +809,12 @@ class Dn {
809
809
  getStatus() {
810
810
  return this.status;
811
811
  }
812
- setStatus(e, n) {
812
+ setStatus(e, r) {
813
813
  if (this.status !== e && (this.status = e, !!this.onStatusChange))
814
814
  try {
815
- this.onStatusChange(e, n);
816
- } catch (a) {
817
- console.error("[AxFetcher] onStatusChange threw:", a);
815
+ this.onStatusChange(e, r);
816
+ } catch (o) {
817
+ console.error("[AxFetcher] onStatusChange threw:", o);
818
818
  }
819
819
  }
820
820
  // Called after any user-driven action that's likely to change the UI
@@ -830,9 +830,9 @@ class Dn {
830
830
  bumpActivity() {
831
831
  if (!this.running) return;
832
832
  const e = Date.now();
833
- this.boostUntilMs = e + pn;
834
- const n = Math.max(150, Math.floor(this.baseIntervalMs / 2));
835
- if (e - this.lastBumpAtMs < n) {
833
+ this.boostUntilMs = e + Sr;
834
+ const r = Math.max(150, Math.floor(this.baseIntervalMs / 2));
835
+ if (e - this.lastBumpAtMs < r) {
836
836
  this.currentInterval = this.baseIntervalMs;
837
837
  return;
838
838
  }
@@ -858,34 +858,34 @@ class Dn {
858
858
  // Returns true when the message was a response we were waiting for.
859
859
  handleMessage(e) {
860
860
  if (!e || typeof e.id != "string") return !1;
861
- const n = e.id;
862
- if (!this.pending.get(n)) return !1;
861
+ const r = e.id;
862
+ if (!this.pending.get(r)) return !1;
863
863
  if (this.platform === "ios") {
864
864
  if (e.type !== "elementTreeResult") return !1;
865
- const E = typeof e.error == "string" ? e.error : null;
866
- if (E)
867
- return this.settleReject(n, new Error(E)), !0;
868
- const O = typeof e.json == "string" ? e.json : "";
865
+ const h = typeof e.error == "string" ? e.error : null;
866
+ if (h)
867
+ return this.settleReject(r, new Error(h)), !0;
868
+ const D = typeof e.json == "string" ? e.json : "";
869
869
  try {
870
- const m = JSON.parse(O), S = an(m);
871
- this.settleResolve(n, S);
872
- } catch (m) {
873
- this.settleReject(n, m instanceof Error ? m : new Error(String(m)));
870
+ const p = JSON.parse(D), S = hr(p);
871
+ this.settleResolve(r, S);
872
+ } catch (p) {
873
+ this.settleReject(r, p instanceof Error ? p : new Error(String(p)));
874
874
  }
875
875
  return !0;
876
876
  }
877
877
  if (e.type !== "getElementTreeResult") return !1;
878
878
  const u = e.error;
879
879
  if (u && typeof u == "object") {
880
- const E = typeof u.message == "string" ? u.message : "getElementTree failed";
881
- return this.settleReject(n, new Error(E)), !0;
880
+ const h = typeof u.message == "string" ? u.message : "getElementTree failed";
881
+ return this.settleReject(r, new Error(h)), !0;
882
882
  }
883
883
  const l = e.payload, i = Array.isArray(l?.nodes) ? l.nodes : [];
884
884
  try {
885
- const E = ln(i);
886
- this.settleResolve(n, E);
887
- } catch (E) {
888
- this.settleReject(n, E instanceof Error ? E : new Error(String(E)));
885
+ const h = Cr(i);
886
+ this.settleResolve(r, h);
887
+ } catch (h) {
888
+ this.settleReject(r, h instanceof Error ? h : new Error(String(h)));
889
889
  }
890
890
  return !0;
891
891
  }
@@ -893,15 +893,15 @@ class Dn {
893
893
  return this.platform === "ios" ? { type: "elementTree", id: e } : { type: "getElementTree", id: e, ...this.androidElementTreeOptions };
894
894
  }
895
895
  async requestOnce() {
896
- const e = On();
897
- return new Promise((n, a) => {
896
+ const e = Ar();
897
+ return new Promise((r, o) => {
898
898
  const u = window.setTimeout(
899
899
  () => {
900
- this.pending.delete(e), a(new Error("elementTree request timed out"));
900
+ this.pending.delete(e), o(new Error("elementTree request timed out"));
901
901
  },
902
- mn + (this.androidElementTreeOptions?.waitForIdleTimeoutMs ?? 0)
902
+ yr + (this.androidElementTreeOptions?.waitForIdleTimeoutMs ?? 0)
903
903
  );
904
- this.pending.set(e, { resolve: n, reject: a, timer: u }), this.send(this.buildRequest(e)) || (window.clearTimeout(u), this.pending.delete(e), a(new Error("elementTree send failed (WebSocket not open)")));
904
+ this.pending.set(e, { resolve: r, reject: o, timer: u }), this.send(this.buildRequest(e)) || (window.clearTimeout(u), this.pending.delete(e), o(new Error("elementTree send failed (WebSocket not open)")));
905
905
  });
906
906
  }
907
907
  async runOnce() {
@@ -913,197 +913,197 @@ class Dn {
913
913
  this.deliver(e);
914
914
  } catch (e) {
915
915
  if (!this.running) return;
916
- const n = e instanceof Error ? e.message : String(e), a = /unavailable|not (yet )?running|failed|timeout/i.test(n);
917
- this.currentInterval = a ? St : Math.min(this.currentInterval * 2, this.maxBackoffMs), this.setStatus(a ? "unavailable" : "error", n);
916
+ const r = e instanceof Error ? e.message : String(e), o = /unavailable|not (yet )?running|failed|timeout/i.test(r);
917
+ this.currentInterval = o ? Nt : Math.min(this.currentInterval * 2, this.maxBackoffMs), this.setStatus(o ? "unavailable" : "error", r);
918
918
  } finally {
919
919
  this.inflight = !1, this.scheduleNext();
920
920
  }
921
921
  }
922
922
  }
923
923
  deliver(e) {
924
- const n = this.lastSnapshot;
925
- if (un(n, e)) {
926
- this.currentInterval = Math.min(this.currentInterval * 2, this.maxBackoffMs), this.lastSnapshot = e, e.errors?.includes(ot) || this.setStatus("ready");
924
+ const r = this.lastSnapshot;
925
+ if (Dr(r, e)) {
926
+ this.currentInterval = Math.min(this.currentInterval * 2, this.maxBackoffMs), this.lastSnapshot = e, e.errors?.includes(lt) || this.setStatus("ready");
927
927
  return;
928
928
  }
929
- this.lastSnapshot = e, this.currentInterval = this.baseIntervalMs, e.errors?.includes(ot) ? (this.currentInterval = St, this.setStatus("unavailable", ot)) : this.setStatus("ready"), this.onSnapshot(e);
929
+ this.lastSnapshot = e, this.currentInterval = this.baseIntervalMs, e.errors?.includes(lt) ? (this.currentInterval = Nt, this.setStatus("unavailable", lt)) : this.setStatus("ready"), this.onSnapshot(e);
930
930
  }
931
931
  scheduleNext() {
932
932
  if (!this.running) return;
933
933
  this.timer !== void 0 && window.clearTimeout(this.timer);
934
- const e = Date.now() < this.boostUntilMs ? Math.min(Cn, this.currentInterval) : this.currentInterval;
934
+ const e = Date.now() < this.boostUntilMs ? Math.min(Kr, this.currentInterval) : this.currentInterval;
935
935
  this.timer = window.setTimeout(() => {
936
936
  this.timer = void 0, this.runOnce();
937
937
  }, e);
938
938
  }
939
- settleResolve(e, n) {
940
- const a = this.pending.get(e);
941
- a && (window.clearTimeout(a.timer), this.pending.delete(e), a.resolve(n));
939
+ settleResolve(e, r) {
940
+ const o = this.pending.get(e);
941
+ o && (window.clearTimeout(o.timer), this.pending.delete(e), o.resolve(r));
942
942
  }
943
- settleReject(e, n) {
944
- const a = this.pending.get(e);
945
- a && (window.clearTimeout(a.timer), this.pending.delete(e), a.reject(n));
943
+ settleReject(e, r) {
944
+ const o = this.pending.get(e);
945
+ o && (window.clearTimeout(o.timer), this.pending.delete(e), o.reject(r));
946
946
  }
947
947
  failAllPending(e) {
948
- for (const [n, a] of this.pending.entries())
949
- window.clearTimeout(a.timer), a.reject(new Error(e)), this.pending.delete(n);
948
+ for (const [r, o] of this.pending.entries())
949
+ window.clearTimeout(o.timer), o.reject(new Error(e)), this.pending.delete(r);
950
950
  }
951
951
  }
952
- function Kt(t, e) {
952
+ function bt(t, e) {
953
953
  if (e != null && (!Number.isFinite(e) || e < 0 || e > 4e3)) {
954
954
  console.warn("RemoteControl: jitterBufferTargetMs must be a finite number between 0 and 4000.");
955
955
  return;
956
956
  }
957
957
  if (!("jitterBufferTarget" in t)) return;
958
- const n = e ?? null;
958
+ const r = e ?? null;
959
959
  try {
960
- t.jitterBufferTarget !== n && (t.jitterBufferTarget = n);
961
- } catch (a) {
962
- console.warn("RemoteControl: could not set the jitter buffer target.", a);
960
+ t.jitterBufferTarget !== r && (t.jitterBufferTarget = r);
961
+ } catch (o) {
962
+ console.warn("RemoteControl: could not set the jitter buffer target.", o);
963
963
  }
964
964
  }
965
- const Nt = `(function(){"use strict";let e,t;self.onmessage=async({data:s})=>{s.type==="start"?(e=new AbortController,t=s.readable.pipeTo(s.writable,{signal:e.signal}).catch(o=>{e?.signal.aborted||self.postMessage({type:"error",message:String(o)})})):s.type==="stop"&&(e?.abort(),await t,self.postMessage({type:"stopped"}),self.close())}})();
966
- `, At = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", Nt], { type: "text/javascript;charset=utf-8" });
967
- function _n(t) {
965
+ const Pt = `(function(){"use strict";let e,t;self.onmessage=async({data:s})=>{s.type==="start"?(e=new AbortController,t=s.readable.pipeTo(s.writable,{signal:e.signal}).catch(o=>{e?.signal.aborted||self.postMessage({type:"error",message:String(o)})})):s.type==="stop"&&(e?.abort(),await t,self.postMessage({type:"stopped"}),self.close())}})();
966
+ `, Yt = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", Pt], { type: "text/javascript;charset=utf-8" });
967
+ function Mr(t) {
968
968
  let e;
969
969
  try {
970
- if (e = At && (self.URL || self.webkitURL).createObjectURL(At), !e) throw "";
971
- const n = new Worker(e, {
970
+ if (e = Yt && (self.URL || self.webkitURL).createObjectURL(Yt), !e) throw "";
971
+ const r = new Worker(e, {
972
972
  name: t?.name
973
973
  });
974
- return n.addEventListener("error", () => {
974
+ return r.addEventListener("error", () => {
975
975
  (self.URL || self.webkitURL).revokeObjectURL(e);
976
- }), n;
976
+ }), r;
977
977
  } catch {
978
978
  return new Worker(
979
- "data:text/javascript;charset=utf-8," + encodeURIComponent(Nt),
979
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(Pt),
980
980
  {
981
981
  name: t?.name
982
982
  }
983
983
  );
984
984
  }
985
985
  }
986
- function gn(t, e, n) {
987
- const { MediaStreamTrackProcessor: a, MediaStreamTrackGenerator: u } = globalThis, l = e.getVideoTracks()[0];
988
- let i, E, O, m, S = !1;
986
+ function wr(t, e, r) {
987
+ const { MediaStreamTrackProcessor: o, MediaStreamTrackGenerator: u } = globalThis, l = e.getVideoTracks()[0];
988
+ let i, h, D, p, S = !1;
989
989
  const w = () => {
990
- S || (S = !0, i?.stop(), E?.stop(), O && (O.postMessage({ type: "stop" }), m = setTimeout(() => O?.terminate(), 1e3)));
991
- }, N = (D) => {
992
- t.srcObject = D, t.play().catch(() => {
990
+ S || (S = !0, i?.stop(), h?.stop(), D && (D.postMessage({ type: "stop" }), p = setTimeout(() => D?.terminate(), 1e3)));
991
+ }, N = (_) => {
992
+ t.srcObject = _, t.play().catch(() => {
993
993
  });
994
- }, q = (D) => {
995
- S || (w(), n(D), N(e));
994
+ }, V = (_) => {
995
+ S || (w(), r(_), N(e));
996
996
  };
997
997
  try {
998
- if (l && a && u) {
998
+ if (l && o && u) {
999
999
  i = l.clone();
1000
- const D = new a({ track: i, maxBufferSize: 1 }), H = new u({ kind: "video" });
1001
- E = H, O = new _n(), O.onmessage = ({ data: L }) => {
1002
- L.type === "error" ? q(new Error(L.message)) : L.type === "stopped" && (clearTimeout(m), O?.terminate());
1003
- }, O.onerror = (L) => q(new Error(L.message)), O.postMessage({ type: "start", readable: D.readable, writable: H.writable }, [
1004
- D.readable,
1000
+ const _ = new o({ track: i, maxBufferSize: 1 }), H = new u({ kind: "video" });
1001
+ h = H, D = new Mr(), D.onmessage = ({ data: L }) => {
1002
+ L.type === "error" ? V(new Error(L.message)) : L.type === "stopped" && (clearTimeout(p), D?.terminate());
1003
+ }, D.onerror = (L) => V(new Error(L.message)), D.postMessage({ type: "start", readable: _.readable, writable: H.writable }, [
1004
+ _.readable,
1005
1005
  H.writable
1006
1006
  ]), N(new MediaStream(e.getTracks().map((L) => L === l ? H : L)));
1007
1007
  } else
1008
1008
  N(e);
1009
- } catch (D) {
1010
- q(D);
1009
+ } catch (_) {
1010
+ V(_);
1011
1011
  }
1012
1012
  return w;
1013
1013
  }
1014
- function Re(t) {
1014
+ function Pe(t) {
1015
1015
  return typeof t == "number" && Number.isFinite(t);
1016
1016
  }
1017
- function Te(t, e) {
1018
- if (!(!Re(t) || !Re(e) || t < e || e < 0))
1017
+ function Se(t, e) {
1018
+ if (!(!Pe(t) || !Pe(e) || t < e || e < 0))
1019
1019
  return t - e;
1020
1020
  }
1021
- class Tn {
1021
+ class Nr {
1022
1022
  previous = /* @__PURE__ */ new Map();
1023
1023
  reset() {
1024
1024
  this.previous.clear();
1025
1025
  }
1026
- read(e, n, a) {
1026
+ read(e, r, o) {
1027
1027
  const u = { timestamp: 0, video: [], audio: [] };
1028
- a == null ? u.requestedTargetMs = null : Re(a) && a >= 0 && a <= 4e3 && (u.requestedTargetMs = a);
1028
+ o == null ? u.requestedTargetMs = null : Pe(o) && o >= 0 && o <= 4e3 && (u.requestedTargetMs = o);
1029
1029
  const l = /* @__PURE__ */ new Map();
1030
1030
  return e.forEach((i) => {
1031
- if (i.type !== "inbound-rtp" || !Re(i.timestamp)) return;
1032
- const E = i.kind ?? i.mediaType;
1033
- if (E !== "video" && E !== "audio") return;
1034
- const O = n.filter((P) => P.kind === E), m = i.trackIdentifier ? O.find((P) => P.trackId === i.trackIdentifier) : i.mid != null ? O.find((P) => P.mid === i.mid) : O.length === 1 ? O[0] : void 0;
1035
- if (!m) return;
1036
- const S = this.previous.get(i.id), N = S?.trackId === m.trackId && S.stats.ssrc === i.ssrc ? S.stats : void 0, q = N ? i.timestamp - N.timestamp : void 0, D = {
1031
+ if (i.type !== "inbound-rtp" || !Pe(i.timestamp)) return;
1032
+ const h = i.kind ?? i.mediaType;
1033
+ if (h !== "video" && h !== "audio") return;
1034
+ const D = r.filter((P) => P.kind === h), p = i.trackIdentifier ? D.find((P) => P.trackId === i.trackIdentifier) : i.mid != null ? D.find((P) => P.mid === i.mid) : D.length === 1 ? D[0] : void 0;
1035
+ if (!p) return;
1036
+ const S = this.previous.get(i.id), N = S?.trackId === p.trackId && S.stats.ssrc === i.ssrc ? S.stats : void 0, V = N ? i.timestamp - N.timestamp : void 0, _ = {
1037
1037
  id: i.id,
1038
- trackId: m.trackId,
1038
+ trackId: p.trackId,
1039
1039
  timestamp: i.timestamp
1040
1040
  };
1041
- if (q !== void 0 && q > 0) {
1042
- D.intervalMs = q;
1043
- const P = Te(i.jitterBufferEmittedCount, N?.jitterBufferEmittedCount), B = Te(i.jitterBufferDelay, N?.jitterBufferDelay);
1044
- P !== void 0 && P > 0 && B !== void 0 && (D.bufferDelayMs = B / P * 1e3);
1045
- const V = Te(i.bytesReceived, N?.bytesReceived);
1046
- V !== void 0 && (D.bitrateBps = V * 8e3 / q);
1041
+ if (V !== void 0 && V > 0) {
1042
+ _.intervalMs = V;
1043
+ const P = Se(i.jitterBufferEmittedCount, N?.jitterBufferEmittedCount), B = Se(i.jitterBufferDelay, N?.jitterBufferDelay);
1044
+ P !== void 0 && P > 0 && B !== void 0 && (_.bufferDelayMs = B / P * 1e3);
1045
+ const x = Se(i.bytesReceived, N?.bytesReceived);
1046
+ x !== void 0 && (_.bitrateBps = x * 8e3 / V);
1047
1047
  }
1048
- if (E === "video") {
1049
- const P = { ...D, display: m.display ?? "primary" };
1050
- if (D.intervalMs !== void 0) {
1051
- const B = Te(i.framesDecoded, N?.framesDecoded);
1052
- B !== void 0 && (P.fps = B * 1e3 / D.intervalMs), P.droppedFrames = Te(i.framesDropped, N?.framesDropped), P.freezes = Te(i.freezeCount, N?.freezeCount);
1048
+ if (h === "video") {
1049
+ const P = { ..._, display: p.display ?? "primary" };
1050
+ if (_.intervalMs !== void 0) {
1051
+ const B = Se(i.framesDecoded, N?.framesDecoded);
1052
+ B !== void 0 && (P.fps = B * 1e3 / _.intervalMs), P.droppedFrames = Se(i.framesDropped, N?.framesDropped), P.freezes = Se(i.freezeCount, N?.freezeCount);
1053
1053
  }
1054
1054
  u.video.push(P);
1055
- } else u.audio.push(D);
1055
+ } else u.audio.push(_);
1056
1056
  u.timestamp = Math.max(u.timestamp, i.timestamp), l.set(
1057
1057
  i.id,
1058
- N && i.timestamp <= N.timestamp ? S : { stats: i, trackId: m.trackId }
1058
+ N && i.timestamp <= N.timestamp ? S : { stats: i, trackId: p.trackId }
1059
1059
  );
1060
1060
  const H = i.transportId ? e.get(i.transportId) : void 0, L = H?.selectedCandidatePairId ? e.get(H.selectedCandidatePairId) : void 0;
1061
- L?.state === "succeeded" && Re(L.currentRoundTripTime) && L.currentRoundTripTime >= 0 && (u.rttMs = L.currentRoundTripTime * 1e3);
1061
+ L?.state === "succeeded" && Pe(L.currentRoundTripTime) && L.currentRoundTripTime >= 0 && (u.rttMs = L.currentRoundTripTime * 1e3);
1062
1062
  }), this.previous = l, u.video.length || u.audio.length ? u : null;
1063
1063
  }
1064
1064
  }
1065
- const at = /* @__PURE__ */ new WeakSet();
1066
- function yn(t, e, n) {
1067
- const { peer: a, displays: u } = t, l = new Tn();
1068
- let i, E = !1, O = !1, m = !1, S = 0, w = !1, N = !1;
1069
- const q = () => !E && !document.hidden && a.connectionState === "connected", D = (B) => {
1065
+ const dt = /* @__PURE__ */ new WeakSet();
1066
+ function br(t, e, r) {
1067
+ const { peer: o, displays: u } = t, l = new Nr();
1068
+ let i, h = !1, D = !1, p = !1, S = 0, w = !1, N = !1;
1069
+ const V = () => !h && !document.hidden && o.connectionState === "connected", _ = (B) => {
1070
1070
  if (!(!B && !w)) {
1071
1071
  w = B !== null;
1072
1072
  try {
1073
1073
  e()?.(B);
1074
- } catch (V) {
1075
- console.error('[RemoteControl] customer callback "onPlaybackStats" threw:', V);
1074
+ } catch (x) {
1075
+ console.error('[RemoteControl] customer callback "onPlaybackStats" threw:', x);
1076
1076
  }
1077
1077
  }
1078
1078
  }, H = () => {
1079
- O = !1, S++, clearTimeout(i), l.reset(), D(null);
1079
+ D = !1, S++, clearTimeout(i), l.reset(), _(null);
1080
1080
  }, L = async () => {
1081
- if (m || !q()) return;
1082
- if (at.has(a)) {
1081
+ if (p || !V()) return;
1082
+ if (dt.has(o)) {
1083
1083
  i = setTimeout(() => {
1084
1084
  L();
1085
1085
  }, 2e3);
1086
1086
  return;
1087
1087
  }
1088
- m = !0, at.add(a);
1088
+ p = !0, dt.add(o);
1089
1089
  const B = S;
1090
1090
  try {
1091
- const V = await a.getStats();
1092
- if (B !== S || !q()) return;
1093
- const se = a.getTransceivers().filter(
1094
- (Y) => (Y.currentDirection === "recvonly" || Y.currentDirection === "sendrecv") && Y.receiver.track.readyState !== "ended"
1095
- ).map((Y) => ({
1096
- trackId: Y.receiver.track.id,
1097
- kind: Y.receiver.track.kind,
1098
- mid: Y.mid,
1099
- display: u.get(Y.receiver)
1091
+ const x = await o.getStats();
1092
+ if (B !== S || !V()) return;
1093
+ const se = o.getTransceivers().filter(
1094
+ (I) => (I.currentDirection === "recvonly" || I.currentDirection === "sendrecv") && I.receiver.track.readyState !== "ended"
1095
+ ).map((I) => ({
1096
+ trackId: I.receiver.track.id,
1097
+ kind: I.receiver.track.kind,
1098
+ mid: I.mid,
1099
+ display: u.get(I.receiver)
1100
1100
  }));
1101
- D(l.read(V, se, n())), N = !1;
1102
- } catch (V) {
1103
- if (B !== S || !q()) return;
1104
- N || console.warn("[RemoteControl] could not read playback stats:", V), N = !0, l.reset(), D(null);
1101
+ _(l.read(x, se, r())), N = !1;
1102
+ } catch (x) {
1103
+ if (B !== S || !V()) return;
1104
+ N || console.warn("[RemoteControl] could not read playback stats:", x), N = !0, l.reset(), _(null);
1105
1105
  } finally {
1106
- m = !1, at.delete(a), O && q() && (i = setTimeout(
1106
+ p = !1, dt.delete(o), D && V() && (i = setTimeout(
1107
1107
  () => {
1108
1108
  L();
1109
1109
  },
@@ -1111,60 +1111,60 @@ function yn(t, e, n) {
1111
1111
  ));
1112
1112
  }
1113
1113
  }, P = () => {
1114
- if (!q()) {
1114
+ if (!V()) {
1115
1115
  H();
1116
1116
  return;
1117
1117
  }
1118
- O || (O = !0, L());
1118
+ D || (D = !0, L());
1119
1119
  };
1120
- return document.addEventListener("visibilitychange", P), a.addEventListener("connectionstatechange", P), P(), () => {
1121
- E = !0, document.removeEventListener("visibilitychange", P), a.removeEventListener("connectionstatechange", P), H();
1120
+ return document.addEventListener("visibilitychange", P), o.addEventListener("connectionstatechange", P), P(), () => {
1121
+ h = !0, document.removeEventListener("visibilitychange", P), o.removeEventListener("connectionstatechange", P), H();
1122
1122
  };
1123
1123
  }
1124
- function Sn(t, e) {
1125
- const n = t.createDataChannel("latency-trace-v1", {
1124
+ function Yr(t, e) {
1125
+ const r = t.createDataChannel("latency-trace-v1", {
1126
1126
  ordered: !0,
1127
1127
  negotiated: !0,
1128
1128
  id: 2
1129
1129
  });
1130
- let a = !1, u = !1, l = 0;
1131
- return n.onmessage = (i) => {
1130
+ let o = !1, u = !1, l = 0;
1131
+ return r.onmessage = (i) => {
1132
1132
  if (u) return;
1133
- let E;
1133
+ let h;
1134
1134
  try {
1135
- E = JSON.parse(i.data);
1136
- } catch (O) {
1137
- console.warn("Invalid latency trace message", O);
1135
+ h = JSON.parse(i.data);
1136
+ } catch (D) {
1137
+ console.warn("Invalid latency trace message", D);
1138
1138
  return;
1139
1139
  }
1140
- E && typeof E == "object" && !Array.isArray(E) && e(E);
1141
- }, n.onclose = () => {
1142
- u = !0, a = !1;
1140
+ h && typeof h == "object" && !Array.isArray(h) && e(h);
1141
+ }, r.onclose = () => {
1142
+ u = !0, o = !1;
1143
1143
  }, {
1144
1144
  accept(i) {
1145
- a = !u && i === 1;
1145
+ o = !u && i === 1;
1146
1146
  },
1147
1147
  wrap(i) {
1148
- if (!a || i.byteLength === 0) return i;
1149
- const E = new DataView(i), O = E.getUint8(0), m = O === ee.INJECT_MOUSE_EVENT || O === ee.INJECT_MAC_KEY || O === ee.INJECT_MAC_SCROLL, S = i.byteLength === 32 && O === ee.INJECT_TOUCH_EVENT && E.getUint8(1) <= 2;
1150
- if (!m && !S) return i;
1148
+ if (!o || i.byteLength === 0) return i;
1149
+ const h = new DataView(i), D = h.getUint8(0), p = D === ee.INJECT_MOUSE_EVENT || D === ee.INJECT_MAC_KEY || D === ee.INJECT_MAC_SCROLL, S = i.byteLength === 32 && D === ee.INJECT_TOUCH_EVENT && h.getUint8(1) <= 2;
1150
+ if (!p && !S) return i;
1151
1151
  const w = new ArrayBuffer(6 + i.byteLength), N = new DataView(w);
1152
1152
  return N.setUint8(0, 240), N.setUint8(1, 1), N.setUint32(2, ++l, !0), new Uint8Array(w, 6).set(new Uint8Array(i)), w;
1153
1153
  },
1154
1154
  close() {
1155
- u = !0, a = !1, n.onmessage = null, n.onclose = null, n.close();
1155
+ u = !0, o = !1, r.onmessage = null, r.onclose = null, r.close();
1156
1156
  }
1157
1157
  };
1158
1158
  }
1159
- class Kn {
1159
+ class Ir {
1160
1160
  generation = 0;
1161
1161
  tail = Promise.resolve();
1162
1162
  get currentGeneration() {
1163
1163
  return this.generation;
1164
1164
  }
1165
1165
  enqueue(e) {
1166
- const n = ++this.generation;
1167
- return this.append(n, e);
1166
+ const r = ++this.generation;
1167
+ return this.append(r, e);
1168
1168
  }
1169
1169
  /**
1170
1170
  * Queues related work without superseding an already queued request.
@@ -1175,11 +1175,11 @@ class Kn {
1175
1175
  enqueueCurrent(e) {
1176
1176
  return this.append(this.generation, e);
1177
1177
  }
1178
- append(e, n) {
1179
- const a = {
1178
+ append(e, r) {
1179
+ const o = {
1180
1180
  generation: e,
1181
1181
  isCurrent: () => e === this.generation
1182
- }, u = this.tail.then(() => n(a));
1182
+ }, u = this.tail.then(() => r(o));
1183
1183
  return this.tail = u.catch(() => {
1184
1184
  }), u;
1185
1185
  }
@@ -1187,23 +1187,23 @@ class Kn {
1187
1187
  ++this.generation;
1188
1188
  }
1189
1189
  }
1190
- function An(t) {
1190
+ function Rr(t) {
1191
1191
  if (!t || typeof t != "object") return null;
1192
1192
  const e = t;
1193
1193
  if (e.type !== "cameraRequest" || typeof e.active != "boolean") return null;
1194
- const n = { active: e.active };
1195
- return (e.facingMode === "user" || e.facingMode === "environment") && (n.facingMode = e.facingMode), n;
1194
+ const r = { active: e.active };
1195
+ return (e.facingMode === "user" || e.facingMode === "environment") && (r.facingMode = e.facingMode), r;
1196
1196
  }
1197
- function Mn(t) {
1197
+ function kr(t) {
1198
1198
  const e = {
1199
1199
  frameRate: { ideal: 30, max: 30 }
1200
1200
  };
1201
1201
  return t?.facingMode && (e.facingMode = { ideal: t.facingMode }), e;
1202
1202
  }
1203
- function vn(t, e) {
1203
+ function Ur(t, e) {
1204
1204
  return !t || t.facingMode !== e.facingMode;
1205
1205
  }
1206
- function wn(t) {
1206
+ function Pr(t) {
1207
1207
  const e = t.getSettings();
1208
1208
  return {
1209
1209
  width: e.width,
@@ -1214,78 +1214,110 @@ function wn(t) {
1214
1214
  facingMode: e.facingMode
1215
1215
  };
1216
1216
  }
1217
- function Nn(t) {
1217
+ function Lr(t) {
1218
1218
  return {
1219
1219
  type: "cameraResult",
1220
1220
  granted: !0,
1221
- camera: wn(t)
1221
+ camera: Pr(t)
1222
1222
  };
1223
1223
  }
1224
1224
  const le = (...t) => {
1225
1225
  window.debugRemoteControl && console.log(...t);
1226
1226
  }, y = (...t) => {
1227
1227
  window.debugRemoteControl && console.warn(...t);
1228
- }, F = (t, e, ...n) => {
1228
+ }, It = ["click", "keydown"], et = /* @__PURE__ */ new WeakMap(), Fr = (t) => {
1229
+ et.get(t)?.();
1230
+ }, Lt = (t, e) => {
1231
+ if (et.has(t)) {
1232
+ Promise.resolve(t.play()).catch(() => {
1233
+ });
1234
+ return;
1235
+ }
1236
+ Promise.resolve(t.play()).catch((r) => {
1237
+ if (r?.name !== "NotAllowedError" || t.muted) return;
1238
+ t.muted = !0, Promise.resolve(t.play()).catch(() => {
1239
+ });
1240
+ const o = t.ownerDocument, u = () => {
1241
+ l(), t.muted = !1, Lt(t, e);
1242
+ }, l = () => {
1243
+ for (const i of It) o.removeEventListener(i, u, !0);
1244
+ et.delete(t);
1245
+ };
1246
+ for (const i of It) o.addEventListener(i, u, !0);
1247
+ et.set(t, l), e();
1248
+ });
1249
+ }, F = (t, e, ...r) => {
1229
1250
  if (e)
1230
1251
  try {
1231
- e(...n);
1232
- } catch (a) {
1233
- console.error(`[RemoteControl] customer callback "${t}" threw:`, a);
1252
+ e(...r);
1253
+ } catch (o) {
1254
+ console.error(`[RemoteControl] customer callback "${t}" threw:`, o);
1234
1255
  }
1235
- }, bn = (t) => t.includes("/android_") ? "android" : t.includes("/macos_") ? "macos" : "ios", Mt = (t, e) => {
1236
- const n = new URL(t);
1237
- return n.searchParams.set("token", e), n.toString();
1238
- }, st = 3, Yn = 1e3, In = 15e3, Rn = 3e3, Un = 4e3;
1239
- function vt() {
1256
+ }, Br = (t) => t.includes("/android_") ? "android" : t.includes("/macos_") ? "macos" : "ios", Rt = (t, e) => {
1257
+ const r = new URL(t);
1258
+ return r.searchParams.set("token", e), r.toString();
1259
+ }, ut = 3, xr = 1e3, Wr = 15e3, qr = 3e3, Vr = 4e3;
1260
+ function kt() {
1240
1261
  const t = crypto.getRandomValues(new Uint8Array(16));
1241
1262
  t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
1242
- const e = Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("");
1263
+ const e = Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("");
1243
1264
  return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
1244
1265
  }
1245
- function tr(t) {
1266
+ function un(t) {
1246
1267
  let e = { ...t };
1247
- const { url: n, deviceModel: a } = e;
1268
+ const { url: r, deviceModel: o } = e;
1248
1269
  let u = e.token;
1249
- const l = e.watchOnly ?? !1, i = e.sessionId ?? vt(), E = e.platform ?? bn(n ?? "");
1250
- let O = {
1270
+ const l = e.watchOnly ?? !1, i = e.sessionId ?? kt(), h = e.platform ?? Br(r ?? "");
1271
+ let D = {
1251
1272
  connection: "idle",
1252
1273
  videoReady: !1,
1253
1274
  controlReady: !1,
1254
1275
  duo: !1,
1255
1276
  duoState: null
1256
1277
  };
1257
- const m = (r) => {
1258
- O = { ...O, ...r }, F("onStateChange", e.onStateChange, O);
1259
- }, S = (r) => m({ videoReady: r }), w = (r) => m({ duoState: r }), N = (r) => m({ duoError: r }), q = (r) => m({ duo: r }), D = (r) => le(r);
1278
+ const p = (n) => {
1279
+ D = { ...D, ...n }, F("onStateChange", e.onStateChange, D);
1280
+ }, S = (n) => p({ videoReady: n }), w = (n) => p({ duoState: n }), N = (n) => p({ duoError: n }), V = (n) => p({ duo: n }), _ = (n) => le(n);
1260
1281
  let H = null, L;
1261
1282
  const P = () => {
1262
- L?.(), L = H && e.onPlaybackStats ? yn(
1283
+ L?.(), L = H && e.onPlaybackStats ? br(
1263
1284
  H,
1264
1285
  () => e.onPlaybackStats,
1265
1286
  () => e.jitterBufferTargetMs
1266
1287
  ) : void 0;
1267
- }, B = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Set(), se = /* @__PURE__ */ new Set(), Y = /* @__PURE__ */ new Map();
1268
- let ye = !1;
1269
- const Ue = /* @__PURE__ */ new Map(), ct = (r, f, c) => {
1270
- f.stop?.(), f.stop = gn(r, c, (d) => y("Video playback fallback:", d));
1271
- }, bt = () => {
1272
- Ue.clear();
1273
- for (const [r, f] of B)
1274
- f.clear?.(), f.stop?.(), f.stop = void 0, r.srcObject = null;
1288
+ }, B = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Set(), se = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Map();
1289
+ let Ee = !1;
1290
+ const Le = /* @__PURE__ */ new Map(), ft = (n, f, c) => {
1291
+ f.stop?.(), f.stop = wr(n, c, (d) => y("Video playback fallback:", d));
1292
+ }, Ke = /* @__PURE__ */ new Set();
1293
+ let Ae = null;
1294
+ const Et = (n) => {
1295
+ n.srcObject = Ae, Ae && Lt(n, () => F("onSpeakerBlocked", e.onSpeakerBlocked));
1296
+ }, Ft = () => {
1297
+ Le.clear(), Ae = null;
1298
+ for (const n of Ke) n.srcObject = null;
1299
+ for (const [n, f] of B)
1300
+ f.clear?.(), f.stop?.(), f.stop = void 0, n.srcObject = null;
1301
+ };
1302
+ let he = !1, ve = !1, Fe = 0, g = null, pe = null;
1303
+ const ht = () => {
1304
+ !pe || pe !== g || pe.readyState === WebSocket.OPEN && pe.send(
1305
+ JSON.stringify({ type: "speakerAudio", sessionId: i, enabled: !(e.speakerMuted ?? !0) })
1306
+ );
1275
1307
  };
1276
- let Ee = !1, Se = !1, ke = 0, g = null, I = null, x = null, Pe = null, he, Ke, Ae, Le, me, de = 0, Fe = 0, ne = !1, ue = null, Q = null, fe;
1277
- const Qe = new Kn();
1278
- let Me = null, Be = null, ze = !l && (e.microphoneEnabled ?? !1), Ze = !1, ve = null, te = null, xe = 0, lt = Promise.resolve(), pe = null, we = !1, re = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Map(), ie = /* @__PURE__ */ new Map(), $ = null, Ne = null, dt = 0;
1279
- const We = (r) => {
1280
- if (r === null && Ne === null) return;
1281
- Ne = r;
1282
- const f = ++dt;
1308
+ let R = null, W = null, Be = null, me, Me, we, xe, Ce, de = 0, We = 0, re = !1, ue = null, Q = null, fe;
1309
+ const tt = new Ir();
1310
+ let Ne = null, qe = null, rt = !l && (e.microphoneEnabled ?? !1), nt = !1, be = null, te = null, Ve = 0, pt = Promise.resolve(), Oe = null, Ye = !1, ne = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Map(), ie = /* @__PURE__ */ new Map(), $ = null, Ie = null, mt = 0;
1311
+ const $e = (n) => {
1312
+ if (n === null && Ie === null) return;
1313
+ Ie = n;
1314
+ const f = ++mt;
1283
1315
  queueMicrotask(() => {
1284
- f === dt && F("onAxSnapshotChange", e.onAxSnapshotChange, r);
1316
+ f === mt && F("onAxSnapshotChange", e.onAxSnapshotChange, n);
1285
1317
  });
1286
1318
  };
1287
- let Ce = null, Oe = /* @__PURE__ */ new Map();
1288
- const Yt = (r, f) => new Promise((c, d) => {
1319
+ let De = null, _e = /* @__PURE__ */ new Map();
1320
+ const Bt = (n, f) => new Promise((c, d) => {
1289
1321
  if (l) {
1290
1322
  d(new Error("Device is watch-only"));
1291
1323
  return;
@@ -1295,62 +1327,62 @@ function tr(t) {
1295
1327
  d(new Error("Simulator disconnected"));
1296
1328
  return;
1297
1329
  }
1298
- const p = vt(), C = setTimeout(() => {
1299
- Oe.delete(p), d(new Error("Device control timed out"));
1330
+ const m = kt(), C = setTimeout(() => {
1331
+ _e.delete(m), d(new Error("Device control timed out"));
1300
1332
  }, 5e3);
1301
- Oe.set(p, { resolve: c, reject: d, timer: C }), K.send(JSON.stringify({ type: r, id: p, ...f }));
1302
- }), De = (r) => {
1303
- Ce !== r && (Ce = r, m({ connection: r }), F("onConnectionStateChange", e.onConnectionStateChange, r));
1304
- }, oe = (r) => {
1305
- l || !x || x.readyState !== "open" || (x.send(Pe?.wrap(r) ?? r), $?.bumpActivity());
1306
- }, It = () => {
1333
+ _e.set(m, { resolve: c, reject: d, timer: C }), K.send(JSON.stringify({ type: n, id: m, ...f }));
1334
+ }), ge = (n) => {
1335
+ De !== n && (De = n, p({ connection: n }), F("onConnectionStateChange", e.onConnectionStateChange, n));
1336
+ }, oe = (n) => {
1337
+ l || !W || W.readyState !== "open" || (W.send(Be?.wrap(n) ?? n), $?.bumpActivity());
1338
+ }, xt = () => {
1307
1339
  g && g.readyState === WebSocket.OPEN && g.send(
1308
1340
  JSON.stringify({
1309
1341
  type: "keepAlive",
1310
1342
  sessionId: i
1311
1343
  })
1312
1344
  );
1313
- }, ut = () => {
1314
- he && window.clearInterval(he), he = window.setInterval(It, 1e4);
1315
- }, be = () => {
1316
- he && (window.clearInterval(he), he = void 0);
1317
- }, qe = () => {
1318
- Ke && (window.clearTimeout(Ke), Ke = void 0);
1319
- }, Ve = () => {
1320
- Ae && (window.clearTimeout(Ae), Ae = void 0);
1321
- }, Ye = () => {
1322
- Le && (window.clearInterval(Le), Le = void 0);
1323
- }, Ie = () => {
1324
- me !== void 0 && (window.clearTimeout(me), me = void 0);
1325
- }, Rt = () => {
1326
- we || (we = !0, Ye(), S(!0), De("connected"));
1327
- }, J = (r) => {
1328
- for (const f of r.getTracks())
1345
+ }, Ct = () => {
1346
+ me && window.clearInterval(me), me = window.setInterval(xt, 1e4);
1347
+ }, Re = () => {
1348
+ me && (window.clearInterval(me), me = void 0);
1349
+ }, He = () => {
1350
+ Me && (window.clearTimeout(Me), Me = void 0);
1351
+ }, Je = () => {
1352
+ we && (window.clearTimeout(we), we = void 0);
1353
+ }, ke = () => {
1354
+ xe && (window.clearInterval(xe), xe = void 0);
1355
+ }, Ue = () => {
1356
+ Ce !== void 0 && (window.clearTimeout(Ce), Ce = void 0);
1357
+ }, Wt = () => {
1358
+ Ye || (Ye = !0, ke(), S(!0), ge("connected"));
1359
+ }, J = (n) => {
1360
+ for (const f of n.getTracks())
1329
1361
  try {
1330
1362
  f.stop();
1331
1363
  } catch (c) {
1332
1364
  y("track.stop() failed:", c);
1333
1365
  }
1334
- }, Ut = () => {
1335
- const r = Q;
1336
- r && (Q = null, J(r));
1337
- }, ft = (r) => {
1338
- const f = lt.then(r).catch((c) => {
1366
+ }, qt = () => {
1367
+ const n = Q;
1368
+ n && (Q = null, J(n));
1369
+ }, Ot = (n) => {
1370
+ const f = pt.then(n).catch((c) => {
1339
1371
  y("microphone operation failed:", c);
1340
1372
  });
1341
- return lt = f, f;
1342
- }, et = () => ze || Ze, Et = (r) => {
1373
+ return pt = f, f;
1374
+ }, it = () => rt || nt, Dt = (n) => {
1343
1375
  const f = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1344
- pe = f, r.send(JSON.stringify({ type: "microphoneStart", id: f }));
1345
- }, tt = () => ft(() => kt()), kt = async () => {
1346
- const r = xe, f = () => r === xe && et(), c = (h) => {
1376
+ Oe = f, n.send(JSON.stringify({ type: "microphoneStart", id: f }));
1377
+ }, ot = () => Ot(() => Vt()), Vt = async () => {
1378
+ const n = Ve, f = () => n === Ve && it(), c = (E) => {
1347
1379
  F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1348
1380
  active: !1,
1349
- error: h
1381
+ error: E
1350
1382
  });
1351
1383
  };
1352
1384
  if (!f()) return;
1353
- const d = g, K = ve;
1385
+ const d = g, K = be;
1354
1386
  if (!d || d.readyState !== WebSocket.OPEN || !K || te) return;
1355
1387
  if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
1356
1388
  console.warn(
@@ -1358,48 +1390,48 @@ function tr(t) {
1358
1390
  ), c("Microphone capture requires a secure context (https)");
1359
1391
  return;
1360
1392
  }
1361
- let p = null;
1393
+ let m = null;
1362
1394
  try {
1363
- p = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !1 });
1364
- } catch (h) {
1365
- console.warn("[RemoteControl] microphone getUserMedia denied/failed:", h);
1395
+ m = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !1 });
1396
+ } catch (E) {
1397
+ console.warn("[RemoteControl] microphone getUserMedia denied/failed:", E);
1366
1398
  }
1367
1399
  if (!f()) {
1368
- p && J(p);
1400
+ m && J(m);
1369
1401
  return;
1370
1402
  }
1371
- if (!p) {
1403
+ if (!m) {
1372
1404
  c("Microphone permission denied or no device available");
1373
1405
  return;
1374
1406
  }
1375
- const C = p.getAudioTracks()[0] ?? null;
1407
+ const C = m.getAudioTracks()[0] ?? null;
1376
1408
  if (!C) {
1377
- J(p), c("Captured stream has no audio track");
1409
+ J(m), c("Captured stream has no audio track");
1378
1410
  return;
1379
1411
  }
1380
1412
  try {
1381
1413
  await K.replaceTrack(C);
1382
- } catch (h) {
1383
- y("replaceTrack(audioTrack) failed:", h), J(p), c("Failed to attach the microphone track to the connection");
1414
+ } catch (E) {
1415
+ y("replaceTrack(audioTrack) failed:", E), J(m), c("Failed to attach the microphone track to the connection");
1384
1416
  return;
1385
1417
  }
1386
1418
  if (!f()) {
1387
1419
  try {
1388
1420
  await K.replaceTrack(null);
1389
- } catch (h) {
1390
- y("replaceTrack(null) on stale mic attach failed:", h);
1421
+ } catch (E) {
1422
+ y("replaceTrack(null) on stale mic attach failed:", E);
1391
1423
  }
1392
- J(p);
1424
+ J(m);
1393
1425
  return;
1394
1426
  }
1395
- te = p, C.onended = () => {
1396
- te === p && $e("microphone capture ended by the browser");
1397
- }, Et(d), F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1427
+ te = m, C.onended = () => {
1428
+ te === m && Ge("microphone capture ended by the browser");
1429
+ }, Dt(d), F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1398
1430
  active: !0,
1399
1431
  label: C.label || void 0
1400
1432
  });
1401
- }, $e = (r) => (++xe, pe = null, ft(async () => {
1402
- const f = ve, c = te;
1433
+ }, Ge = (n) => (++Ve, Oe = null, Ot(async () => {
1434
+ const f = be, c = te;
1403
1435
  if (te = null, f && c)
1404
1436
  try {
1405
1437
  await f.replaceTrack(null);
@@ -1412,14 +1444,14 @@ function tr(t) {
1412
1444
  const K = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1413
1445
  d.send(JSON.stringify({ type: "microphoneStop", id: K }));
1414
1446
  }
1415
- (c || r) && F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1447
+ (c || n) && F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1416
1448
  active: !1,
1417
- ...r !== void 0 && { error: r }
1449
+ ...n !== void 0 && { error: n }
1418
1450
  });
1419
- })), ht = (r, f) => {
1451
+ })), _t = (n, f) => {
1420
1452
  let c;
1421
1453
  try {
1422
- c = Nn(f), console.info(
1454
+ c = Lr(f), console.info(
1423
1455
  `[RemoteControl] camera capture: ${c.camera?.width}x${c.camera?.height} @ ${c.camera?.frameRate ?? "?"}fps` + (c.camera?.label ? ` — ${c.camera.label}` : "")
1424
1456
  );
1425
1457
  } catch (d) {
@@ -1431,109 +1463,109 @@ function tr(t) {
1431
1463
  }
1432
1464
  };
1433
1465
  }
1434
- r.send(JSON.stringify(c)), F("onCameraDemandChange", e.onCameraDemandChange, !0, !0, c.camera);
1435
- }, Pt = (r) => {
1436
- if (!r) return;
1437
- const f = r.indexOf("/"), d = (f >= 0 ? r.slice(f + 1) : r).toUpperCase();
1466
+ n.send(JSON.stringify(c)), F("onCameraDemandChange", e.onCameraDemandChange, !0, !0, c.camera);
1467
+ }, $t = (n) => {
1468
+ if (!n) return;
1469
+ const f = n.indexOf("/"), d = (f >= 0 ? n.slice(f + 1) : n).toUpperCase();
1438
1470
  return d === "HEVC" ? "H265" : d;
1439
- }, Lt = async () => {
1440
- const r = ue, f = e.onCameraStats;
1441
- if (!r || !f) return;
1471
+ }, Ht = async () => {
1472
+ const n = ue, f = e.onCameraStats;
1473
+ if (!n || !f) return;
1442
1474
  let c;
1443
1475
  try {
1444
- c = await r.getStats();
1476
+ c = await n.getStats();
1445
1477
  } catch {
1446
1478
  return;
1447
1479
  }
1448
- let d, K, p;
1480
+ let d, K, m;
1449
1481
  if (c.forEach((U) => {
1450
- U.type === "outbound-rtp" && U.kind === "video" ? d = U : U.type === "remote-inbound-rtp" && U.kind === "video" && (p = U);
1482
+ U.type === "outbound-rtp" && U.kind === "video" ? d = U : U.type === "remote-inbound-rtp" && U.kind === "video" && (m = U);
1451
1483
  }), d?.codecId) {
1452
1484
  const U = c.get(d.codecId);
1453
1485
  U && (K = U.mimeType);
1454
1486
  }
1455
1487
  if (!d) return;
1456
- const C = d.timestamp ?? Date.now(), h = Be;
1457
- let R, b, G;
1458
- if (h && C > h.timestamp) {
1459
- const U = (C - h.timestamp) / 1e3;
1460
- if (typeof d.framesEncoded == "number" && typeof h.framesEncoded == "number" && (R = Math.max(0, (d.framesEncoded - h.framesEncoded) / U)), typeof d.bytesSent == "number" && typeof h.bytesSent == "number" && (b = Math.max(0, (d.bytesSent - h.bytesSent) * 8 / U)), typeof d.packetsSent == "number" && typeof h.packetsSent == "number" && p && typeof p.packetsLost == "number" && typeof h.packetsLost == "number") {
1461
- const A = d.packetsSent - h.packetsSent, Je = p.packetsLost - h.packetsLost;
1462
- A > 0 && (G = Math.max(0, Math.min(100, Je / A * 100)));
1488
+ const C = d.timestamp ?? Date.now(), E = qe;
1489
+ let k, b, G;
1490
+ if (E && C > E.timestamp) {
1491
+ const U = (C - E.timestamp) / 1e3;
1492
+ if (typeof d.framesEncoded == "number" && typeof E.framesEncoded == "number" && (k = Math.max(0, (d.framesEncoded - E.framesEncoded) / U)), typeof d.bytesSent == "number" && typeof E.bytesSent == "number" && (b = Math.max(0, (d.bytesSent - E.bytesSent) * 8 / U)), typeof d.packetsSent == "number" && typeof E.packetsSent == "number" && m && typeof m.packetsLost == "number" && typeof E.packetsLost == "number") {
1493
+ const A = d.packetsSent - E.packetsSent, Xe = m.packetsLost - E.packetsLost;
1494
+ A > 0 && (G = Math.max(0, Math.min(100, Xe / A * 100)));
1463
1495
  }
1464
1496
  }
1465
- Be = {
1497
+ qe = {
1466
1498
  timestamp: C,
1467
1499
  framesEncoded: d.framesEncoded,
1468
1500
  bytesSent: d.bytesSent,
1469
1501
  packetsSent: d.packetsSent,
1470
- packetsLost: p?.packetsLost
1502
+ packetsLost: m?.packetsLost
1471
1503
  };
1472
- const v = {
1473
- codec: Pt(K),
1504
+ const M = {
1505
+ codec: $t(K),
1474
1506
  encoderImplementation: d.encoderImplementation,
1475
1507
  hardwareAccelerated: typeof d.powerEfficientEncoder == "boolean" ? d.powerEfficientEncoder : void 0,
1476
- framesPerSecond: R,
1508
+ framesPerSecond: k,
1477
1509
  framesEncoded: d.framesEncoded,
1478
1510
  bitrateBps: b,
1479
1511
  width: d.frameWidth,
1480
1512
  height: d.frameHeight,
1481
1513
  qualityLimitationReason: d.qualityLimitationReason,
1482
- rttMs: typeof p?.roundTripTime == "number" ? p.roundTripTime * 1e3 : void 0,
1514
+ rttMs: typeof m?.roundTripTime == "number" ? m.roundTripTime * 1e3 : void 0,
1483
1515
  packetsLostPct: G
1484
1516
  };
1485
- F("onCameraStats", e.onCameraStats, v);
1486
- }, mt = () => {
1487
- Me === null && (Be = null, Me = setInterval(() => {
1488
- Lt();
1517
+ F("onCameraStats", e.onCameraStats, M);
1518
+ }, gt = () => {
1519
+ Ne === null && (qe = null, Ne = setInterval(() => {
1520
+ Ht();
1489
1521
  }, 1e3));
1490
- }, He = () => {
1491
- Me !== null && (clearInterval(Me), Me = null), Be = null, F("onCameraStats", e.onCameraStats, null);
1492
- }, Ft = (r, f, c, d) => Qe.enqueue(async ({ isCurrent: K }) => {
1493
- const p = () => K() && d() && g === f && ue === c;
1494
- if (!p()) return;
1495
- if (!r.active) {
1496
- const v = Q;
1522
+ }, je = () => {
1523
+ Ne !== null && (clearInterval(Ne), Ne = null), qe = null, F("onCameraStats", e.onCameraStats, null);
1524
+ }, Jt = (n, f, c, d) => tt.enqueue(async ({ isCurrent: K }) => {
1525
+ const m = () => K() && d() && g === f && ue === c;
1526
+ if (!m()) return;
1527
+ if (!n.active) {
1528
+ const M = Q;
1497
1529
  try {
1498
1530
  await c.replaceTrack(null);
1499
1531
  } catch (U) {
1500
1532
  y("replaceTrack(null) on camera detach failed:", U);
1501
1533
  }
1502
- if (Q === v && (Q = null, fe = void 0, v && J(v)), He(), !p()) return;
1534
+ if (Q === M && (Q = null, fe = void 0, M && J(M)), je(), !m()) return;
1503
1535
  F("onCameraDemandChange", e.onCameraDemandChange, !1);
1504
1536
  return;
1505
1537
  }
1506
1538
  F("onCameraDemandChange", e.onCameraDemandChange, !0);
1507
- const C = Q, h = C?.getVideoTracks()[0], R = fe;
1508
- if (h?.readyState === "live" && R && !vn(R, r)) {
1509
- fe = r, ht(f, h), mt();
1539
+ const C = Q, E = C?.getVideoTracks()[0], k = fe;
1540
+ if (E?.readyState === "live" && k && !Ur(k, n)) {
1541
+ fe = n, _t(f, E), gt();
1510
1542
  return;
1511
1543
  }
1512
1544
  if (C) {
1513
1545
  try {
1514
1546
  await c.replaceTrack(null);
1515
- } catch (v) {
1516
- y("replaceTrack(null) before camera switch failed:", v);
1547
+ } catch (M) {
1548
+ y("replaceTrack(null) before camera switch failed:", M);
1517
1549
  }
1518
- if (Q === C && (Q = null, fe = void 0, J(C)), He(), !p()) return;
1550
+ if (Q === C && (Q = null, fe = void 0, J(C)), je(), !m()) return;
1519
1551
  }
1520
1552
  if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
1521
1553
  if (console.warn(
1522
1554
  "[RemoteControl] navigator.mediaDevices.getUserMedia unavailable. getUserMedia requires a secure context (https or http://localhost). Replying cameraResult granted=false so limulator falls back to black frames."
1523
- ), !p()) return;
1555
+ ), !m()) return;
1524
1556
  f.send(JSON.stringify({ type: "cameraResult", granted: !1 })), F("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
1525
1557
  return;
1526
1558
  }
1527
1559
  let b = null;
1528
1560
  try {
1529
1561
  b = await navigator.mediaDevices.getUserMedia({
1530
- video: Mn(r),
1562
+ video: kr(n),
1531
1563
  audio: !1
1532
1564
  });
1533
- } catch (v) {
1534
- console.warn("[RemoteControl] getUserMedia denied/failed:", v);
1565
+ } catch (M) {
1566
+ console.warn("[RemoteControl] getUserMedia denied/failed:", M);
1535
1567
  }
1536
- if (!p()) {
1568
+ if (!m()) {
1537
1569
  b && J(b);
1538
1570
  return;
1539
1571
  }
@@ -1543,7 +1575,7 @@ function tr(t) {
1543
1575
  }
1544
1576
  const G = b.getVideoTracks()[0] ?? null;
1545
1577
  if (!G) {
1546
- if (J(b), !p()) return;
1578
+ if (J(b), !m()) return;
1547
1579
  f.send(JSON.stringify({ type: "cameraResult", granted: !1 })), F("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
1548
1580
  return;
1549
1581
  }
@@ -1553,168 +1585,168 @@ function tr(t) {
1553
1585
  }
1554
1586
  try {
1555
1587
  await c.replaceTrack(G);
1556
- } catch (v) {
1557
- if (y("replaceTrack(videoTrack) failed:", v), J(b), !p()) return;
1588
+ } catch (M) {
1589
+ if (y("replaceTrack(videoTrack) failed:", M), J(b), !m()) return;
1558
1590
  f.send(JSON.stringify({ type: "cameraResult", granted: !1 })), F("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
1559
1591
  return;
1560
1592
  }
1561
- if (!p()) {
1593
+ if (!m()) {
1562
1594
  try {
1563
1595
  await c.replaceTrack(null);
1564
- } catch (v) {
1565
- y("replaceTrack(null) for stale camera attach failed:", v);
1596
+ } catch (M) {
1597
+ y("replaceTrack(null) for stale camera attach failed:", M);
1566
1598
  }
1567
1599
  J(b);
1568
1600
  return;
1569
1601
  }
1570
1602
  try {
1571
- const v = c.getParameters();
1572
- (!v.encodings || v.encodings.length === 0) && (v.encodings = [{}]), v.encodings[0].maxBitrate = 8e6, v.encodings[0].maxFramerate = 30, v.degradationPreference = "maintain-framerate", await c.setParameters(v);
1573
- } catch (v) {
1574
- y("setParameters on outbound camera failed:", v);
1603
+ const M = c.getParameters();
1604
+ (!M.encodings || M.encodings.length === 0) && (M.encodings = [{}]), M.encodings[0].maxBitrate = 8e6, M.encodings[0].maxFramerate = 30, M.degradationPreference = "maintain-framerate", await c.setParameters(M);
1605
+ } catch (M) {
1606
+ y("setParameters on outbound camera failed:", M);
1575
1607
  }
1576
- if (!p()) {
1608
+ if (!m()) {
1577
1609
  try {
1578
1610
  await c.replaceTrack(null);
1579
- } catch (v) {
1580
- y("replaceTrack(null) for stale camera finalize failed:", v);
1611
+ } catch (M) {
1612
+ y("replaceTrack(null) for stale camera finalize failed:", M);
1581
1613
  }
1582
1614
  J(b);
1583
1615
  return;
1584
1616
  }
1585
- Q = b, fe = r, G.onended = () => {
1586
- Q === b && Qe.enqueueCurrent(async ({ isCurrent: v }) => {
1587
- if (!(!v() || Q !== b || !d() || g !== f || ue !== c)) {
1617
+ Q = b, fe = n, G.onended = () => {
1618
+ Q === b && tt.enqueueCurrent(async ({ isCurrent: M }) => {
1619
+ if (!(!M() || Q !== b || !d() || g !== f || ue !== c)) {
1588
1620
  try {
1589
1621
  await c.replaceTrack(null);
1590
1622
  } catch (U) {
1591
1623
  y("replaceTrack(null) after camera ended failed:", U);
1592
1624
  }
1593
- !v() || Q !== b || !d() || g !== f || ue !== c || (Q = null, fe = void 0, J(b), He(), f.send(JSON.stringify({ type: "cameraResult", granted: !1 })), F("onCameraDemandChange", e.onCameraDemandChange, !0, !1));
1625
+ !M() || Q !== b || !d() || g !== f || ue !== c || (Q = null, fe = void 0, J(b), je(), f.send(JSON.stringify({ type: "cameraResult", granted: !1 })), F("onCameraDemandChange", e.onCameraDemandChange, !0, !1));
1594
1626
  }
1595
- }).catch((v) => y("camera ended cleanup failed:", v));
1596
- }, p() && (ht(f, G), mt());
1597
- }), _e = () => {
1598
- for (const r of se) r();
1627
+ }).catch((M) => y("camera ended cleanup failed:", M));
1628
+ }, m() && (_t(f, G), gt());
1629
+ }), Te = () => {
1630
+ for (const n of se) n();
1599
1631
  se.clear();
1600
- for (const r of Y.values()) clearTimeout(r);
1601
- Y.clear();
1602
- for (const r of Z.values())
1603
- r(new Error("Simulator disconnected"));
1604
- for (const r of ie.values())
1605
- r(new Error("Simulator disconnected"));
1606
- Z.clear(), re.clear(), ie.clear(), ce.clear(), L?.(), L = void 0, bt(), H = null;
1607
- for (const r of Oe.values())
1608
- clearTimeout(r.timer), r.reject(new Error("Simulator disconnected"));
1609
- Oe.clear(), w(null), m({ controlReady: !1, videoReady: !1 }), Ve(), Ie(), Ye(), $ && ($.stop(), $ = null), Ne !== null && We(null), Qe.invalidate(), He(), Ut(), fe = void 0, ue = null, ++xe, Ze = !1, pe = null, te && (J(te), te = null, F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1632
+ for (const n of I.values()) clearTimeout(n);
1633
+ I.clear();
1634
+ for (const n of Z.values())
1635
+ n(new Error("Simulator disconnected"));
1636
+ for (const n of ie.values())
1637
+ n(new Error("Simulator disconnected"));
1638
+ Z.clear(), ne.clear(), ie.clear(), ce.clear(), L?.(), L = void 0, Ft(), H = null;
1639
+ for (const n of _e.values())
1640
+ clearTimeout(n.timer), n.reject(new Error("Simulator disconnected"));
1641
+ _e.clear(), w(null), p({ controlReady: !1, videoReady: !1 }), Je(), Ue(), ke(), $ && ($.stop(), $ = null), Ie !== null && $e(null), tt.invalidate(), je(), qt(), fe = void 0, ue = null, ++Ve, nt = !1, Oe = null, te && (J(te), te = null, F("onMicrophoneStateChange", e.onMicrophoneStateChange, {
1610
1642
  active: !1
1611
- })), ve = null, g && (g.onopen = null, g.onmessage = null, g.onerror = null, g.onclose = null, g.close(), g = null), Pe?.close(), Pe = null, I && (I.onconnectionstatechange = null, I.oniceconnectionstatechange = null, I.ontrack = null, I.onicecandidate = null, I.close(), I = null), x && (x.onopen = null, x.onclose = null, x.onerror = null, x.close(), x = null);
1612
- }, pt = () => {
1613
- document.hidden ? be() : ut();
1614
- }, Bt = async () => {
1643
+ })), be = null, pe = null, g && (g.onopen = null, g.onmessage = null, g.onerror = null, g.onclose = null, g.close(), g = null), Be?.close(), Be = null, R && (R.onconnectionstatechange = null, R.oniceconnectionstatechange = null, R.ontrack = null, R.onicecandidate = null, R.close(), R = null), W && (W.onopen = null, W.onclose = null, W.onerror = null, W.close(), W = null);
1644
+ }, Tt = () => {
1645
+ document.hidden ? Re() : Ct();
1646
+ }, Gt = async () => {
1615
1647
  if (e.transport) return e.transport.isTerminated?.() ?? !1;
1616
1648
  if (typeof navigator < "u" && navigator.onLine === !1)
1617
1649
  return !1;
1618
- let r;
1650
+ let n;
1619
1651
  try {
1620
- const d = new URL(n);
1621
- d.protocol = d.protocol === "wss:" ? "https:" : d.protocol === "ws:" ? "http:" : d.protocol, r = Mt(d.toString(), u);
1652
+ const d = new URL(r);
1653
+ d.protocol = d.protocol === "wss:" ? "https:" : d.protocol === "ws:" ? "http:" : d.protocol, n = Rt(d.toString(), u);
1622
1654
  } catch {
1623
1655
  return !1;
1624
1656
  }
1625
- const f = new AbortController(), c = window.setTimeout(() => f.abort(), Un);
1657
+ const f = new AbortController(), c = window.setTimeout(() => f.abort(), Vr);
1626
1658
  try {
1627
- return (await fetch(r, { method: "GET", cache: "no-store", signal: f.signal })).status === 404;
1659
+ return (await fetch(n, { method: "GET", cache: "no-store", signal: f.signal })).status === 404;
1628
1660
  } catch {
1629
1661
  return !1;
1630
1662
  } finally {
1631
1663
  window.clearTimeout(c);
1632
1664
  }
1633
- }, xt = () => {
1634
- Ee || (Ee = !0, de += 1, qe(), Ve(), Ie(), _e(), D("Instance terminated"), be(), De("terminated"), F("onTerminated", e.onTerminated));
1635
- }, Wt = () => {
1636
- if (Ee || Se) return;
1637
- Se = !0;
1638
- const r = ke;
1639
- Bt().catch(() => !1).then((f) => {
1640
- r === ke && (Se = !1, f && xt());
1665
+ }, jt = () => {
1666
+ he || (he = !0, de += 1, He(), Je(), Ue(), Te(), _("Instance terminated"), Re(), ge("terminated"), F("onTerminated", e.onTerminated));
1667
+ }, Xt = () => {
1668
+ if (he || ve) return;
1669
+ ve = !0;
1670
+ const n = Fe;
1671
+ Gt().catch(() => !1).then((f) => {
1672
+ n === Fe && (ve = !1, f && jt());
1641
1673
  });
1642
- }, ge = (r, f) => {
1643
- if (Ee || f !== de)
1674
+ }, ye = (n, f) => {
1675
+ if (he || f !== de)
1644
1676
  return;
1645
- if (Wt(), ne) {
1677
+ if (Xt(), re) {
1646
1678
  if (e.autoReconnect === !1) {
1647
- D(`Connection failed after it was established: ${r}`), be(), De("failed"), _e();
1679
+ _(`Connection failed after it was established: ${n}`), Re(), ge("failed"), Te();
1648
1680
  return;
1649
1681
  }
1650
- D(`Reconnecting after established session dropped: ${r}`), ne = !1, Fe = -1;
1682
+ _(`Reconnecting after established session dropped: ${n}`), re = !1, We = -1;
1651
1683
  }
1652
- qe();
1653
- const c = Fe + 1;
1654
- if (c >= st) {
1655
- D(`Connection failed after ${st} attempts: ${r}`), be(), De("failed"), _e();
1684
+ He();
1685
+ const c = We + 1;
1686
+ if (c >= ut) {
1687
+ _(`Connection failed after ${ut} attempts: ${n}`), Re(), ge("failed"), Te();
1656
1688
  return;
1657
1689
  }
1658
- D(`Retrying connection (${c + 1}/${st})`), De("reconnecting"), _e(), Ke = window.setTimeout(() => {
1659
- Ke = void 0, f === de && Ct(c);
1660
- }, Yn);
1661
- }, Ct = async (r = 0) => {
1690
+ _(`Retrying connection (${c + 1}/${ut})`), ge("reconnecting"), Te(), Me = window.setTimeout(() => {
1691
+ Me = void 0, f === de && yt(c);
1692
+ }, xr);
1693
+ }, yt = async (n = 0) => {
1662
1694
  const { openUrl: f, axPollIntervalMs: c, axMaxBackoffMs: d, androidElementTreeOptions: K } = e;
1663
- if (Ee) return;
1664
- const p = de + 1;
1665
- de = p, Fe = r, ne = !1, r === 0 && Ce !== "reconnecting" && De("connecting"), qe(), Ve(), Ye(), we = !1, S(!1), _e();
1666
- const C = () => p === de;
1667
- Ae = window.setTimeout(() => {
1668
- Ae = void 0, !(!C() || ne) && ge("Connection did not succeed within 15 seconds", p);
1669
- }, In);
1695
+ if (he) return;
1696
+ const m = de + 1;
1697
+ de = m, We = n, re = !1, n === 0 && De !== "reconnecting" && ge("connecting"), He(), Je(), ke(), Ye = !1, S(!1), Te();
1698
+ const C = () => m === de;
1699
+ we = window.setTimeout(() => {
1700
+ we = void 0, !(!C() || re) && ye("Connection did not succeed within 15 seconds", m);
1701
+ }, Wr);
1670
1702
  try {
1671
- const h = e.transport ? await e.transport.connect() : new WebSocket(Mt(n, u));
1703
+ const E = e.transport ? await e.transport.connect() : new WebSocket(Rt(r, u));
1672
1704
  if (!C()) {
1673
- h.close();
1705
+ E.close();
1674
1706
  return;
1675
1707
  }
1676
- if (g = h, await new Promise((_, s) => {
1677
- let k = !1;
1678
- const W = () => M(() => s(new Error("Connection stopped")));
1679
- se.add(W);
1708
+ if (g = E, await new Promise((O, s) => {
1709
+ let Y = !1;
1710
+ const q = () => v(() => s(new Error("Connection stopped")));
1711
+ se.add(q);
1680
1712
  const T = window.setTimeout(
1681
- () => M(() => s(new Error("WebSocket connection timeout"))),
1713
+ () => v(() => s(new Error("WebSocket connection timeout"))),
1682
1714
  3e4
1683
- ), M = (z) => {
1684
- k || (k = !0, se.delete(W), window.clearTimeout(T), z());
1715
+ ), v = (z) => {
1716
+ Y || (Y = !0, se.delete(q), window.clearTimeout(T), z());
1685
1717
  };
1686
- h.onopen = () => {
1687
- !C() || g !== h || M(_);
1688
- }, h.onerror = (z) => {
1689
- !C() || g !== h || (D("WebSocket error: " + z), M(() => s(new Error("WebSocket connection failed"))));
1690
- }, h.onclose = () => {
1691
- !C() || g !== h || (D("WebSocket closed"), M(() => s(new Error("WebSocket closed before connection was established"))));
1692
- }, h.readyState === WebSocket.OPEN ? M(_) : h.readyState !== WebSocket.CONNECTING && M(() => s(new Error("WebSocket is closed")));
1693
- }), !C() || g !== h)
1718
+ E.onopen = () => {
1719
+ !C() || g !== E || v(O);
1720
+ }, E.onerror = (z) => {
1721
+ !C() || g !== E || (_("WebSocket error: " + z), v(() => s(new Error("WebSocket connection failed"))));
1722
+ }, E.onclose = () => {
1723
+ !C() || g !== E || (_("WebSocket closed"), v(() => s(new Error("WebSocket closed before connection was established"))));
1724
+ }, E.readyState === WebSocket.OPEN ? v(O) : E.readyState !== WebSocket.CONNECTING && v(() => s(new Error("WebSocket is closed")));
1725
+ }), !C() || g !== E)
1694
1726
  return;
1695
- h.onerror = (_) => {
1696
- !C() || g !== h || D("WebSocket error: " + _);
1697
- }, h.onclose = () => {
1698
- !C() || g !== h || D("WebSocket closed");
1727
+ E.onerror = (O) => {
1728
+ !C() || g !== E || _("WebSocket error: " + O);
1729
+ }, E.onclose = () => {
1730
+ !C() || g !== E || _("WebSocket closed");
1699
1731
  };
1700
- const R = new Promise((_, s) => {
1701
- let k = !1;
1702
- const W = () => T(() => s(new Error("Connection stopped")));
1703
- se.add(W);
1732
+ const k = new Promise((O, s) => {
1733
+ let Y = !1;
1734
+ const q = () => T(() => s(new Error("Connection stopped")));
1735
+ se.add(q);
1704
1736
  const T = (j) => {
1705
- k || (k = !0, se.delete(W), window.clearTimeout(M), h.removeEventListener("message", z), j());
1706
- }, M = window.setTimeout(
1737
+ Y || (Y = !0, se.delete(q), window.clearTimeout(v), E.removeEventListener("message", z), j());
1738
+ }, v = window.setTimeout(
1707
1739
  () => T(() => s(new Error("RTCConfiguration timeout"))),
1708
1740
  3e4
1709
1741
  ), z = (j) => {
1710
- if (!(!C() || g !== h))
1742
+ if (!(!C() || g !== E))
1711
1743
  try {
1712
1744
  const X = JSON.parse(j.data);
1713
1745
  if (X.type === "signalingError" && X.requestType === "requestRtcConfiguration" && X.sessionId === i) {
1714
- const $t = typeof X.error == "string" ? X.error : "Unable to load streaming configuration";
1715
- T(() => s(new Error($t)));
1746
+ const er = typeof X.error == "string" ? X.error : "Unable to load streaming configuration";
1747
+ T(() => s(new Error(er)));
1716
1748
  } else X.type === "rtcConfiguration" && T(
1717
- () => _({
1749
+ () => O({
1718
1750
  rtcConfiguration: X.rtcConfiguration,
1719
1751
  cameraSupported: X.cameraSupported === !0,
1720
1752
  foldSupported: X.foldSupported === !0
@@ -1724,7 +1756,7 @@ function tr(t) {
1724
1756
  console.error("Error handling RTC configuration:", X), T(() => s(X));
1725
1757
  }
1726
1758
  };
1727
- h.addEventListener("message", z), h.send(
1759
+ E.addEventListener("message", z), E.send(
1728
1760
  JSON.stringify({
1729
1761
  type: "requestRtcConfiguration",
1730
1762
  sessionId: i
@@ -1733,45 +1765,45 @@ function tr(t) {
1733
1765
  }), {
1734
1766
  rtcConfiguration: b,
1735
1767
  cameraSupported: G,
1736
- foldSupported: v
1737
- } = await R;
1738
- if (!C() || g !== h)
1768
+ foldSupported: M
1769
+ } = await k;
1770
+ if (!C() || g !== E)
1739
1771
  return;
1740
- const U = a === "iphone-duo" || v;
1741
- q(U);
1772
+ const U = o === "iphone-duo" || M;
1773
+ V(U);
1742
1774
  const A = new RTCPeerConnection({ ...b, iceTransportPolicy: "relay" });
1743
- I = A;
1744
- const Je = { peer: A, displays: /* @__PURE__ */ new Map() };
1745
- H = Je, P(), A.addTransceiver("audio", { direction: "recvonly" });
1746
- const qt = A.addTransceiver("video", { direction: "recvonly" }), Vt = U ? A.addTransceiver("video", { direction: "recvonly" }) : null, gt = !l && (E === "ios" || G), nt = gt ? A.addTransceiver("video", {
1775
+ R = A;
1776
+ const Xe = { peer: A, displays: /* @__PURE__ */ new Map() };
1777
+ H = Xe, P(), A.addTransceiver("audio", { direction: "recvonly" });
1778
+ const zt = A.addTransceiver("video", { direction: "recvonly" }), Zt = U ? A.addTransceiver("video", { direction: "recvonly" }) : null, vt = !l && (h === "ios" || G), at = vt ? A.addTransceiver("video", {
1747
1779
  direction: "sendonly"
1748
1780
  }) : null;
1749
- if (ue = nt?.sender ?? null, ve = (gt ? A.addTransceiver("audio", {
1781
+ if (ue = at?.sender ?? null, be = (vt ? A.addTransceiver("audio", {
1750
1782
  direction: "sendonly"
1751
1783
  }) : null)?.sender ?? null, RTCRtpReceiver.getCapabilities) {
1752
- const _ = RTCRtpReceiver.getCapabilities("video");
1753
- if (_ && _.codecs) {
1754
- const k = _.codecs.sort((W, T) => {
1755
- const M = (z) => {
1784
+ const O = RTCRtpReceiver.getCapabilities("video");
1785
+ if (O && O.codecs) {
1786
+ const Y = O.codecs.sort((q, T) => {
1787
+ const v = (z) => {
1756
1788
  const j = z.mimeType.toLowerCase();
1757
1789
  return j.includes("h265") || j.includes("hevc") ? 1 : j.includes("h264") || j.includes("avc") ? 2 : 3;
1758
1790
  };
1759
- return M(W) - M(T);
1791
+ return v(q) - v(T);
1760
1792
  });
1761
- qt.setCodecPreferences(k), Vt?.setCodecPreferences(k), le("Set codec preferences:", k.map((W) => W.mimeType).join(", "));
1793
+ zt.setCodecPreferences(Y), Zt?.setCodecPreferences(Y), le("Set codec preferences:", Y.map((q) => q.mimeType).join(", "));
1762
1794
  }
1763
1795
  }
1764
- if (nt && RTCRtpSender.getCapabilities) {
1765
- const _ = RTCRtpSender.getCapabilities("video");
1766
- if (_ && _.codecs) {
1767
- const s = /* @__PURE__ */ new Set(["42e01f", "42e028", "640c1f"]), k = (T) => {
1768
- const M = T.mimeType.toLowerCase(), j = (T.sdpFmtpLine || "").toLowerCase().match(/profile-level-id=([0-9a-f]{6})/), X = j ? j[1] : "";
1769
- return M === "video/h265" || M === "video/hevc" ? 1 : M === "video/h264" && s.has(X) ? 2 : M === "video/h264" ? 3 : M === "video/vp9" ? 4 : M === "video/vp8" ? 5 : M === "video/rtx" || M === "video/red" || M === "video/ulpfec" ? 0 : 6;
1770
- }, W = [..._.codecs].sort((T, M) => k(T) - k(M));
1796
+ if (at && RTCRtpSender.getCapabilities) {
1797
+ const O = RTCRtpSender.getCapabilities("video");
1798
+ if (O && O.codecs) {
1799
+ const s = /* @__PURE__ */ new Set(["42e01f", "42e028", "640c1f"]), Y = (T) => {
1800
+ const v = T.mimeType.toLowerCase(), j = (T.sdpFmtpLine || "").toLowerCase().match(/profile-level-id=([0-9a-f]{6})/), X = j ? j[1] : "";
1801
+ return v === "video/h265" || v === "video/hevc" ? 1 : v === "video/h264" && s.has(X) ? 2 : v === "video/h264" ? 3 : v === "video/vp9" ? 4 : v === "video/vp8" ? 5 : v === "video/rtx" || v === "video/red" || v === "video/ulpfec" ? 0 : 6;
1802
+ }, q = [...O.codecs].sort((T, v) => Y(T) - Y(v));
1771
1803
  try {
1772
- nt.setCodecPreferences(W), le(
1804
+ at.setCodecPreferences(q), le(
1773
1805
  "Outbound camera codec preferences:",
1774
- W.map((T) => `${T.mimeType}${T.sdpFmtpLine ? `[${T.sdpFmtpLine}]` : ""}`).join(", ")
1806
+ q.map((T) => `${T.mimeType}${T.sdpFmtpLine ? `[${T.sdpFmtpLine}]` : ""}`).join(", ")
1775
1807
  );
1776
1808
  } catch (T) {
1777
1809
  y("Failed to set outbound camera codec preferences:", T);
@@ -1783,15 +1815,15 @@ function tr(t) {
1783
1815
  negotiated: !0,
1784
1816
  id: 1
1785
1817
  });
1786
- x = ae;
1787
- const rt = !l && !U && e.onTrace ? Sn(A, (_) => {
1788
- C() && I === A && F("onTrace", e.onTrace, _);
1818
+ W = ae;
1819
+ const st = !l && !U && e.onTrace ? Yr(A, (O) => {
1820
+ C() && R === A && F("onTrace", e.onTrace, O);
1789
1821
  }) : null;
1790
- if (Pe = rt, ae.onopen = () => {
1791
- if (!C() || x !== ae || g !== h)
1822
+ if (Be = st, ae.onopen = () => {
1823
+ if (!C() || W !== ae || g !== E)
1792
1824
  return;
1793
- ne = !0, m({ controlReady: !l }), Ve(), D("Control channel opened"), U && h.send(JSON.stringify({ type: "getFoldState", id: "duo-capabilities" })), !$ && E !== "macos" && ($ = new Dn({
1794
- platform: E,
1825
+ re = !0, p({ controlReady: !l }), Je(), _("Control channel opened"), U && E.send(JSON.stringify({ type: "getFoldState", id: "duo-capabilities" })), !$ && h !== "macos" && ($ = new vr({
1826
+ platform: h,
1795
1827
  baseIntervalMs: c,
1796
1828
  maxBackoffMs: d,
1797
1829
  androidElementTreeOptions: K,
@@ -1803,24 +1835,24 @@ function tr(t) {
1803
1835
  return !1;
1804
1836
  }
1805
1837
  },
1806
- onSnapshot: We,
1807
- onStatusChange: (s, k) => {
1808
- F("onAxStatusChange", e.onAxStatusChange, s, k);
1838
+ onSnapshot: $e,
1839
+ onStatusChange: (s, Y) => {
1840
+ F("onAxStatusChange", e.onAxStatusChange, s, Y);
1809
1841
  }
1810
1842
  }), (e.inspectMode === !0 || e.inspectMode === "hover-only") && $.start());
1811
- const _ = () => {
1812
- !C() || we || x !== ae || g !== h || h.readyState !== WebSocket.OPEN || h.send(JSON.stringify({ type: "requestFrame", sessionId: i }));
1843
+ const O = () => {
1844
+ !C() || Ye || W !== ae || g !== E || E.readyState !== WebSocket.OPEN || E.send(JSON.stringify({ type: "requestFrame", sessionId: i }));
1813
1845
  };
1814
- if (_(), Ye(), Le = window.setInterval(() => {
1815
- if (!C() || we || x !== ae || g !== h || h.readyState !== WebSocket.OPEN) {
1816
- Ye();
1846
+ if (O(), ke(), xe = window.setInterval(() => {
1847
+ if (!C() || Ye || W !== ae || g !== E || E.readyState !== WebSocket.OPEN) {
1848
+ ke();
1817
1849
  return;
1818
1850
  }
1819
- _();
1851
+ O();
1820
1852
  }, 250), !l && f) {
1821
1853
  try {
1822
1854
  const s = decodeURIComponent(f);
1823
- D("Opening URL"), h.send(
1855
+ _("Opening URL"), E.send(
1824
1856
  JSON.stringify({
1825
1857
  type: "openUrl",
1826
1858
  url: s,
@@ -1828,7 +1860,7 @@ function tr(t) {
1828
1860
  })
1829
1861
  );
1830
1862
  } catch (s) {
1831
- console.error({ error: s }, "Error decoding URL, falling back to the original URL"), h.send(
1863
+ console.error({ error: s }, "Error decoding URL, falling back to the original URL"), E.send(
1832
1864
  JSON.stringify({
1833
1865
  type: "openUrl",
1834
1866
  url: f,
@@ -1839,95 +1871,99 @@ function tr(t) {
1839
1871
  $?.bumpActivity();
1840
1872
  }
1841
1873
  }, ae.onclose = () => {
1842
- !C() || x !== ae || (m({ controlReady: !1 }), D("Control channel closed"));
1843
- }, ae.onerror = (_) => {
1844
- !C() || x !== ae || (console.error("Control channel error:", _), D("Control channel error: " + _));
1874
+ !C() || W !== ae || (p({ controlReady: !1 }), _("Control channel closed"));
1875
+ }, ae.onerror = (O) => {
1876
+ !C() || W !== ae || (console.error("Control channel error:", O), _("Control channel error: " + O));
1845
1877
  }, A.onconnectionstatechange = () => {
1846
- !C() || I !== A || (D("Connection state: " + A.connectionState), A.connectionState === "failed" && ne && ge("WebRTC connection entered failed state", p));
1878
+ !C() || R !== A || (_("Connection state: " + A.connectionState), A.connectionState === "failed" && re && ye("WebRTC connection entered failed state", m));
1847
1879
  }, A.oniceconnectionstatechange = () => {
1848
- if (!C() || I !== A)
1880
+ if (!C() || R !== A)
1849
1881
  return;
1850
- const _ = A.iceConnectionState;
1851
- if (D("ICE state: " + _), _ === "connected" || _ === "completed") {
1852
- Ie(), et() && !te && tt();
1882
+ const O = A.iceConnectionState;
1883
+ if (_("ICE state: " + O), O === "connected" || O === "completed") {
1884
+ Ue(), it() && !te && ot();
1853
1885
  return;
1854
1886
  }
1855
- if (_ === "failed") {
1856
- Ie(), ne && ge("ICE connection entered failed state", p);
1887
+ if (O === "failed") {
1888
+ Ue(), re && ye("ICE connection entered failed state", m);
1857
1889
  return;
1858
1890
  }
1859
- _ === "disconnected" && ne && e.autoReconnect !== !1 && me === void 0 && (me = window.setTimeout(() => {
1860
- me = void 0, !(!C() || I !== A) && A.iceConnectionState === "disconnected" && ge("ICE stayed disconnected past grace period", p);
1861
- }, Rn));
1862
- }, A.ontrack = (_) => {
1863
- if (!C() || I !== A)
1891
+ O === "disconnected" && re && e.autoReconnect !== !1 && Ce === void 0 && (Ce = window.setTimeout(() => {
1892
+ Ce = void 0, !(!C() || R !== A) && A.iceConnectionState === "disconnected" && ye("ICE stayed disconnected past grace period", m);
1893
+ }, qr));
1894
+ }, A.ontrack = (O) => {
1895
+ if (!C() || R !== A)
1864
1896
  return;
1865
- Kt(_.receiver, e.jitterBufferTargetMs);
1866
- const s = _.track.id === "duo-inner" || _.streams.some((k) => k.id === "duo-inner");
1867
- if (_.track.kind === "video" && Je.displays.set(_.receiver, s ? "inner" : "primary"), D("Received remote track: " + _.track.kind), _.track.kind === "video") {
1868
- const k = s ? "inner" : "primary", W = U ? new MediaStream([_.track]) : _.streams[0] ?? new MediaStream([_.track]);
1869
- Ue.set(k, W);
1870
- for (const [T, M] of B)
1871
- M.display === k && ct(T, M, W);
1897
+ bt(O.receiver, e.jitterBufferTargetMs);
1898
+ const s = O.track.id === "duo-inner" || O.streams.some((Y) => Y.id === "duo-inner");
1899
+ if (O.track.kind === "video" && Xe.displays.set(O.receiver, s ? "inner" : "primary"), _("Received remote track: " + O.track.kind), O.track.kind === "video") {
1900
+ const Y = s ? "inner" : "primary", q = U ? new MediaStream([O.track]) : O.streams[0] ?? new MediaStream([O.track]);
1901
+ Le.set(Y, q);
1902
+ for (const [T, v] of B)
1903
+ v.display === Y && ft(T, v, q);
1904
+ }
1905
+ if (O.track.kind === "audio") {
1906
+ Ae = new MediaStream([O.track]);
1907
+ for (const Y of Ke) Et(Y);
1872
1908
  }
1873
- }, A.onicecandidate = (_) => {
1874
- if (!(!C() || I !== A || g !== h))
1875
- if (_.candidate && h.readyState === WebSocket.OPEN) {
1909
+ }, A.onicecandidate = (O) => {
1910
+ if (!(!C() || R !== A || g !== E))
1911
+ if (O.candidate && E.readyState === WebSocket.OPEN) {
1876
1912
  const s = {
1877
1913
  type: "candidate",
1878
- candidate: _.candidate.candidate,
1879
- sdpMid: _.candidate.sdpMid,
1880
- sdpMLineIndex: _.candidate.sdpMLineIndex,
1914
+ candidate: O.candidate.candidate,
1915
+ sdpMid: O.candidate.sdpMid,
1916
+ sdpMLineIndex: O.candidate.sdpMLineIndex,
1881
1917
  sessionId: i
1882
1918
  };
1883
- h.send(JSON.stringify(s)), D("Sent ICE candidate");
1919
+ E.send(JSON.stringify(s)), _("Sent ICE candidate");
1884
1920
  } else
1885
- D("ICE candidate gathering completed");
1886
- }, h.onmessage = async (_) => {
1887
- if (!C() || g !== h)
1921
+ _("ICE candidate gathering completed");
1922
+ }, E.onmessage = async (O) => {
1923
+ if (!C() || g !== E)
1888
1924
  return;
1889
1925
  let s;
1890
1926
  try {
1891
- s = JSON.parse(_.data);
1892
- } catch (k) {
1893
- y("Error parsing message:", k);
1927
+ s = JSON.parse(O.data);
1928
+ } catch (Y) {
1929
+ y("Error parsing message:", Y);
1894
1930
  return;
1895
1931
  }
1896
1932
  if (!$?.handleMessage(s))
1897
- switch (D("Received: " + s.type), s.type) {
1933
+ switch (_("Received: " + s.type), s.type) {
1898
1934
  case "performActionsResult":
1899
1935
  case "foldStateResult":
1900
1936
  case "foldStateChanged": {
1901
1937
  if (!U) break;
1902
1938
  s.state ? (w(s.state), N(void 0)) : s.id === "duo-capabilities" && N(s.error || "This instance does not support native iPhone Duo displays.");
1903
- const T = Oe.get(s.id);
1904
- T && (clearTimeout(T.timer), Oe.delete(s.id), s.error ? T.reject(new Error(s.error)) : T.resolve());
1939
+ const T = _e.get(s.id);
1940
+ T && (clearTimeout(T.timer), _e.delete(s.id), s.error ? T.reject(new Error(s.error)) : T.resolve());
1905
1941
  break;
1906
1942
  }
1907
1943
  case "signalingError": {
1908
1944
  if (s.requestType !== "offer" || s.sessionId !== i)
1909
1945
  break;
1910
1946
  const T = typeof s.error == "string" ? s.error : "Unable to establish the streaming connection";
1911
- D("Error: " + T), ge(T, p);
1947
+ _("Error: " + T), ye(T, m);
1912
1948
  break;
1913
1949
  }
1914
1950
  case "answer":
1915
- if (!I || I !== A) {
1916
- D("No peer connection, skipping answer");
1951
+ if (!R || R !== A) {
1952
+ _("No peer connection, skipping answer");
1917
1953
  break;
1918
1954
  }
1919
- if (rt?.accept(s.latencyTraceVersion), await A.setRemoteDescription(
1955
+ if (st?.accept(s.latencyTraceVersion), await A.setRemoteDescription(
1920
1956
  new RTCSessionDescription({
1921
1957
  type: "answer",
1922
1958
  sdp: s.sdp
1923
1959
  })
1924
- ), !C() || I !== A)
1960
+ ), !C() || R !== A)
1925
1961
  return;
1926
- D("Set remote description");
1962
+ _("Set remote description"), pe = E, (e.speakerMuted ?? !0) || ht();
1927
1963
  break;
1928
1964
  case "candidate":
1929
- if (!I || I !== A) {
1930
- D("No peer connection, skipping candidate");
1965
+ if (!R || R !== A) {
1966
+ _("No peer connection, skipping candidate");
1931
1967
  break;
1932
1968
  }
1933
1969
  if (await A.addIceCandidate(
@@ -1936,9 +1972,9 @@ function tr(t) {
1936
1972
  sdpMid: s.sdpMid,
1937
1973
  sdpMLineIndex: s.sdpMLineIndex
1938
1974
  })
1939
- ), !C() || I !== A)
1975
+ ), !C() || R !== A)
1940
1976
  return;
1941
- D("Added ICE candidate");
1977
+ _("Added ICE candidate");
1942
1978
  break;
1943
1979
  case "screenshot":
1944
1980
  case "screenshotResult": {
@@ -1946,27 +1982,27 @@ function tr(t) {
1946
1982
  y("Received invalid screenshot success message:", s);
1947
1983
  break;
1948
1984
  }
1949
- const T = kn(s);
1985
+ const T = $r(s);
1950
1986
  if (T) {
1951
1987
  const j = Z.get(s.id);
1952
1988
  if (typeof j != "function") {
1953
1989
  y(`Received screenshot error for unknown or handled id: ${s.id}`);
1954
1990
  break;
1955
1991
  }
1956
- y(`Received screenshot error for id ${s.id}: ${T}`), j(new Error(T)), re.delete(s.id), Z.delete(s.id), clearTimeout(Y.get(s.id)), Y.delete(s.id);
1992
+ y(`Received screenshot error for id ${s.id}: ${T}`), j(new Error(T)), ne.delete(s.id), Z.delete(s.id), clearTimeout(I.get(s.id)), I.delete(s.id);
1957
1993
  break;
1958
1994
  }
1959
- const M = Pn(s);
1960
- if (!M) {
1995
+ const v = Hr(s);
1996
+ if (!v) {
1961
1997
  y("Received screenshot message without image data:", s);
1962
1998
  break;
1963
1999
  }
1964
- const z = re.get(s.id);
2000
+ const z = ne.get(s.id);
1965
2001
  if (typeof z != "function") {
1966
2002
  y(`Received screenshot data for unknown or handled id: ${s.id}`);
1967
2003
  break;
1968
2004
  }
1969
- le(`Received screenshot data for id ${s.id}`), z(M), re.delete(s.id), Z.delete(s.id), clearTimeout(Y.get(s.id)), Y.delete(s.id);
2005
+ le(`Received screenshot data for id ${s.id}`), z(v), ne.delete(s.id), Z.delete(s.id), clearTimeout(I.get(s.id)), I.delete(s.id);
1970
2006
  break;
1971
2007
  }
1972
2008
  case "screenshotError":
@@ -1974,44 +2010,44 @@ function tr(t) {
1974
2010
  y("Received invalid screenshot error message:", s);
1975
2011
  break;
1976
2012
  }
1977
- const k = Z.get(s.id);
1978
- if (typeof k != "function") {
2013
+ const Y = Z.get(s.id);
2014
+ if (typeof Y != "function") {
1979
2015
  y(`Received screenshot error for unknown or handled id: ${s.id}`);
1980
2016
  break;
1981
2017
  }
1982
- y(`Received screenshot error for id ${s.id}: ${s.message}`), k(new Error(s.message)), re.delete(s.id), Z.delete(s.id), clearTimeout(Y.get(s.id)), Y.delete(s.id);
2018
+ y(`Received screenshot error for id ${s.id}: ${s.message}`), Y(new Error(s.message)), ne.delete(s.id), Z.delete(s.id), clearTimeout(I.get(s.id)), I.delete(s.id);
1983
2019
  break;
1984
2020
  case "cameraRequest": {
1985
2021
  const T = ue;
1986
2022
  if (!T)
1987
2023
  break;
1988
- const M = An(s);
1989
- if (!M) {
2024
+ const v = Rr(s);
2025
+ if (!v) {
1990
2026
  y("Received invalid cameraRequest:", s);
1991
2027
  break;
1992
2028
  }
1993
- console.info("[RemoteControl] cameraRequest received:", M.active, M.facingMode), await Ft(M, h, T, C);
2029
+ console.info("[RemoteControl] cameraRequest received:", v.active, v.facingMode), await Jt(v, E, T, C);
1994
2030
  break;
1995
2031
  }
1996
2032
  case "microphoneRequest": {
1997
- if (!ve)
2033
+ if (!be)
1998
2034
  break;
1999
2035
  const T = s.active === !0;
2000
- if (Ze = T, console.info("[RemoteControl] microphoneRequest received, active=", T), !T) {
2001
- ze || await $e();
2036
+ if (nt = T, console.info("[RemoteControl] microphoneRequest received, active=", T), !T) {
2037
+ rt || await Ge();
2002
2038
  break;
2003
2039
  }
2004
2040
  if (te) {
2005
- Et(h);
2041
+ Dt(E);
2006
2042
  break;
2007
2043
  }
2008
- await tt();
2044
+ await ot();
2009
2045
  break;
2010
2046
  }
2011
2047
  case "microphoneStartResult": {
2012
- if (pe === null || s.id !== pe)
2048
+ if (Oe === null || s.id !== Oe)
2013
2049
  break;
2014
- pe = null, typeof s.error == "string" && (console.warn("[RemoteControl] microphoneStart rejected by host:", s.error), $e(s.error));
2050
+ Oe = null, typeof s.error == "string" && (console.warn("[RemoteControl] microphoneStart rejected by host:", s.error), Ge(s.error));
2015
2051
  break;
2016
2052
  }
2017
2053
  case "terminateAppResult":
@@ -2025,146 +2061,159 @@ function tr(t) {
2025
2061
  y(`Received terminateApp error for unknown or handled id: ${s.id}`);
2026
2062
  break;
2027
2063
  }
2028
- y(`Received terminateApp error for id ${s.id}: ${s.error}`), T(new Error(s.error)), ce.delete(s.id), ie.delete(s.id), clearTimeout(Y.get(s.id)), Y.delete(s.id);
2064
+ y(`Received terminateApp error for id ${s.id}: ${s.error}`), T(new Error(s.error)), ce.delete(s.id), ie.delete(s.id), clearTimeout(I.get(s.id)), I.delete(s.id);
2029
2065
  break;
2030
2066
  }
2031
- const W = ce.get(s.id);
2032
- if (typeof W != "function") {
2067
+ const q = ce.get(s.id);
2068
+ if (typeof q != "function") {
2033
2069
  y(`Received terminateApp result for unknown or handled id: ${s.id}`);
2034
2070
  break;
2035
2071
  }
2036
- le(`Received terminateApp success for id ${s.id}`), W(), ce.delete(s.id), ie.delete(s.id), clearTimeout(Y.get(s.id)), Y.delete(s.id);
2072
+ le(`Received terminateApp success for id ${s.id}`), q(), ce.delete(s.id), ie.delete(s.id), clearTimeout(I.get(s.id)), I.delete(s.id);
2037
2073
  break;
2038
2074
  default:
2039
2075
  y(`Received unhandled message type: ${s.type}`, s);
2040
2076
  break;
2041
2077
  }
2042
- }, I === A) {
2043
- const _ = await A.createOffer({
2078
+ }, R === A) {
2079
+ const O = await A.createOffer({
2044
2080
  offerToReceiveVideo: !0,
2045
- offerToReceiveAudio: !1
2081
+ // This legacy option overrides transceiver directions: false would
2082
+ // turn the speaker's receive-only audio section inactive.
2083
+ offerToReceiveAudio: !0
2046
2084
  });
2047
- if (!C() || I !== A || (await A.setLocalDescription(_), !C() || I !== A))
2085
+ if (!C() || R !== A || (await A.setLocalDescription(O), !C() || R !== A))
2048
2086
  return;
2049
- C() && g === h && h.readyState === WebSocket.OPEN && h.send(
2087
+ C() && g === E && E.readyState === WebSocket.OPEN && E.send(
2050
2088
  JSON.stringify({
2051
2089
  type: "offer",
2052
2090
  ...U ? { displayStreams: !0 } : {},
2053
- ...rt ? { latencyTraceVersion: 1 } : {},
2054
- sdp: _.sdp,
2091
+ speakerAudio: !0,
2092
+ ...st ? { latencyTraceVersion: 1 } : {},
2093
+ sdp: O.sdp,
2055
2094
  sessionId: i
2056
2095
  })
2057
- ), D("Sent offer");
2096
+ ), _("Sent offer");
2058
2097
  }
2059
- } catch (h) {
2060
- if (!C() || h instanceof Error && h.message === "Connection stopped")
2098
+ } catch (E) {
2099
+ if (!C() || E instanceof Error && E.message === "Connection stopped")
2061
2100
  return;
2062
- const R = h instanceof Error ? h.message : String(h);
2063
- D("Error: " + R), ge(R, p);
2101
+ const k = E instanceof Error ? E.message : String(E);
2102
+ _("Error: " + k), ye(k, m);
2064
2103
  }
2065
- }, Ot = () => {
2066
- if (ye) throw new Error("Device stream is disposed");
2067
- ke++, Se = !1, We(null), Ce !== "reconnecting" && (Ce = null), document.addEventListener("visibilitychange", pt), document.hidden || ut(), Ee = !1, Ct(0);
2068
- }, Dt = () => {
2069
- ke++, Se = !1, be(), document.removeEventListener("visibilitychange", pt), de += 1, Fe = 0, ne = !1, qe(), Ie(), _e(), Ce = null, m({ connection: "idle", videoReady: !1, controlReady: !1 }), D("Stopped");
2070
- }, _t = (r, f = "primary") => {
2071
- if (ye) throw new Error("Device stream is disposed");
2072
- if (B.has(r)) throw new Error("Video element is already attached");
2104
+ }, St = () => {
2105
+ if (Ee) throw new Error("Device stream is disposed");
2106
+ Fe++, ve = !1, $e(null), De !== "reconnecting" && (De = null), document.addEventListener("visibilitychange", Tt), document.hidden || Ct(), he = !1, yt(0);
2107
+ }, Kt = () => {
2108
+ Fe++, ve = !1, Re(), document.removeEventListener("visibilitychange", Tt), de += 1, We = 0, re = !1, He(), Ue(), Te(), De = null, p({ connection: "idle", videoReady: !1, controlReady: !1 }), _("Stopped");
2109
+ }, Qt = (n) => {
2110
+ if (Ee) throw new Error("Device stream is disposed");
2111
+ if (Ke.has(n)) throw new Error("Audio element is already attached");
2112
+ Ke.add(n), Ae && Et(n);
2113
+ let f = !1;
2114
+ const c = () => {
2115
+ f || (f = !0, x.delete(c), Ke.delete(n), Fr(n), n.srcObject = null);
2116
+ };
2117
+ return x.add(c), c;
2118
+ }, At = (n, f = "primary") => {
2119
+ if (Ee) throw new Error("Device stream is disposed");
2120
+ if (B.has(n)) throw new Error("Video element is already attached");
2073
2121
  const c = { display: f };
2074
- B.set(r, c);
2122
+ B.set(n, c);
2075
2123
  const d = () => {
2076
- f === "primary" && Ue.has(f) && Rt();
2124
+ f === "primary" && Le.has(f) && Wt();
2077
2125
  };
2078
- r.addEventListener("loadeddata", d);
2079
- const K = Ue.get(f);
2080
- K && ct(r, c, K);
2081
- let p = !1;
2126
+ n.addEventListener("loadeddata", d);
2127
+ const K = Le.get(f);
2128
+ K && ft(n, c, K);
2129
+ let m = !1;
2082
2130
  const C = () => {
2083
- p || (p = !0, V.delete(C), r.removeEventListener("loadeddata", d), c.stop?.(), B.delete(r), r.srcObject = null);
2131
+ m || (m = !0, x.delete(C), n.removeEventListener("loadeddata", d), c.stop?.(), B.delete(n), n.srcObject = null);
2084
2132
  };
2085
- return V.add(C), C;
2133
+ return x.add(C), C;
2086
2134
  };
2087
2135
  return {
2088
- start: Ot,
2089
- stop: Dt,
2090
- attachVideo: _t,
2091
- attachFrameSink: (r, f = "primary") => {
2136
+ start: St,
2137
+ stop: Kt,
2138
+ attachVideo: At,
2139
+ attachAudio: Qt,
2140
+ attachFrameSink: (n, f = "primary") => {
2092
2141
  const c = document.createElement("video");
2093
2142
  c.muted = !0, c.playsInline = !0, c.autoplay = !0;
2094
- const d = _t(c, f);
2095
- let K = !1, p = 0, C = 0;
2096
- const h = () => {
2097
- c.cancelVideoFrameCallback?.(p), cancelAnimationFrame(C);
2098
- }, R = () => {
2143
+ const d = At(c, f);
2144
+ let K = !1, m = 0, C = 0;
2145
+ const E = () => {
2146
+ c.cancelVideoFrameCallback?.(m), cancelAnimationFrame(C);
2147
+ }, k = () => {
2099
2148
  K || !c.srcObject || (c.readyState >= 2 && c.videoWidth > 0 && F(
2100
2149
  "present",
2101
- (...v) => r.present(...v),
2150
+ (...M) => n.present(...M),
2102
2151
  c,
2103
2152
  c.videoWidth,
2104
2153
  c.videoHeight,
2105
2154
  f
2106
- ), !(K || !c.srcObject) && (c.requestVideoFrameCallback ? p = c.requestVideoFrameCallback(R) : C = requestAnimationFrame(R)));
2155
+ ), !(K || !c.srcObject) && (c.requestVideoFrameCallback ? m = c.requestVideoFrameCallback(k) : C = requestAnimationFrame(k)));
2107
2156
  }, b = () => {
2108
- h(), R();
2157
+ E(), k();
2109
2158
  };
2110
- B.get(c).clear = h, c.addEventListener("loadeddata", b);
2159
+ B.get(c).clear = E, c.addEventListener("loadeddata", b);
2111
2160
  const G = () => {
2112
- K || (K = !0, V.delete(G), h(), c.removeEventListener("loadeddata", b), d(), c.remove());
2161
+ K || (K = !0, x.delete(G), E(), c.removeEventListener("loadeddata", b), d(), c.remove());
2113
2162
  };
2114
- return V.delete(d), V.add(G), c.readyState >= 2 && b(), G;
2163
+ return x.delete(d), x.add(G), c.readyState >= 2 && b(), G;
2115
2164
  },
2116
2165
  dispose: () => {
2117
- if (!ye) {
2118
- ye = !0, Dt();
2119
- for (const r of V) r();
2120
- V.clear();
2166
+ if (!Ee) {
2167
+ Ee = !0, Kt();
2168
+ for (const n of x) n();
2169
+ x.clear();
2121
2170
  }
2122
2171
  },
2123
- getState: () => O,
2172
+ getState: () => D,
2124
2173
  /** A new token applies to the next connection attempt and termination probe. */
2125
2174
  updateOptions: ({
2126
- token: r,
2175
+ token: n,
2127
2176
  ...f
2128
2177
  }) => {
2129
- if (ye) throw new Error("Device stream is disposed");
2130
- r !== void 0 && !e.transport && (u = r);
2178
+ if (Ee) throw new Error("Device stream is disposed");
2179
+ n !== void 0 && !e.transport && (u = n);
2131
2180
  const c = e;
2132
2181
  if (e = { ...e, ...f }, c.jitterBufferTargetMs !== e.jitterBufferTargetMs)
2133
- for (const d of I?.getTransceivers() ?? [])
2134
- (d.currentDirection === "recvonly" || d.currentDirection === "sendrecv") && Kt(d.receiver, e.jitterBufferTargetMs);
2135
- !!c.onPlaybackStats != !!e.onPlaybackStats && P(), !!c.microphoneEnabled != !!e.microphoneEnabled && (ze = !l && (e.microphoneEnabled ?? !1), et() ? tt() : $e()), !!c.inspectMode != !!e.inspectMode && (e.inspectMode ? $?.start() : ($?.stop(), Ne !== null && We(null)));
2182
+ for (const d of R?.getTransceivers() ?? [])
2183
+ (d.currentDirection === "recvonly" || d.currentDirection === "sendrecv") && bt(d.receiver, e.jitterBufferTargetMs);
2184
+ !!c.onPlaybackStats != !!e.onPlaybackStats && P(), !!c.microphoneEnabled != !!e.microphoneEnabled && (rt = !l && (e.microphoneEnabled ?? !1), it() ? ot() : Ge()), (c.speakerMuted ?? !0) !== (e.speakerMuted ?? !0) && ht(), !!c.inspectMode != !!e.inspectMode && (e.inspectMode ? $?.start() : ($?.stop(), Ie !== null && $e(null)));
2136
2185
  },
2137
2186
  sendControl: oe,
2138
- sendTouch: (r, f, c, d, K, p = 0) => oe(
2139
- Gt(
2140
- r === "begin" ? 0 : r === "end" ? 1 : 2,
2141
- p,
2187
+ sendTouch: (n, f, c, d, K, m = 0) => oe(
2188
+ nr(
2189
+ n === "begin" ? 0 : n === "end" ? 1 : 2,
2190
+ m,
2142
2191
  d,
2143
2192
  K,
2144
2193
  f,
2145
2194
  c,
2146
- r === "end" ? 0 : 1
2195
+ n === "end" ? 0 : 1
2147
2196
  )
2148
2197
  ),
2149
- sendText: (r) => oe(jt(r)),
2150
- sendDisplayTouch: (r, f, c, d) => oe(en(r, f, c, d)),
2151
- sendDuoControl: Yt,
2152
- pressButton: (r) => {
2153
- const f = { home: 3, back: 4, recents: 187, power: 26 }[r];
2154
- oe(it(0, f, 0, 0)), oe(it(1, f, 0, 0));
2198
+ sendText: (n) => oe(ir(n)),
2199
+ sendDisplayTouch: (n, f, c, d) => oe(lr(n, f, c, d)),
2200
+ sendDuoControl: Bt,
2201
+ pressButton: (n) => {
2202
+ const f = { home: 3, back: 4, recents: 187, power: 26 }[n];
2203
+ oe(ct(0, f, 0, 0)), oe(ct(1, f, 0, 0));
2155
2204
  },
2156
2205
  rotate: () => oe(new Uint8Array([11]).buffer),
2157
2206
  bumpActivity: () => $?.bumpActivity(),
2158
2207
  getAxStatus: () => $?.getStatus() ?? "idle",
2159
- openUrl: (r) => {
2208
+ openUrl: (n) => {
2160
2209
  if (!l) {
2161
2210
  if (!g || g.readyState !== WebSocket.OPEN) {
2162
2211
  y("WebSocket not open, cannot send open_url command.");
2163
2212
  return;
2164
2213
  }
2165
2214
  try {
2166
- const f = decodeURIComponent(r);
2167
- D("Opening URL"), g.send(
2215
+ const f = decodeURIComponent(n);
2216
+ _("Opening URL"), g.send(
2168
2217
  JSON.stringify({
2169
2218
  type: "openUrl",
2170
2219
  url: f,
@@ -2172,10 +2221,10 @@ function tr(t) {
2172
2221
  })
2173
2222
  );
2174
2223
  } catch (f) {
2175
- y("Error decoding or sending URL :", { error: f, url: r }), g.send(
2224
+ y("Error decoding or sending URL :", { error: f, url: n }), g.send(
2176
2225
  JSON.stringify({
2177
2226
  type: "openUrl",
2178
- url: r,
2227
+ url: n,
2179
2228
  sessionId: i
2180
2229
  })
2181
2230
  );
@@ -2183,44 +2232,44 @@ function tr(t) {
2183
2232
  $?.bumpActivity();
2184
2233
  }
2185
2234
  },
2186
- sendKeyEvent: (r) => {
2187
- if (!x || x.readyState !== "open") {
2188
- y("Data channel not ready for imperative key command:", x?.readyState);
2235
+ sendKeyEvent: (n) => {
2236
+ if (!W || W.readyState !== "open") {
2237
+ y("Data channel not ready for imperative key command:", W?.readyState);
2189
2238
  return;
2190
2239
  }
2191
- if (E === "macos") {
2192
- const p = Tt(r.code);
2193
- if (p === void 0) {
2194
- y(`Unknown event.code for imperative command: ${r.code}`);
2240
+ if (h === "macos") {
2241
+ const m = Mt(n.code);
2242
+ if (m === void 0) {
2243
+ y(`Unknown event.code for imperative command: ${n.code}`);
2195
2244
  return;
2196
2245
  }
2197
2246
  const C = [
2198
- [r.metaKey, "Meta"],
2199
- [r.ctrlKey, "Control"],
2200
- [r.altKey, "Alt"],
2201
- [r.shiftKey, "Shift"]
2202
- ].filter(([R, b]) => R && !r.code.startsWith(b)).map(([, R]) => Tt(`${R}Left`)), h = (R, b) => oe(Xt(R, b));
2203
- if (r.type === "keydown") {
2204
- for (const R of C) h(Ge.DOWN, R);
2205
- h(Ge.DOWN, p);
2247
+ [n.metaKey, "Meta"],
2248
+ [n.ctrlKey, "Control"],
2249
+ [n.altKey, "Alt"],
2250
+ [n.shiftKey, "Shift"]
2251
+ ].filter(([k, b]) => k && !n.code.startsWith(b)).map(([, k]) => Mt(`${k}Left`)), E = (k, b) => oe(or(k, b));
2252
+ if (n.type === "keydown") {
2253
+ for (const k of C) E(Qe.DOWN, k);
2254
+ E(Qe.DOWN, m);
2206
2255
  } else {
2207
- h(Ge.UP, p);
2208
- for (const R of [...C].reverse()) h(Ge.UP, R);
2256
+ E(Qe.UP, m);
2257
+ for (const k of [...C].reverse()) E(Qe.UP, k);
2209
2258
  }
2210
2259
  return;
2211
2260
  }
2212
- const f = Ht[r.code];
2261
+ const f = tr[n.code];
2213
2262
  if (!f) {
2214
- y(`Unknown event.code for imperative command: ${r.code}`);
2263
+ y(`Unknown event.code for imperative command: ${n.code}`);
2215
2264
  return;
2216
2265
  }
2217
- let c = o.META_NONE;
2218
- r.shiftKey && (c |= o.META_SHIFT_ON), r.altKey && (c |= o.META_ALT_ON), r.ctrlKey && (c |= o.META_CTRL_ON), r.metaKey && (c |= o.META_META_ON);
2219
- const d = r.type === "keydown" ? o.ACTION_DOWN : o.ACTION_UP;
2266
+ let c = a.META_NONE;
2267
+ n.shiftKey && (c |= a.META_SHIFT_ON), n.altKey && (c |= a.META_ALT_ON), n.ctrlKey && (c |= a.META_CTRL_ON), n.metaKey && (c |= a.META_META_ON);
2268
+ const d = n.type === "keydown" ? a.ACTION_DOWN : a.ACTION_UP;
2220
2269
  le(
2221
- `Sending Imperative Key Command: code=${r.code}, keycode=${f}, action=${d}, meta=${c}`
2270
+ `Sending Imperative Key Command: code=${n.code}, keycode=${f}, action=${d}, meta=${c}`
2222
2271
  );
2223
- const K = it(
2272
+ const K = ct(
2224
2273
  d,
2225
2274
  f,
2226
2275
  0,
@@ -2229,99 +2278,101 @@ function tr(t) {
2229
2278
  );
2230
2279
  K && oe(K);
2231
2280
  },
2232
- screenshot: (r) => new Promise((f, c) => {
2281
+ screenshot: (n) => new Promise((f, c) => {
2233
2282
  if (!g || g.readyState !== WebSocket.OPEN)
2234
2283
  return y("WebSocket not open, cannot send screenshot command."), c(new Error("WebSocket is not connected or connection is not open."));
2235
2284
  const d = `ui-ss-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, K = {
2236
- type: r ? "screenshotDisplay" : "screenshot",
2237
- ...r ? { display: r } : {},
2285
+ type: n ? "screenshotDisplay" : "screenshot",
2286
+ ...n ? { display: n } : {},
2238
2287
  id: d
2239
2288
  };
2240
- re.set(d, f), Z.set(d, c), le("Sending screenshot request:", K);
2289
+ ne.set(d, f), Z.set(d, c), le("Sending screenshot request:", K);
2241
2290
  try {
2242
2291
  g.send(JSON.stringify(K));
2243
- } catch (p) {
2244
- y("Failed to send screenshot request immediately:", p), re.delete(d), Z.delete(d), c(p);
2292
+ } catch (m) {
2293
+ y("Failed to send screenshot request immediately:", m), ne.delete(d), Z.delete(d), c(m);
2245
2294
  return;
2246
2295
  }
2247
- Y.set(
2296
+ I.set(
2248
2297
  d,
2249
2298
  setTimeout(() => {
2250
- Y.delete(d), re.has(d) && (y(`Screenshot request timed out for id ${d}`), Z.get(d)?.(new Error("Screenshot request timed out")), re.delete(d), Z.delete(d));
2299
+ I.delete(d), ne.has(d) && (y(`Screenshot request timed out for id ${d}`), Z.get(d)?.(new Error("Screenshot request timed out")), ne.delete(d), Z.delete(d));
2251
2300
  }, 3e4)
2252
2301
  );
2253
2302
  }),
2254
- terminateApp: (r) => l ? Promise.reject(new Error("Device is watch-only")) : new Promise((f, c) => {
2303
+ terminateApp: (n) => l ? Promise.reject(new Error("Device is watch-only")) : new Promise((f, c) => {
2255
2304
  if (!g || g.readyState !== WebSocket.OPEN)
2256
2305
  return y("WebSocket not open, cannot send terminateApp command."), c(new Error("WebSocket is not connected or connection is not open."));
2257
2306
  const d = `ui-term-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, K = {
2258
2307
  type: "terminateApp",
2259
2308
  id: d,
2260
- bundleId: r
2309
+ bundleId: n
2261
2310
  };
2262
2311
  ce.set(d, f), ie.set(d, c), le("Sending terminateApp request:", K);
2263
2312
  try {
2264
2313
  g.send(JSON.stringify(K));
2265
- } catch (p) {
2266
- y("Failed to send terminateApp request immediately:", p), ce.delete(d), ie.delete(d), c(p);
2314
+ } catch (m) {
2315
+ y("Failed to send terminateApp request immediately:", m), ce.delete(d), ie.delete(d), c(m);
2267
2316
  return;
2268
2317
  }
2269
- $?.bumpActivity(), Y.set(
2318
+ $?.bumpActivity(), I.set(
2270
2319
  d,
2271
2320
  setTimeout(() => {
2272
- Y.delete(d), ce.has(d) && (y(`terminateApp request timed out for id ${d}`), ie.get(d)?.(new Error("terminateApp request timed out")), ce.delete(d), ie.delete(d));
2321
+ I.delete(d), ce.has(d) && (y(`terminateApp request timed out for id ${d}`), ie.get(d)?.(new Error("terminateApp request timed out")), ce.delete(d), ie.delete(d));
2273
2322
  }, 3e4)
2274
2323
  );
2275
2324
  }),
2276
- reconnect: () => Ot(),
2325
+ reconnect: () => St(),
2277
2326
  refreshAxTree: async () => {
2278
- const r = $;
2279
- if (!r)
2327
+ const n = $;
2328
+ if (!n)
2280
2329
  throw new Error("Inspect mode is not active");
2281
- return r.refresh();
2330
+ return n.refresh();
2282
2331
  },
2283
- getAxSnapshot: () => Ne
2332
+ getAxSnapshot: () => Ie
2284
2333
  };
2285
2334
  }
2286
- const kn = (t) => typeof t.message == "string" ? t.message : typeof t.error == "string" ? t.error : null, Pn = (t) => typeof t.dataUri == "string" ? { dataUri: t.dataUri } : typeof t.base64 == "string" ? t.base64.startsWith("data:") ? { dataUri: t.base64 } : { dataUri: `data:${t.base64.startsWith("/9j/") ? "image/jpeg" : "image/png"};base64,${t.base64}` } : null;
2335
+ const $r = (t) => typeof t.message == "string" ? t.message : typeof t.error == "string" ? t.error : null, Hr = (t) => typeof t.dataUri == "string" ? { dataUri: t.dataUri } : typeof t.base64 == "string" ? t.base64.startsWith("data:") ? { dataUri: t.base64 } : { dataUri: `data:${t.base64.startsWith("/9j/") ? "image/jpeg" : "image/png"};base64,${t.base64}` } : null;
2287
2336
  export {
2288
- ot as A,
2289
- it as B,
2290
- o as C,
2291
- $n as D,
2292
- Gt as E,
2293
- Ht as F,
2294
- je as G,
2295
- Gn as H,
2296
- Bn as I,
2297
- ee as J,
2298
- en as K,
2299
- zt as L,
2300
- Ge as M,
2301
- zn as a,
2302
- Zn as b,
2303
- er as c,
2304
- dn as d,
2305
- un as e,
2306
- Qn as f,
2307
- an as g,
2308
- Vn as h,
2309
- qn as i,
2310
- Qt as j,
2311
- Xn as k,
2312
- jn as l,
2313
- Jn as m,
2314
- ln as n,
2315
- xn as o,
2316
- Hn as p,
2317
- Wn as q,
2318
- fn as r,
2319
- bn as s,
2320
- Xt as t,
2337
+ lt as A,
2338
+ Mt as B,
2339
+ ir as C,
2340
+ en as D,
2341
+ ct as E,
2342
+ a as F,
2343
+ nr as G,
2344
+ nn as H,
2345
+ tr as I,
2346
+ ze as J,
2347
+ jr as K,
2348
+ ee as L,
2349
+ Qe as M,
2350
+ lr as N,
2351
+ sr as O,
2352
+ cn as a,
2353
+ ln as b,
2354
+ dn as c,
2355
+ Or as d,
2356
+ Dr as e,
2357
+ sn as f,
2358
+ hr as g,
2359
+ Zr as h,
2360
+ zr as i,
2361
+ ar as j,
2362
+ an as k,
2363
+ on as l,
2364
+ rn as m,
2365
+ Cr as n,
2366
+ Xr as o,
2367
+ tn as p,
2368
+ Qr as q,
2369
+ _r as r,
2370
+ Br as s,
2371
+ or as t,
2321
2372
  F as u,
2322
- tr as v,
2323
- le as w,
2324
- y as x,
2325
- Tt as y,
2326
- jt as z
2373
+ un as v,
2374
+ Fr as w,
2375
+ Lt as x,
2376
+ le as y,
2377
+ y as z
2327
2378
  };