@limrun/ui 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GLTFLoader-BjfxfJc4.mjs → GLTFLoader-CEdCEYr6.mjs} +1 -1
- package/dist/{GLTFLoader-Ccp1cQVL.js → GLTFLoader-yqDaHF46.js} +1 -1
- package/dist/core-BqXmROsc.mjs +2162 -0
- package/dist/core-D7ODbXln.js +2 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{duo-frame-D9832t6H.js → duo-frame-BMVxq-Qi.js} +2 -2
- package/dist/{duo-frame-CMiDITQA.mjs → duo-frame-DCl_2GS3.mjs} +3 -3
- package/dist/{duo-view-tndcvbIi.mjs → duo-view-DhzmW9X6.mjs} +2 -2
- package/dist/{duo-view-Bhr7zyWr.js → duo-view-UZazbOh-.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/lite.cjs +1 -1
- package/dist/lite.js +2 -2
- package/dist/remote-control-Cl8nEKUE.js +1 -0
- package/dist/{remote-control-BBgt4TkM.mjs → remote-control-aGoEKYFB.mjs} +388 -405
- package/package.json +1 -3
- package/dist/core-BhHpU_lr.mjs +0 -2113
- package/dist/core-DkhLItUD.js +0 -2
- package/dist/remote-control-GLVdY8Xa.js +0 -1
|
@@ -0,0 +1,2162 @@
|
|
|
1
|
+
const Xe = {
|
|
2
|
+
INJECT_KEYCODE: 0,
|
|
3
|
+
INJECT_TEXT: 1,
|
|
4
|
+
INJECT_TOUCH_EVENT: 2,
|
|
5
|
+
// iOS-specific: send two touch points in one message (Option/Alt+drag pinch)
|
|
6
|
+
INJECT_TWO_FINGER_TOUCH_EVENT: 18,
|
|
7
|
+
INJECT_SCROLL_EVENT: 3,
|
|
8
|
+
BACK_OR_SCREEN_ON: 4,
|
|
9
|
+
EXPAND_NOTIFICATION_PANEL: 5,
|
|
10
|
+
EXPAND_SETTINGS_PANEL: 6,
|
|
11
|
+
COLLAPSE_PANELS: 7,
|
|
12
|
+
GET_CLIPBOARD: 8,
|
|
13
|
+
SET_CLIPBOARD: 9,
|
|
14
|
+
SET_DISPLAY_POWER: 10,
|
|
15
|
+
ROTATE_DEVICE: 11
|
|
16
|
+
}, Je = {
|
|
17
|
+
ACTION_DOWN: 0,
|
|
18
|
+
ACTION_UP: 1,
|
|
19
|
+
ACTION_MOVE: 2,
|
|
20
|
+
ACTION_CANCEL: 3,
|
|
21
|
+
ACTION_POINTER_DOWN: 5,
|
|
22
|
+
ACTION_POINTER_UP: 6,
|
|
23
|
+
BUTTON_PRIMARY: 1,
|
|
24
|
+
BUTTON_SECONDARY: 2,
|
|
25
|
+
BUTTON_TERTIARY: 4
|
|
26
|
+
}, o = {
|
|
27
|
+
// Actions
|
|
28
|
+
ACTION_DOWN: 0,
|
|
29
|
+
ACTION_UP: 1,
|
|
30
|
+
// Meta state flags (from android.view.KeyEvent)
|
|
31
|
+
META_NONE: 0,
|
|
32
|
+
META_SHIFT_ON: 1,
|
|
33
|
+
META_ALT_ON: 2,
|
|
34
|
+
META_CTRL_ON: 4096,
|
|
35
|
+
// META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON
|
|
36
|
+
META_META_ON: 65536,
|
|
37
|
+
// META_META_LEFT_ON | META_META_RIGHT_ON
|
|
38
|
+
// Keycodes (from android.view.KeyEvent)
|
|
39
|
+
KEYCODE_UNKNOWN: 0,
|
|
40
|
+
KEYCODE_SOFT_LEFT: 1,
|
|
41
|
+
KEYCODE_SOFT_RIGHT: 2,
|
|
42
|
+
KEYCODE_HOME: 3,
|
|
43
|
+
KEYCODE_BACK: 4,
|
|
44
|
+
KEYCODE_CALL: 5,
|
|
45
|
+
KEYCODE_ENDCALL: 6,
|
|
46
|
+
KEYCODE_0: 7,
|
|
47
|
+
KEYCODE_1: 8,
|
|
48
|
+
KEYCODE_2: 9,
|
|
49
|
+
KEYCODE_3: 10,
|
|
50
|
+
KEYCODE_4: 11,
|
|
51
|
+
KEYCODE_5: 12,
|
|
52
|
+
KEYCODE_6: 13,
|
|
53
|
+
KEYCODE_7: 14,
|
|
54
|
+
KEYCODE_8: 15,
|
|
55
|
+
KEYCODE_9: 16,
|
|
56
|
+
KEYCODE_STAR: 17,
|
|
57
|
+
KEYCODE_POUND: 18,
|
|
58
|
+
DPAD_UP: 19,
|
|
59
|
+
// KEYCODE_DPAD_UP
|
|
60
|
+
DPAD_DOWN: 20,
|
|
61
|
+
// KEYCODE_DPAD_DOWN
|
|
62
|
+
DPAD_LEFT: 21,
|
|
63
|
+
// KEYCODE_DPAD_LEFT
|
|
64
|
+
DPAD_RIGHT: 22,
|
|
65
|
+
// KEYCODE_DPAD_RIGHT
|
|
66
|
+
KEYCODE_DPAD_CENTER: 23,
|
|
67
|
+
KEYCODE_VOLUME_UP: 24,
|
|
68
|
+
KEYCODE_VOLUME_DOWN: 25,
|
|
69
|
+
KEYCODE_POWER: 26,
|
|
70
|
+
KEYCODE_CAMERA: 27,
|
|
71
|
+
KEYCODE_CLEAR: 28,
|
|
72
|
+
KEYCODE_A: 29,
|
|
73
|
+
KEYCODE_B: 30,
|
|
74
|
+
KEYCODE_C: 31,
|
|
75
|
+
KEYCODE_D: 32,
|
|
76
|
+
KEYCODE_E: 33,
|
|
77
|
+
KEYCODE_F: 34,
|
|
78
|
+
KEYCODE_G: 35,
|
|
79
|
+
KEYCODE_H: 36,
|
|
80
|
+
KEYCODE_I: 37,
|
|
81
|
+
KEYCODE_J: 38,
|
|
82
|
+
KEYCODE_K: 39,
|
|
83
|
+
KEYCODE_L: 40,
|
|
84
|
+
KEYCODE_M: 41,
|
|
85
|
+
KEYCODE_N: 42,
|
|
86
|
+
KEYCODE_O: 43,
|
|
87
|
+
KEYCODE_P: 44,
|
|
88
|
+
KEYCODE_Q: 45,
|
|
89
|
+
KEYCODE_R: 46,
|
|
90
|
+
KEYCODE_S: 47,
|
|
91
|
+
KEYCODE_T: 48,
|
|
92
|
+
KEYCODE_U: 49,
|
|
93
|
+
KEYCODE_V: 50,
|
|
94
|
+
KEYCODE_W: 51,
|
|
95
|
+
KEYCODE_X: 52,
|
|
96
|
+
KEYCODE_Y: 53,
|
|
97
|
+
KEYCODE_Z: 54,
|
|
98
|
+
KEYCODE_COMMA: 55,
|
|
99
|
+
KEYCODE_PERIOD: 56,
|
|
100
|
+
KEYCODE_ALT_LEFT: 57,
|
|
101
|
+
KEYCODE_ALT_RIGHT: 58,
|
|
102
|
+
KEYCODE_SHIFT_LEFT: 59,
|
|
103
|
+
KEYCODE_SHIFT_RIGHT: 60,
|
|
104
|
+
KEYCODE_TAB: 61,
|
|
105
|
+
KEYCODE_SPACE: 62,
|
|
106
|
+
KEYCODE_SYM: 63,
|
|
107
|
+
KEYCODE_EXPLORER: 64,
|
|
108
|
+
KEYCODE_ENVELOPE: 65,
|
|
109
|
+
ENTER: 66,
|
|
110
|
+
// KEYCODE_ENTER
|
|
111
|
+
DEL: 67,
|
|
112
|
+
// KEYCODE_DEL (Backspace)
|
|
113
|
+
KEYCODE_GRAVE: 68,
|
|
114
|
+
// `
|
|
115
|
+
KEYCODE_MINUS: 69,
|
|
116
|
+
// -
|
|
117
|
+
KEYCODE_EQUALS: 70,
|
|
118
|
+
// =
|
|
119
|
+
KEYCODE_LEFT_BRACKET: 71,
|
|
120
|
+
// [
|
|
121
|
+
KEYCODE_RIGHT_BRACKET: 72,
|
|
122
|
+
// ]
|
|
123
|
+
KEYCODE_BACKSLASH: 73,
|
|
124
|
+
// \
|
|
125
|
+
KEYCODE_SEMICOLON: 74,
|
|
126
|
+
// ;
|
|
127
|
+
KEYCODE_APOSTROPHE: 75,
|
|
128
|
+
// '
|
|
129
|
+
KEYCODE_SLASH: 76,
|
|
130
|
+
// /
|
|
131
|
+
KEYCODE_AT: 77,
|
|
132
|
+
// @
|
|
133
|
+
KEYCODE_NUM: 78,
|
|
134
|
+
KEYCODE_HEADSETHOOK: 79,
|
|
135
|
+
KEYCODE_FOCUS: 80,
|
|
136
|
+
KEYCODE_PLUS: 81,
|
|
137
|
+
MENU: 82,
|
|
138
|
+
// KEYCODE_MENU
|
|
139
|
+
KEYCODE_NOTIFICATION: 83,
|
|
140
|
+
KEYCODE_SEARCH: 84,
|
|
141
|
+
KEYCODE_MEDIA_PLAY_PAUSE: 85,
|
|
142
|
+
KEYCODE_MEDIA_STOP: 86,
|
|
143
|
+
KEYCODE_MEDIA_NEXT: 87,
|
|
144
|
+
KEYCODE_MEDIA_PREVIOUS: 88,
|
|
145
|
+
KEYCODE_MEDIA_REWIND: 89,
|
|
146
|
+
KEYCODE_MEDIA_FAST_FORWARD: 90,
|
|
147
|
+
KEYCODE_MUTE: 91,
|
|
148
|
+
KEYCODE_PAGE_UP: 92,
|
|
149
|
+
KEYCODE_PAGE_DOWN: 93,
|
|
150
|
+
KEYCODE_PICTSYMBOLS: 94,
|
|
151
|
+
KEYCODE_SWITCH_CHARSET: 95,
|
|
152
|
+
KEYCODE_BUTTON_A: 96,
|
|
153
|
+
KEYCODE_BUTTON_B: 97,
|
|
154
|
+
KEYCODE_BUTTON_C: 98,
|
|
155
|
+
KEYCODE_BUTTON_X: 99,
|
|
156
|
+
KEYCODE_BUTTON_Y: 100,
|
|
157
|
+
KEYCODE_BUTTON_Z: 101,
|
|
158
|
+
KEYCODE_BUTTON_L1: 102,
|
|
159
|
+
KEYCODE_BUTTON_R1: 103,
|
|
160
|
+
KEYCODE_BUTTON_L2: 104,
|
|
161
|
+
KEYCODE_BUTTON_R2: 105,
|
|
162
|
+
KEYCODE_BUTTON_THUMBL: 106,
|
|
163
|
+
KEYCODE_BUTTON_THUMBR: 107,
|
|
164
|
+
KEYCODE_BUTTON_START: 108,
|
|
165
|
+
KEYCODE_BUTTON_SELECT: 109,
|
|
166
|
+
KEYCODE_BUTTON_MODE: 110,
|
|
167
|
+
KEYCODE_ESCAPE: 111,
|
|
168
|
+
FORWARD_DEL: 112,
|
|
169
|
+
// KEYCODE_FORWARD_DEL (Delete key)
|
|
170
|
+
KEYCODE_CTRL_LEFT: 113,
|
|
171
|
+
KEYCODE_CTRL_RIGHT: 114,
|
|
172
|
+
KEYCODE_CAPS_LOCK: 115,
|
|
173
|
+
KEYCODE_SCROLL_LOCK: 116,
|
|
174
|
+
KEYCODE_META_LEFT: 117,
|
|
175
|
+
KEYCODE_META_RIGHT: 118,
|
|
176
|
+
KEYCODE_FUNCTION: 119,
|
|
177
|
+
KEYCODE_SYSRQ: 120,
|
|
178
|
+
KEYCODE_BREAK: 121,
|
|
179
|
+
KEYCODE_MOVE_HOME: 122,
|
|
180
|
+
KEYCODE_MOVE_END: 123,
|
|
181
|
+
KEYCODE_INSERT: 124,
|
|
182
|
+
KEYCODE_FORWARD: 125,
|
|
183
|
+
KEYCODE_MEDIA_PLAY: 126,
|
|
184
|
+
KEYCODE_MEDIA_PAUSE: 127,
|
|
185
|
+
KEYCODE_MEDIA_CLOSE: 128,
|
|
186
|
+
KEYCODE_MEDIA_EJECT: 129,
|
|
187
|
+
KEYCODE_MEDIA_RECORD: 130,
|
|
188
|
+
KEYCODE_F1: 131,
|
|
189
|
+
KEYCODE_F2: 132,
|
|
190
|
+
KEYCODE_F3: 133,
|
|
191
|
+
KEYCODE_F4: 134,
|
|
192
|
+
KEYCODE_F5: 135,
|
|
193
|
+
KEYCODE_F6: 136,
|
|
194
|
+
KEYCODE_F7: 137,
|
|
195
|
+
KEYCODE_F8: 138,
|
|
196
|
+
KEYCODE_F9: 139,
|
|
197
|
+
KEYCODE_F10: 140,
|
|
198
|
+
KEYCODE_F11: 141,
|
|
199
|
+
KEYCODE_F12: 142,
|
|
200
|
+
KEYCODE_NUM_LOCK: 143,
|
|
201
|
+
KEYCODE_NUMPAD_0: 144,
|
|
202
|
+
KEYCODE_NUMPAD_1: 145,
|
|
203
|
+
KEYCODE_NUMPAD_2: 146,
|
|
204
|
+
KEYCODE_NUMPAD_3: 147,
|
|
205
|
+
KEYCODE_NUMPAD_4: 148,
|
|
206
|
+
KEYCODE_NUMPAD_5: 149,
|
|
207
|
+
KEYCODE_NUMPAD_6: 150,
|
|
208
|
+
KEYCODE_NUMPAD_7: 151,
|
|
209
|
+
KEYCODE_NUMPAD_8: 152,
|
|
210
|
+
KEYCODE_NUMPAD_9: 153,
|
|
211
|
+
KEYCODE_NUMPAD_DIVIDE: 154,
|
|
212
|
+
KEYCODE_NUMPAD_MULTIPLY: 155,
|
|
213
|
+
KEYCODE_NUMPAD_SUBTRACT: 156,
|
|
214
|
+
KEYCODE_NUMPAD_ADD: 157,
|
|
215
|
+
KEYCODE_NUMPAD_DOT: 158,
|
|
216
|
+
KEYCODE_NUMPAD_COMMA: 159,
|
|
217
|
+
KEYCODE_NUMPAD_ENTER: 160,
|
|
218
|
+
KEYCODE_NUMPAD_EQUALS: 161,
|
|
219
|
+
KEYCODE_NUMPAD_LEFT_PAREN: 162,
|
|
220
|
+
KEYCODE_NUMPAD_RIGHT_PAREN: 163,
|
|
221
|
+
KEYCODE_VOLUME_MUTE: 164,
|
|
222
|
+
KEYCODE_INFO: 165,
|
|
223
|
+
KEYCODE_CHANNEL_UP: 166,
|
|
224
|
+
KEYCODE_CHANNEL_DOWN: 167,
|
|
225
|
+
KEYCODE_ZOOM_IN: 168,
|
|
226
|
+
KEYCODE_ZOOM_OUT: 169,
|
|
227
|
+
KEYCODE_TV: 170,
|
|
228
|
+
KEYCODE_WINDOW: 171,
|
|
229
|
+
KEYCODE_GUIDE: 172,
|
|
230
|
+
KEYCODE_DVR: 173,
|
|
231
|
+
KEYCODE_BOOKMARK: 174,
|
|
232
|
+
KEYCODE_CAPTIONS: 175,
|
|
233
|
+
KEYCODE_SETTINGS: 176,
|
|
234
|
+
KEYCODE_TV_POWER: 177,
|
|
235
|
+
KEYCODE_TV_INPUT: 178,
|
|
236
|
+
KEYCODE_STB_POWER: 179,
|
|
237
|
+
KEYCODE_STB_INPUT: 180,
|
|
238
|
+
KEYCODE_AVR_POWER: 181,
|
|
239
|
+
KEYCODE_AVR_INPUT: 182,
|
|
240
|
+
KEYCODE_PROG_RED: 183,
|
|
241
|
+
KEYCODE_PROG_GREEN: 184,
|
|
242
|
+
KEYCODE_PROG_YELLOW: 185,
|
|
243
|
+
KEYCODE_PROG_BLUE: 186,
|
|
244
|
+
KEYCODE_APP_SWITCH: 187,
|
|
245
|
+
KEYCODE_LANGUAGE_SWITCH: 204,
|
|
246
|
+
KEYCODE_ASSIST: 219,
|
|
247
|
+
KEYCODE_BRIGHTNESS_DOWN: 220,
|
|
248
|
+
KEYCODE_BRIGHTNESS_UP: 221,
|
|
249
|
+
KEYCODE_SLEEP: 223,
|
|
250
|
+
KEYCODE_WAKEUP: 224,
|
|
251
|
+
KEYCODE_SOFT_SLEEP: 276
|
|
252
|
+
}, Vt = {
|
|
253
|
+
KeyA: o.KEYCODE_A,
|
|
254
|
+
KeyB: o.KEYCODE_B,
|
|
255
|
+
KeyC: o.KEYCODE_C,
|
|
256
|
+
KeyD: o.KEYCODE_D,
|
|
257
|
+
KeyE: o.KEYCODE_E,
|
|
258
|
+
KeyF: o.KEYCODE_F,
|
|
259
|
+
KeyG: o.KEYCODE_G,
|
|
260
|
+
KeyH: o.KEYCODE_H,
|
|
261
|
+
KeyI: o.KEYCODE_I,
|
|
262
|
+
KeyJ: o.KEYCODE_J,
|
|
263
|
+
KeyK: o.KEYCODE_K,
|
|
264
|
+
KeyL: o.KEYCODE_L,
|
|
265
|
+
KeyM: o.KEYCODE_M,
|
|
266
|
+
KeyN: o.KEYCODE_N,
|
|
267
|
+
KeyO: o.KEYCODE_O,
|
|
268
|
+
KeyP: o.KEYCODE_P,
|
|
269
|
+
KeyQ: o.KEYCODE_Q,
|
|
270
|
+
KeyR: o.KEYCODE_R,
|
|
271
|
+
KeyS: o.KEYCODE_S,
|
|
272
|
+
KeyT: o.KEYCODE_T,
|
|
273
|
+
KeyU: o.KEYCODE_U,
|
|
274
|
+
KeyV: o.KEYCODE_V,
|
|
275
|
+
KeyW: o.KEYCODE_W,
|
|
276
|
+
KeyX: o.KEYCODE_X,
|
|
277
|
+
KeyY: o.KEYCODE_Y,
|
|
278
|
+
KeyZ: o.KEYCODE_Z,
|
|
279
|
+
Digit0: o.KEYCODE_0,
|
|
280
|
+
Digit1: o.KEYCODE_1,
|
|
281
|
+
Digit2: o.KEYCODE_2,
|
|
282
|
+
Digit3: o.KEYCODE_3,
|
|
283
|
+
Digit4: o.KEYCODE_4,
|
|
284
|
+
Digit5: o.KEYCODE_5,
|
|
285
|
+
Digit6: o.KEYCODE_6,
|
|
286
|
+
Digit7: o.KEYCODE_7,
|
|
287
|
+
Digit8: o.KEYCODE_8,
|
|
288
|
+
Digit9: o.KEYCODE_9,
|
|
289
|
+
Backquote: o.KEYCODE_GRAVE,
|
|
290
|
+
Minus: o.KEYCODE_MINUS,
|
|
291
|
+
Equal: o.KEYCODE_EQUALS,
|
|
292
|
+
BracketLeft: o.KEYCODE_LEFT_BRACKET,
|
|
293
|
+
BracketRight: o.KEYCODE_RIGHT_BRACKET,
|
|
294
|
+
Backslash: o.KEYCODE_BACKSLASH,
|
|
295
|
+
Semicolon: o.KEYCODE_SEMICOLON,
|
|
296
|
+
Quote: o.KEYCODE_APOSTROPHE,
|
|
297
|
+
Comma: o.KEYCODE_COMMA,
|
|
298
|
+
Period: o.KEYCODE_PERIOD,
|
|
299
|
+
Slash: o.KEYCODE_SLASH,
|
|
300
|
+
Space: o.KEYCODE_SPACE,
|
|
301
|
+
Tab: o.KEYCODE_TAB,
|
|
302
|
+
Escape: o.KEYCODE_ESCAPE,
|
|
303
|
+
ArrowUp: o.DPAD_UP,
|
|
304
|
+
ArrowDown: o.DPAD_DOWN,
|
|
305
|
+
ArrowLeft: o.DPAD_LEFT,
|
|
306
|
+
ArrowRight: o.DPAD_RIGHT,
|
|
307
|
+
Enter: o.ENTER,
|
|
308
|
+
Backspace: o.DEL,
|
|
309
|
+
Delete: o.FORWARD_DEL,
|
|
310
|
+
Home: o.KEYCODE_MOVE_HOME,
|
|
311
|
+
End: o.KEYCODE_MOVE_END,
|
|
312
|
+
PageUp: o.KEYCODE_PAGE_UP,
|
|
313
|
+
PageDown: o.KEYCODE_PAGE_DOWN,
|
|
314
|
+
Insert: o.KEYCODE_INSERT,
|
|
315
|
+
F1: o.KEYCODE_F1,
|
|
316
|
+
F2: o.KEYCODE_F2,
|
|
317
|
+
F3: o.KEYCODE_F3,
|
|
318
|
+
F4: o.KEYCODE_F4,
|
|
319
|
+
F5: o.KEYCODE_F5,
|
|
320
|
+
F6: o.KEYCODE_F6,
|
|
321
|
+
F7: o.KEYCODE_F7,
|
|
322
|
+
F8: o.KEYCODE_F8,
|
|
323
|
+
F9: o.KEYCODE_F9,
|
|
324
|
+
F10: o.KEYCODE_F10,
|
|
325
|
+
F11: o.KEYCODE_F11,
|
|
326
|
+
F12: o.KEYCODE_F12,
|
|
327
|
+
ShiftLeft: o.KEYCODE_SHIFT_LEFT,
|
|
328
|
+
ShiftRight: o.KEYCODE_SHIFT_RIGHT,
|
|
329
|
+
ControlLeft: o.KEYCODE_CTRL_LEFT,
|
|
330
|
+
ControlRight: o.KEYCODE_CTRL_RIGHT,
|
|
331
|
+
AltLeft: o.KEYCODE_ALT_LEFT,
|
|
332
|
+
AltRight: o.KEYCODE_ALT_RIGHT,
|
|
333
|
+
MetaLeft: o.KEYCODE_META_LEFT,
|
|
334
|
+
MetaRight: o.KEYCODE_META_RIGHT,
|
|
335
|
+
// Windows/Command key
|
|
336
|
+
ContextMenu: o.MENU,
|
|
337
|
+
// Often the Menu key
|
|
338
|
+
// Numpad mappings
|
|
339
|
+
Numpad0: o.KEYCODE_NUMPAD_0,
|
|
340
|
+
Numpad1: o.KEYCODE_NUMPAD_1,
|
|
341
|
+
Numpad2: o.KEYCODE_NUMPAD_2,
|
|
342
|
+
Numpad3: o.KEYCODE_NUMPAD_3,
|
|
343
|
+
Numpad4: o.KEYCODE_NUMPAD_4,
|
|
344
|
+
Numpad5: o.KEYCODE_NUMPAD_5,
|
|
345
|
+
Numpad6: o.KEYCODE_NUMPAD_6,
|
|
346
|
+
Numpad7: o.KEYCODE_NUMPAD_7,
|
|
347
|
+
Numpad8: o.KEYCODE_NUMPAD_8,
|
|
348
|
+
Numpad9: o.KEYCODE_NUMPAD_9,
|
|
349
|
+
NumpadDivide: o.KEYCODE_NUMPAD_DIVIDE,
|
|
350
|
+
NumpadMultiply: o.KEYCODE_NUMPAD_MULTIPLY,
|
|
351
|
+
NumpadSubtract: o.KEYCODE_NUMPAD_SUBTRACT,
|
|
352
|
+
NumpadAdd: o.KEYCODE_NUMPAD_ADD,
|
|
353
|
+
NumpadDecimal: o.KEYCODE_NUMPAD_DOT,
|
|
354
|
+
NumpadComma: o.KEYCODE_NUMPAD_COMMA,
|
|
355
|
+
// Some numpads have comma
|
|
356
|
+
NumpadEnter: o.KEYCODE_NUMPAD_ENTER,
|
|
357
|
+
NumpadEqual: o.KEYCODE_NUMPAD_EQUALS
|
|
358
|
+
};
|
|
359
|
+
function Ht(t, e, r, c, E, d, l = 1, h = 0, O = 0) {
|
|
360
|
+
const C = new ArrayBuffer(32), A = new DataView(C);
|
|
361
|
+
let M = 0;
|
|
362
|
+
A.setUint8(M, Xe.INJECT_TOUCH_EVENT), M += 1;
|
|
363
|
+
const U = t === Je.ACTION_POINTER_DOWN ? Je.ACTION_DOWN : t === Je.ACTION_POINTER_UP ? Je.ACTION_UP : t;
|
|
364
|
+
return A.setUint8(M, U), M += 1, A.setBigInt64(M, BigInt(e), !0), M += 8, A.setInt32(M, Math.round(E), !0), M += 4, A.setInt32(M, Math.round(d), !0), M += 4, A.setUint16(M, r, !0), M += 2, A.setUint16(M, c, !0), M += 2, A.setInt16(M, Math.round(l * 65535), !0), M += 2, A.setInt32(M, h, !0), M += 4, A.setInt32(M, O, !0), C;
|
|
365
|
+
}
|
|
366
|
+
function kn(t, e, r, c, E, d, l) {
|
|
367
|
+
const h = new ArrayBuffer(24), O = new DataView(h);
|
|
368
|
+
let C = 0;
|
|
369
|
+
return O.setUint8(C, Xe.INJECT_TWO_FINGER_TOUCH_EVENT), C += 1, O.setUint8(C, t), C += 1, O.setInt32(C, Math.round(c), !0), C += 4, O.setInt32(C, Math.round(E), !0), C += 4, O.setInt32(C, Math.round(d), !0), C += 4, O.setInt32(C, Math.round(l), !0), C += 4, O.setUint16(C, e, !0), C += 2, O.setUint16(C, r, !0), C += 2, O.setUint16(C, 0, !0), h;
|
|
370
|
+
}
|
|
371
|
+
function Gt(t, e = !0) {
|
|
372
|
+
const c = new TextEncoder().encode(t), E = new ArrayBuffer(14 + c.length), d = new DataView(E);
|
|
373
|
+
let l = 0;
|
|
374
|
+
return d.setUint8(l, Xe.SET_CLIPBOARD), l += 1, d.setBigInt64(l, BigInt(0), !1), l += 8, d.setUint8(l, e ? 1 : 0), l += 1, d.setUint32(l, c.length, !1), l += 4, new Uint8Array(E, l).set(c), E;
|
|
375
|
+
}
|
|
376
|
+
function it(t, e, r = 0, c = 0) {
|
|
377
|
+
const E = new ArrayBuffer(14), d = new DataView(E);
|
|
378
|
+
let l = 0;
|
|
379
|
+
return d.setUint8(l, Xe.INJECT_KEYCODE), l += 1, d.setUint8(l, t), l += 1, d.setInt32(l, e, !0), l += 4, d.setInt32(l, r, !0), l += 4, d.setInt32(l, c, !0), E;
|
|
380
|
+
}
|
|
381
|
+
const Un = { width: 164.6, height: 117.8, depth: 5.2 };
|
|
382
|
+
function Pn(t, e, r) {
|
|
383
|
+
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 };
|
|
384
|
+
}
|
|
385
|
+
function Jt(t) {
|
|
386
|
+
return Number.isFinite(t) && t >= 0 && t <= 180;
|
|
387
|
+
}
|
|
388
|
+
function Ln(t, e) {
|
|
389
|
+
return { x: Math.max(0, Math.min(1, t)), y: Math.max(0, Math.min(1, 1 - e)) };
|
|
390
|
+
}
|
|
391
|
+
function Fn(t, e, r) {
|
|
392
|
+
return e && (t || !r) ? "touch" : t ? "ignore" : "orbit";
|
|
393
|
+
}
|
|
394
|
+
function jt(t, e, r, c) {
|
|
395
|
+
if (!Number.isInteger(t) || t < 0 || t > 3 || !Number.isInteger(e) || e < 1 || e > 255 || !Number.isFinite(r) || !Number.isFinite(c) || r < 0 || r > 1 || c < 0 || c > 1)
|
|
396
|
+
throw new RangeError("Invalid display touch coordinates");
|
|
397
|
+
const E = new ArrayBuffer(12), d = new DataView(E);
|
|
398
|
+
return d.setUint8(0, 19), d.setUint8(1, t), d.setUint8(2, e), d.setFloat32(4, r, !0), d.setFloat32(8, c, !0), E;
|
|
399
|
+
}
|
|
400
|
+
class Bn {
|
|
401
|
+
constructor(e, r) {
|
|
402
|
+
this.send = e, this.failed = r;
|
|
403
|
+
}
|
|
404
|
+
send;
|
|
405
|
+
failed;
|
|
406
|
+
latest;
|
|
407
|
+
running = !1;
|
|
408
|
+
stopped = !1;
|
|
409
|
+
set(e) {
|
|
410
|
+
this.stopped || !Jt(e) || (this.latest = e, this.flush());
|
|
411
|
+
}
|
|
412
|
+
stop() {
|
|
413
|
+
this.stopped = !0, this.latest = void 0;
|
|
414
|
+
}
|
|
415
|
+
async flush() {
|
|
416
|
+
if (!(this.running || this.stopped)) {
|
|
417
|
+
this.running = !0;
|
|
418
|
+
try {
|
|
419
|
+
for (; this.latest !== void 0 && !this.stopped; ) {
|
|
420
|
+
const e = this.latest;
|
|
421
|
+
this.latest = void 0, await this.send(e);
|
|
422
|
+
}
|
|
423
|
+
} catch (e) {
|
|
424
|
+
this.latest = void 0, this.stopped || this.failed(e);
|
|
425
|
+
} finally {
|
|
426
|
+
this.running = !1;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const xn = {
|
|
432
|
+
side: "Sleep/Wake",
|
|
433
|
+
volumeUp: "Volume Up",
|
|
434
|
+
volumeDown: "Volume Down"
|
|
435
|
+
};
|
|
436
|
+
class Wn {
|
|
437
|
+
constructor(e, r) {
|
|
438
|
+
this.send = e, this.failed = r;
|
|
439
|
+
}
|
|
440
|
+
send;
|
|
441
|
+
failed;
|
|
442
|
+
held;
|
|
443
|
+
tail = Promise.resolve();
|
|
444
|
+
timeout;
|
|
445
|
+
press(e) {
|
|
446
|
+
this.held || (this.held = e, this.enqueue(e, !0), this.timeout = setTimeout(() => this.release(), 1e4));
|
|
447
|
+
}
|
|
448
|
+
release() {
|
|
449
|
+
if (!this.held) return;
|
|
450
|
+
clearTimeout(this.timeout);
|
|
451
|
+
const e = this.held;
|
|
452
|
+
this.held = void 0, this.enqueue(e, !1);
|
|
453
|
+
}
|
|
454
|
+
enqueue(e, r) {
|
|
455
|
+
this.tail = this.tail.then(() => this.send(e, r)).catch(this.failed);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const ot = "Accessibility unavailable on this device.", je = 500, Mt = (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, Xt = (t) => Math.max(0, t.width) * Math.max(0, t.height), Qt = (t) => {
|
|
459
|
+
const e = t.find((r) => r.frame && r.frame.width > 0 && r.frame.height > 0);
|
|
460
|
+
return e?.frame ? ((Math.abs(e.frame.x) > 0.5 || Math.abs(e.frame.y) > 0.5) && console.warn(
|
|
461
|
+
`[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.`
|
|
462
|
+
), { x: 0, y: 0, width: e.frame.width, height: e.frame.height }) : { x: 0, y: 0, width: 1, height: 1 };
|
|
463
|
+
}, zt = (t) => {
|
|
464
|
+
const e = {};
|
|
465
|
+
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;
|
|
466
|
+
}, Zt = (t) => {
|
|
467
|
+
const e = {};
|
|
468
|
+
for (const [r, c] of Object.entries(t))
|
|
469
|
+
r !== "children" && (e[r] = c);
|
|
470
|
+
return e;
|
|
471
|
+
};
|
|
472
|
+
function en(t) {
|
|
473
|
+
const e = Array.isArray(t) ? t : [t], r = Qt(e), c = [], E = (d, l) => {
|
|
474
|
+
if (c.length >= je) return;
|
|
475
|
+
const h = d.frame;
|
|
476
|
+
if (h && h.width > 0 && h.height > 0 && !Mt(h, r)) {
|
|
477
|
+
const C = d.role_description || d.role || "", A = (typeof d.AXLabel == "string" ? d.AXLabel : "") || (typeof d.title == "string" ? d.title : "") || "";
|
|
478
|
+
c.push({
|
|
479
|
+
id: typeof d.AXUniqueId == "string" && d.AXUniqueId.length > 0 ? d.AXUniqueId : l,
|
|
480
|
+
path: l,
|
|
481
|
+
label: A,
|
|
482
|
+
value: typeof d.AXValue == "string" ? d.AXValue : "",
|
|
483
|
+
role: C,
|
|
484
|
+
type: typeof d.type == "string" ? d.type : "",
|
|
485
|
+
enabled: d.enabled !== !1,
|
|
486
|
+
focused: d.focused === !0,
|
|
487
|
+
frame: { x: h.x, y: h.y, width: h.width, height: h.height },
|
|
488
|
+
selectors: zt(d),
|
|
489
|
+
raw: Zt(d)
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
const O = Array.isArray(d.children) ? d.children : [];
|
|
493
|
+
for (let C = 0; C < O.length && c.length < je; C++)
|
|
494
|
+
E(O[C], `${l}.${C}`);
|
|
495
|
+
};
|
|
496
|
+
for (let d = 0; d < e.length && c.length < je; d++)
|
|
497
|
+
E(e[d], String(d));
|
|
498
|
+
return {
|
|
499
|
+
platform: "ios",
|
|
500
|
+
screen: { width: r.width, height: r.height },
|
|
501
|
+
elements: c,
|
|
502
|
+
capturedAt: Date.now()
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
const tn = (t) => {
|
|
506
|
+
let e = { x: 0, y: 0, width: 1, height: 1 }, r = 0;
|
|
507
|
+
for (const c of t) {
|
|
508
|
+
const E = c.parsedBounds;
|
|
509
|
+
if (!E) continue;
|
|
510
|
+
const d = E.right - E.left, l = E.bottom - E.top, h = Math.max(0, d) * Math.max(0, l);
|
|
511
|
+
h > r && (r = h, e = { x: 0, y: 0, width: d, height: l });
|
|
512
|
+
}
|
|
513
|
+
return e;
|
|
514
|
+
}, nn = (t) => {
|
|
515
|
+
const e = {};
|
|
516
|
+
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;
|
|
517
|
+
};
|
|
518
|
+
function rn(t) {
|
|
519
|
+
const e = tn(t), r = [];
|
|
520
|
+
for (let c = 0; c < t.length && r.length < je; c++) {
|
|
521
|
+
const E = t[c], d = E.parsedBounds;
|
|
522
|
+
if (!d) continue;
|
|
523
|
+
const l = Math.max(0, d.right - d.left), h = Math.max(0, d.bottom - d.top);
|
|
524
|
+
if (l <= 0 || h <= 0) continue;
|
|
525
|
+
const O = { x: d.left, y: d.top, width: l, height: h };
|
|
526
|
+
if (Mt(O, { x: 0, y: 0, width: e.width, height: e.height })) continue;
|
|
527
|
+
const C = E.contentDesc || E.text || "", A = E.className || "";
|
|
528
|
+
r.push({
|
|
529
|
+
id: E.resourceId && E.resourceId.length > 0 ? E.resourceId : E.contentDesc && E.contentDesc.length > 0 ? `cd:${E.contentDesc}` : String(c),
|
|
530
|
+
path: String(c),
|
|
531
|
+
label: C,
|
|
532
|
+
value: typeof E.text == "string" ? E.text : "",
|
|
533
|
+
role: A,
|
|
534
|
+
type: A,
|
|
535
|
+
enabled: E.enabled !== !1,
|
|
536
|
+
focused: E.focused === !0,
|
|
537
|
+
frame: O,
|
|
538
|
+
selectors: nn(E),
|
|
539
|
+
raw: { ...E }
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
platform: "android",
|
|
544
|
+
screen: { width: e.width, height: e.height },
|
|
545
|
+
elements: r,
|
|
546
|
+
capturedAt: Date.now()
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function qn(t, e) {
|
|
550
|
+
const r = Math.max(0, t.x), c = Math.max(0, t.y), E = Math.min(e.width, t.x + t.width), d = Math.min(e.height, t.y + t.height), l = Math.max(0, E - r), h = Math.max(0, d - c);
|
|
551
|
+
return l > 0 && h > 0 ? { x: r, y: c, width: l, height: h } : null;
|
|
552
|
+
}
|
|
553
|
+
function on(t, e) {
|
|
554
|
+
if (t === e) return !0;
|
|
555
|
+
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;
|
|
556
|
+
const r = t.frame, c = e.frame;
|
|
557
|
+
return r.x === c.x && r.y === c.y && r.width === c.width && r.height === c.height;
|
|
558
|
+
}
|
|
559
|
+
function an(t, e) {
|
|
560
|
+
if (t === e) return !0;
|
|
561
|
+
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;
|
|
562
|
+
for (let r = 0; r < t.elements.length; r++)
|
|
563
|
+
if (!on(t.elements[r], e.elements[r])) return !1;
|
|
564
|
+
return !0;
|
|
565
|
+
}
|
|
566
|
+
function $n(t, e, r) {
|
|
567
|
+
let c = null, E = 1 / 0;
|
|
568
|
+
for (const d of t.elements) {
|
|
569
|
+
const l = d.frame;
|
|
570
|
+
if (e < l.x || r < l.y || e > l.x + l.width || r > l.y + l.height) continue;
|
|
571
|
+
const h = Xt(l);
|
|
572
|
+
h < E && (E = h, c = d);
|
|
573
|
+
}
|
|
574
|
+
return c;
|
|
575
|
+
}
|
|
576
|
+
function Vn(t, e) {
|
|
577
|
+
if (e === "ios") {
|
|
578
|
+
if (t.selectors.AXUniqueId)
|
|
579
|
+
return `client.tapElement({ AXUniqueId: ${JSON.stringify(t.selectors.AXUniqueId)} })`;
|
|
580
|
+
if (t.selectors.AXLabel) {
|
|
581
|
+
const r = t.selectors.className ? `, type: ${JSON.stringify(t.selectors.className)}` : "";
|
|
582
|
+
return `client.tapElement({ AXLabel: ${JSON.stringify(t.selectors.AXLabel)}${r} })`;
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
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;
|
|
587
|
+
}
|
|
588
|
+
function sn(t) {
|
|
589
|
+
const e = t.role || t.type || "";
|
|
590
|
+
if (!e) return "element";
|
|
591
|
+
let r = e.replace(/^AX/, "");
|
|
592
|
+
return r.includes(".") && (r = r.split(".").pop()), r === "GenericElement" ? "Element" : (r = r.replace(/([a-z])([A-Z])/g, "$1 $2"), r);
|
|
593
|
+
}
|
|
594
|
+
const St = 80;
|
|
595
|
+
function Hn(t) {
|
|
596
|
+
const e = sn(t), r = t.label || t.value || "";
|
|
597
|
+
if (!r) return e;
|
|
598
|
+
const c = r.length > St ? r.slice(0, St).trimEnd() + "…" : r;
|
|
599
|
+
return `${e} · ${c}`;
|
|
600
|
+
}
|
|
601
|
+
const cn = 500, ln = 2e3, yt = 5e3, dn = 8e3, un = 1200, fn = 250, En = () => `ax-rc-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
602
|
+
class hn {
|
|
603
|
+
platform;
|
|
604
|
+
send;
|
|
605
|
+
onSnapshot;
|
|
606
|
+
onStatusChange;
|
|
607
|
+
baseIntervalMs;
|
|
608
|
+
maxBackoffMs;
|
|
609
|
+
androidElementTreeOptions;
|
|
610
|
+
pending = /* @__PURE__ */ new Map();
|
|
611
|
+
running = !1;
|
|
612
|
+
timer;
|
|
613
|
+
currentInterval;
|
|
614
|
+
lastSnapshot = null;
|
|
615
|
+
// Single-flight: only one outstanding request at a time. Avoids piling
|
|
616
|
+
// identical requests on a slow server.
|
|
617
|
+
inflight = !1;
|
|
618
|
+
// Rate-limit floor for bumpActivity so high-frequency input (drags,
|
|
619
|
+
// typing) doesn't trigger a request storm.
|
|
620
|
+
lastBumpAtMs = 0;
|
|
621
|
+
// Wall-clock timestamp until which we're in "activity boost" mode and
|
|
622
|
+
// schedule fetches at ACTIVITY_BOOST_INTERVAL_MS instead of the normal
|
|
623
|
+
// backed-off interval. Set by bumpActivity().
|
|
624
|
+
boostUntilMs = 0;
|
|
625
|
+
// Coarse-grained current status; deduplicated before emission so
|
|
626
|
+
// identical-to-current transitions are no-ops.
|
|
627
|
+
status = "idle";
|
|
628
|
+
constructor(e) {
|
|
629
|
+
this.platform = e.platform, this.send = e.send, this.onSnapshot = e.onSnapshot, this.onStatusChange = e.onStatusChange, this.baseIntervalMs = e.baseIntervalMs ?? cn, this.maxBackoffMs = e.maxBackoffMs ?? ln, this.androidElementTreeOptions = e.androidElementTreeOptions, this.currentInterval = this.baseIntervalMs;
|
|
630
|
+
}
|
|
631
|
+
start() {
|
|
632
|
+
this.running || (this.running = !0, this.currentInterval = this.baseIntervalMs, this.boostUntilMs = 0, this.setStatus("starting"), this.runOnce());
|
|
633
|
+
}
|
|
634
|
+
stop() {
|
|
635
|
+
this.running && (this.running = !1, this.timer !== void 0 && (window.clearTimeout(this.timer), this.timer = void 0), this.failAllPending("Inspector stopped"), this.lastSnapshot = null, this.setStatus("idle"), this.onSnapshot(null));
|
|
636
|
+
}
|
|
637
|
+
getStatus() {
|
|
638
|
+
return this.status;
|
|
639
|
+
}
|
|
640
|
+
setStatus(e, r) {
|
|
641
|
+
if (this.status !== e && (this.status = e, !!this.onStatusChange))
|
|
642
|
+
try {
|
|
643
|
+
this.onStatusChange(e, r);
|
|
644
|
+
} catch (c) {
|
|
645
|
+
console.error("[AxFetcher] onStatusChange threw:", c);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
// Called after any user-driven action that's likely to change the UI
|
|
649
|
+
// (taps, scrolls, key events, openUrl, app termination, orientation
|
|
650
|
+
// change, etc.). Has two effects:
|
|
651
|
+
//
|
|
652
|
+
// 1. Resets the polling interval to base and triggers an immediate
|
|
653
|
+
// fetch (rate-limited so drags / rapid typing don't request-storm).
|
|
654
|
+
// 2. Enters a brief "boost" window during which scheduleNext() uses a
|
|
655
|
+
// shorter interval (ACTIVITY_BOOST_INTERVAL_MS), so we capture the
|
|
656
|
+
// mid- and post-animation tree without waiting for the next
|
|
657
|
+
// back-off cycle.
|
|
658
|
+
bumpActivity() {
|
|
659
|
+
if (!this.running) return;
|
|
660
|
+
const e = Date.now();
|
|
661
|
+
this.boostUntilMs = e + un;
|
|
662
|
+
const r = Math.max(150, Math.floor(this.baseIntervalMs / 2));
|
|
663
|
+
if (e - this.lastBumpAtMs < r) {
|
|
664
|
+
this.currentInterval = this.baseIntervalMs;
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
this.lastBumpAtMs = e, this.currentInterval = this.baseIntervalMs, this.timer !== void 0 && (window.clearTimeout(this.timer), this.timer = void 0), this.inflight || this.runOnce();
|
|
668
|
+
}
|
|
669
|
+
// Fire a one-shot fetch independent of the poll loop. Useful for the
|
|
670
|
+
// imperative refresh() ref method customers may call.
|
|
671
|
+
//
|
|
672
|
+
// Goes through the same change-detect path as the regular poll loop —
|
|
673
|
+
// identical-to-last-snapshot responses do NOT re-emit via onSnapshot, so
|
|
674
|
+
// a customer calling refresh() in a tight loop doesn't see a stream of
|
|
675
|
+
// duplicate snapshots. The returned promise still resolves with the
|
|
676
|
+
// (possibly identical) snapshot for the caller's own use.
|
|
677
|
+
async refresh() {
|
|
678
|
+
const e = await this.requestOnce();
|
|
679
|
+
return this.running && this.deliver(e), e;
|
|
680
|
+
}
|
|
681
|
+
// Returns the latest snapshot delivered to onSnapshot. May be stale.
|
|
682
|
+
getLatest() {
|
|
683
|
+
return this.lastSnapshot;
|
|
684
|
+
}
|
|
685
|
+
// Called by RemoteControl's ws.onmessage when it sees a message type we own.
|
|
686
|
+
// Returns true when the message was a response we were waiting for.
|
|
687
|
+
handleMessage(e) {
|
|
688
|
+
if (!e || typeof e.id != "string") return !1;
|
|
689
|
+
const r = e.id;
|
|
690
|
+
if (!this.pending.get(r)) return !1;
|
|
691
|
+
if (this.platform === "ios") {
|
|
692
|
+
if (e.type !== "elementTreeResult") return !1;
|
|
693
|
+
const h = typeof e.error == "string" ? e.error : null;
|
|
694
|
+
if (h)
|
|
695
|
+
return this.settleReject(r, new Error(h)), !0;
|
|
696
|
+
const O = typeof e.json == "string" ? e.json : "";
|
|
697
|
+
try {
|
|
698
|
+
const C = JSON.parse(O), A = en(C);
|
|
699
|
+
this.settleResolve(r, A);
|
|
700
|
+
} catch (C) {
|
|
701
|
+
this.settleReject(r, C instanceof Error ? C : new Error(String(C)));
|
|
702
|
+
}
|
|
703
|
+
return !0;
|
|
704
|
+
}
|
|
705
|
+
if (e.type !== "getElementTreeResult") return !1;
|
|
706
|
+
const E = e.error;
|
|
707
|
+
if (E && typeof E == "object") {
|
|
708
|
+
const h = typeof E.message == "string" ? E.message : "getElementTree failed";
|
|
709
|
+
return this.settleReject(r, new Error(h)), !0;
|
|
710
|
+
}
|
|
711
|
+
const d = e.payload, l = Array.isArray(d?.nodes) ? d.nodes : [];
|
|
712
|
+
try {
|
|
713
|
+
const h = rn(l);
|
|
714
|
+
this.settleResolve(r, h);
|
|
715
|
+
} catch (h) {
|
|
716
|
+
this.settleReject(r, h instanceof Error ? h : new Error(String(h)));
|
|
717
|
+
}
|
|
718
|
+
return !0;
|
|
719
|
+
}
|
|
720
|
+
buildRequest(e) {
|
|
721
|
+
return this.platform === "ios" ? { type: "elementTree", id: e } : { type: "getElementTree", id: e, ...this.androidElementTreeOptions };
|
|
722
|
+
}
|
|
723
|
+
async requestOnce() {
|
|
724
|
+
const e = En();
|
|
725
|
+
return new Promise((r, c) => {
|
|
726
|
+
const E = window.setTimeout(
|
|
727
|
+
() => {
|
|
728
|
+
this.pending.delete(e), c(new Error("elementTree request timed out"));
|
|
729
|
+
},
|
|
730
|
+
dn + (this.androidElementTreeOptions?.waitForIdleTimeoutMs ?? 0)
|
|
731
|
+
);
|
|
732
|
+
this.pending.set(e, { resolve: r, reject: c, timer: E }), this.send(this.buildRequest(e)) || (window.clearTimeout(E), this.pending.delete(e), c(new Error("elementTree send failed (WebSocket not open)")));
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
async runOnce() {
|
|
736
|
+
if (this.running && !this.inflight) {
|
|
737
|
+
this.inflight = !0;
|
|
738
|
+
try {
|
|
739
|
+
const e = await this.requestOnce();
|
|
740
|
+
if (!this.running) return;
|
|
741
|
+
this.deliver(e);
|
|
742
|
+
} catch (e) {
|
|
743
|
+
if (!this.running) return;
|
|
744
|
+
const r = e instanceof Error ? e.message : String(e), c = /unavailable|not (yet )?running|failed|timeout/i.test(r);
|
|
745
|
+
this.currentInterval = c ? yt : Math.min(this.currentInterval * 2, this.maxBackoffMs), this.setStatus(c ? "unavailable" : "error", r);
|
|
746
|
+
} finally {
|
|
747
|
+
this.inflight = !1, this.scheduleNext();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
deliver(e) {
|
|
752
|
+
const r = this.lastSnapshot;
|
|
753
|
+
if (an(r, e)) {
|
|
754
|
+
this.currentInterval = Math.min(this.currentInterval * 2, this.maxBackoffMs), this.lastSnapshot = e, e.errors?.includes(ot) || this.setStatus("ready");
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
this.lastSnapshot = e, this.currentInterval = this.baseIntervalMs, e.errors?.includes(ot) ? (this.currentInterval = yt, this.setStatus("unavailable", ot)) : this.setStatus("ready"), this.onSnapshot(e);
|
|
758
|
+
}
|
|
759
|
+
scheduleNext() {
|
|
760
|
+
if (!this.running) return;
|
|
761
|
+
this.timer !== void 0 && window.clearTimeout(this.timer);
|
|
762
|
+
const e = Date.now() < this.boostUntilMs ? Math.min(fn, this.currentInterval) : this.currentInterval;
|
|
763
|
+
this.timer = window.setTimeout(() => {
|
|
764
|
+
this.timer = void 0, this.runOnce();
|
|
765
|
+
}, e);
|
|
766
|
+
}
|
|
767
|
+
settleResolve(e, r) {
|
|
768
|
+
const c = this.pending.get(e);
|
|
769
|
+
c && (window.clearTimeout(c.timer), this.pending.delete(e), c.resolve(r));
|
|
770
|
+
}
|
|
771
|
+
settleReject(e, r) {
|
|
772
|
+
const c = this.pending.get(e);
|
|
773
|
+
c && (window.clearTimeout(c.timer), this.pending.delete(e), c.reject(r));
|
|
774
|
+
}
|
|
775
|
+
failAllPending(e) {
|
|
776
|
+
for (const [r, c] of this.pending.entries())
|
|
777
|
+
window.clearTimeout(c.timer), c.reject(new Error(e)), this.pending.delete(r);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function vt(t, e) {
|
|
781
|
+
if (e != null && (!Number.isFinite(e) || e < 0 || e > 4e3)) {
|
|
782
|
+
console.warn("RemoteControl: jitterBufferTargetMs must be a finite number between 0 and 4000.");
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (!("jitterBufferTarget" in t)) return;
|
|
786
|
+
const r = e ?? null;
|
|
787
|
+
try {
|
|
788
|
+
t.jitterBufferTarget !== r && (t.jitterBufferTarget = r);
|
|
789
|
+
} catch (c) {
|
|
790
|
+
console.warn("RemoteControl: could not set the jitter buffer target.", c);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
const Yt = `(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())}})();
|
|
794
|
+
`, At = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", Yt], { type: "text/javascript;charset=utf-8" });
|
|
795
|
+
function mn(t) {
|
|
796
|
+
let e;
|
|
797
|
+
try {
|
|
798
|
+
if (e = At && (self.URL || self.webkitURL).createObjectURL(At), !e) throw "";
|
|
799
|
+
const r = new Worker(e, {
|
|
800
|
+
name: t?.name
|
|
801
|
+
});
|
|
802
|
+
return r.addEventListener("error", () => {
|
|
803
|
+
(self.URL || self.webkitURL).revokeObjectURL(e);
|
|
804
|
+
}), r;
|
|
805
|
+
} catch {
|
|
806
|
+
return new Worker(
|
|
807
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(Yt),
|
|
808
|
+
{
|
|
809
|
+
name: t?.name
|
|
810
|
+
}
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function pn(t, e, r) {
|
|
815
|
+
const { MediaStreamTrackProcessor: c, MediaStreamTrackGenerator: E } = globalThis, d = e.getVideoTracks()[0];
|
|
816
|
+
let l, h, O, C, A = !1;
|
|
817
|
+
const M = () => {
|
|
818
|
+
A || (A = !0, l?.stop(), h?.stop(), O && (O.postMessage({ type: "stop" }), C = setTimeout(() => O?.terminate(), 1e3)));
|
|
819
|
+
}, U = (b) => {
|
|
820
|
+
t.srcObject = b, t.play().catch(() => {
|
|
821
|
+
});
|
|
822
|
+
}, T = (b) => {
|
|
823
|
+
A || (M(), r(b), U(e));
|
|
824
|
+
};
|
|
825
|
+
try {
|
|
826
|
+
if (d && c && E) {
|
|
827
|
+
l = d.clone();
|
|
828
|
+
const b = new c({ track: l, maxBufferSize: 1 }), V = new E({ kind: "video" });
|
|
829
|
+
h = V, O = new mn(), O.onmessage = ({ data: F }) => {
|
|
830
|
+
F.type === "error" ? T(new Error(F.message)) : F.type === "stopped" && (clearTimeout(C), O?.terminate());
|
|
831
|
+
}, O.onerror = (F) => T(new Error(F.message)), O.postMessage({ type: "start", readable: b.readable, writable: V.writable }, [
|
|
832
|
+
b.readable,
|
|
833
|
+
V.writable
|
|
834
|
+
]), U(new MediaStream(e.getTracks().map((F) => F === d ? V : F)));
|
|
835
|
+
} else
|
|
836
|
+
U(e);
|
|
837
|
+
} catch (b) {
|
|
838
|
+
T(b);
|
|
839
|
+
}
|
|
840
|
+
return M;
|
|
841
|
+
}
|
|
842
|
+
function ke(t) {
|
|
843
|
+
return typeof t == "number" && Number.isFinite(t);
|
|
844
|
+
}
|
|
845
|
+
function Te(t, e) {
|
|
846
|
+
if (!(!ke(t) || !ke(e) || t < e || e < 0))
|
|
847
|
+
return t - e;
|
|
848
|
+
}
|
|
849
|
+
class Cn {
|
|
850
|
+
previous = /* @__PURE__ */ new Map();
|
|
851
|
+
reset() {
|
|
852
|
+
this.previous.clear();
|
|
853
|
+
}
|
|
854
|
+
read(e, r, c) {
|
|
855
|
+
const E = { timestamp: 0, video: [], audio: [] };
|
|
856
|
+
c == null ? E.requestedTargetMs = null : ke(c) && c >= 0 && c <= 4e3 && (E.requestedTargetMs = c);
|
|
857
|
+
const d = /* @__PURE__ */ new Map();
|
|
858
|
+
return e.forEach((l) => {
|
|
859
|
+
if (l.type !== "inbound-rtp" || !ke(l.timestamp)) return;
|
|
860
|
+
const h = l.kind ?? l.mediaType;
|
|
861
|
+
if (h !== "video" && h !== "audio") return;
|
|
862
|
+
const O = r.filter((Y) => Y.kind === h), C = l.trackIdentifier ? O.find((Y) => Y.trackId === l.trackIdentifier) : l.mid != null ? O.find((Y) => Y.mid === l.mid) : O.length === 1 ? O[0] : void 0;
|
|
863
|
+
if (!C) return;
|
|
864
|
+
const A = this.previous.get(l.id), U = A?.trackId === C.trackId && A.stats.ssrc === l.ssrc ? A.stats : void 0, T = U ? l.timestamp - U.timestamp : void 0, b = {
|
|
865
|
+
id: l.id,
|
|
866
|
+
trackId: C.trackId,
|
|
867
|
+
timestamp: l.timestamp
|
|
868
|
+
};
|
|
869
|
+
if (T !== void 0 && T > 0) {
|
|
870
|
+
b.intervalMs = T;
|
|
871
|
+
const Y = Te(l.jitterBufferEmittedCount, U?.jitterBufferEmittedCount), P = Te(l.jitterBufferDelay, U?.jitterBufferDelay);
|
|
872
|
+
Y !== void 0 && Y > 0 && P !== void 0 && (b.bufferDelayMs = P / Y * 1e3);
|
|
873
|
+
const H = Te(l.bytesReceived, U?.bytesReceived);
|
|
874
|
+
H !== void 0 && (b.bitrateBps = H * 8e3 / T);
|
|
875
|
+
}
|
|
876
|
+
if (h === "video") {
|
|
877
|
+
const Y = { ...b, display: C.display ?? "primary" };
|
|
878
|
+
if (b.intervalMs !== void 0) {
|
|
879
|
+
const P = Te(l.framesDecoded, U?.framesDecoded);
|
|
880
|
+
P !== void 0 && (Y.fps = P * 1e3 / b.intervalMs), Y.droppedFrames = Te(l.framesDropped, U?.framesDropped), Y.freezes = Te(l.freezeCount, U?.freezeCount);
|
|
881
|
+
}
|
|
882
|
+
E.video.push(Y);
|
|
883
|
+
} else E.audio.push(b);
|
|
884
|
+
E.timestamp = Math.max(E.timestamp, l.timestamp), d.set(
|
|
885
|
+
l.id,
|
|
886
|
+
U && l.timestamp <= U.timestamp ? A : { stats: l, trackId: C.trackId }
|
|
887
|
+
);
|
|
888
|
+
const V = l.transportId ? e.get(l.transportId) : void 0, F = V?.selectedCandidatePairId ? e.get(V.selectedCandidatePairId) : void 0;
|
|
889
|
+
F?.state === "succeeded" && ke(F.currentRoundTripTime) && F.currentRoundTripTime >= 0 && (E.rttMs = F.currentRoundTripTime * 1e3);
|
|
890
|
+
}), this.previous = d, E.video.length || E.audio.length ? E : null;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
const at = /* @__PURE__ */ new WeakSet();
|
|
894
|
+
function On(t, e, r) {
|
|
895
|
+
const { peer: c, displays: E } = t, d = new Cn();
|
|
896
|
+
let l, h = !1, O = !1, C = !1, A = 0, M = !1, U = !1;
|
|
897
|
+
const T = () => !h && !document.hidden && c.connectionState === "connected", b = (P) => {
|
|
898
|
+
if (!(!P && !M)) {
|
|
899
|
+
M = P !== null;
|
|
900
|
+
try {
|
|
901
|
+
e()?.(P);
|
|
902
|
+
} catch (H) {
|
|
903
|
+
console.error('[RemoteControl] customer callback "onPlaybackStats" threw:', H);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}, V = () => {
|
|
907
|
+
O = !1, A++, clearTimeout(l), d.reset(), b(null);
|
|
908
|
+
}, F = async () => {
|
|
909
|
+
if (C || !T()) return;
|
|
910
|
+
if (at.has(c)) {
|
|
911
|
+
l = setTimeout(() => {
|
|
912
|
+
F();
|
|
913
|
+
}, 2e3);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
C = !0, at.add(c);
|
|
917
|
+
const P = A;
|
|
918
|
+
try {
|
|
919
|
+
const H = await c.getStats();
|
|
920
|
+
if (P !== A || !T()) return;
|
|
921
|
+
const B = c.getTransceivers().filter(
|
|
922
|
+
(j) => (j.currentDirection === "recvonly" || j.currentDirection === "sendrecv") && j.receiver.track.readyState !== "ended"
|
|
923
|
+
).map((j) => ({
|
|
924
|
+
trackId: j.receiver.track.id,
|
|
925
|
+
kind: j.receiver.track.kind,
|
|
926
|
+
mid: j.mid,
|
|
927
|
+
display: E.get(j.receiver)
|
|
928
|
+
}));
|
|
929
|
+
b(d.read(H, B, r())), U = !1;
|
|
930
|
+
} catch (H) {
|
|
931
|
+
if (P !== A || !T()) return;
|
|
932
|
+
U || console.warn("[RemoteControl] could not read playback stats:", H), U = !0, d.reset(), b(null);
|
|
933
|
+
} finally {
|
|
934
|
+
C = !1, at.delete(c), O && T() && (l = setTimeout(
|
|
935
|
+
() => {
|
|
936
|
+
F();
|
|
937
|
+
},
|
|
938
|
+
P === A ? 2e3 : 0
|
|
939
|
+
));
|
|
940
|
+
}
|
|
941
|
+
}, Y = () => {
|
|
942
|
+
if (!T()) {
|
|
943
|
+
V();
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
O || (O = !0, F());
|
|
947
|
+
};
|
|
948
|
+
return document.addEventListener("visibilitychange", Y), c.addEventListener("connectionstatechange", Y), Y(), () => {
|
|
949
|
+
h = !0, document.removeEventListener("visibilitychange", Y), c.removeEventListener("connectionstatechange", Y), V();
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function Dn(t, e) {
|
|
953
|
+
const r = t.createDataChannel("latency-trace-v1", {
|
|
954
|
+
ordered: !0,
|
|
955
|
+
negotiated: !0,
|
|
956
|
+
id: 2
|
|
957
|
+
});
|
|
958
|
+
let c = !1, E = !1, d = 0;
|
|
959
|
+
return r.onmessage = (l) => {
|
|
960
|
+
if (E) return;
|
|
961
|
+
let h;
|
|
962
|
+
try {
|
|
963
|
+
h = JSON.parse(l.data);
|
|
964
|
+
} catch (O) {
|
|
965
|
+
console.warn("Invalid latency trace message", O);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
h && typeof h == "object" && !Array.isArray(h) && e(h);
|
|
969
|
+
}, r.onclose = () => {
|
|
970
|
+
E = !0, c = !1;
|
|
971
|
+
}, {
|
|
972
|
+
accept(l) {
|
|
973
|
+
c = !E && l === 1;
|
|
974
|
+
},
|
|
975
|
+
wrap(l) {
|
|
976
|
+
if (!c || l.byteLength !== 32) return l;
|
|
977
|
+
const h = new DataView(l);
|
|
978
|
+
if (h.getUint8(0) !== 2 || h.getUint8(1) > 2) return l;
|
|
979
|
+
const O = new ArrayBuffer(38), C = new DataView(O);
|
|
980
|
+
return C.setUint8(0, 240), C.setUint8(1, 1), C.setUint32(2, ++d, !0), new Uint8Array(O, 6).set(new Uint8Array(l)), O;
|
|
981
|
+
},
|
|
982
|
+
close() {
|
|
983
|
+
E = !0, c = !1, r.onmessage = null, r.onclose = null, r.close();
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
class _n {
|
|
988
|
+
generation = 0;
|
|
989
|
+
tail = Promise.resolve();
|
|
990
|
+
get currentGeneration() {
|
|
991
|
+
return this.generation;
|
|
992
|
+
}
|
|
993
|
+
enqueue(e) {
|
|
994
|
+
const r = ++this.generation;
|
|
995
|
+
return this.append(r, e);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Queues related work without superseding an already queued request.
|
|
999
|
+
*
|
|
1000
|
+
* The operation retains the generation current at enqueue time and becomes
|
|
1001
|
+
* stale if a later camera request increments it before this work starts.
|
|
1002
|
+
*/
|
|
1003
|
+
enqueueCurrent(e) {
|
|
1004
|
+
return this.append(this.generation, e);
|
|
1005
|
+
}
|
|
1006
|
+
append(e, r) {
|
|
1007
|
+
const c = {
|
|
1008
|
+
generation: e,
|
|
1009
|
+
isCurrent: () => e === this.generation
|
|
1010
|
+
}, E = this.tail.then(() => r(c));
|
|
1011
|
+
return this.tail = E.catch(() => {
|
|
1012
|
+
}), E;
|
|
1013
|
+
}
|
|
1014
|
+
invalidate() {
|
|
1015
|
+
++this.generation;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function gn(t) {
|
|
1019
|
+
if (!t || typeof t != "object") return null;
|
|
1020
|
+
const e = t;
|
|
1021
|
+
if (e.type !== "cameraRequest" || typeof e.active != "boolean") return null;
|
|
1022
|
+
const r = { active: e.active };
|
|
1023
|
+
return (e.facingMode === "user" || e.facingMode === "environment") && (r.facingMode = e.facingMode), r;
|
|
1024
|
+
}
|
|
1025
|
+
function Tn(t) {
|
|
1026
|
+
const e = {
|
|
1027
|
+
frameRate: { ideal: 30, max: 30 }
|
|
1028
|
+
};
|
|
1029
|
+
return t?.facingMode && (e.facingMode = { ideal: t.facingMode }), e;
|
|
1030
|
+
}
|
|
1031
|
+
function Sn(t, e) {
|
|
1032
|
+
return !t || t.facingMode !== e.facingMode;
|
|
1033
|
+
}
|
|
1034
|
+
function yn(t) {
|
|
1035
|
+
const e = t.getSettings();
|
|
1036
|
+
return {
|
|
1037
|
+
width: e.width,
|
|
1038
|
+
height: e.height,
|
|
1039
|
+
frameRate: e.frameRate,
|
|
1040
|
+
deviceId: e.deviceId,
|
|
1041
|
+
label: t.label || void 0,
|
|
1042
|
+
facingMode: e.facingMode
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
function vn(t) {
|
|
1046
|
+
return {
|
|
1047
|
+
type: "cameraResult",
|
|
1048
|
+
granted: !0,
|
|
1049
|
+
camera: yn(t)
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
const ce = (...t) => {
|
|
1053
|
+
window.debugRemoteControl && console.log(...t);
|
|
1054
|
+
}, y = (...t) => {
|
|
1055
|
+
window.debugRemoteControl && console.warn(...t);
|
|
1056
|
+
}, L = (t, e, ...r) => {
|
|
1057
|
+
if (e)
|
|
1058
|
+
try {
|
|
1059
|
+
e(...r);
|
|
1060
|
+
} catch (c) {
|
|
1061
|
+
console.error(`[RemoteControl] customer callback "${t}" threw:`, c);
|
|
1062
|
+
}
|
|
1063
|
+
}, An = (t) => t.includes("/android_") ? "android" : "ios", Kt = (t, e) => {
|
|
1064
|
+
const r = new URL(t);
|
|
1065
|
+
return r.searchParams.set("token", e), r.toString();
|
|
1066
|
+
}, st = 3, Kn = 1e3, wn = 15e3, Mn = 3e3, Yn = 4e3;
|
|
1067
|
+
function wt() {
|
|
1068
|
+
const t = crypto.getRandomValues(new Uint8Array(16));
|
|
1069
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
1070
|
+
const e = Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("");
|
|
1071
|
+
return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
|
|
1072
|
+
}
|
|
1073
|
+
function Gn(t) {
|
|
1074
|
+
let e = { ...t };
|
|
1075
|
+
const { url: r, token: c, deviceModel: E } = e, d = e.sessionId ?? wt(), l = e.platform ?? An(r ?? "");
|
|
1076
|
+
let h = {
|
|
1077
|
+
connection: "idle",
|
|
1078
|
+
videoReady: !1,
|
|
1079
|
+
controlReady: !1,
|
|
1080
|
+
duo: !1,
|
|
1081
|
+
duoState: null
|
|
1082
|
+
};
|
|
1083
|
+
const O = (n) => {
|
|
1084
|
+
h = { ...h, ...n }, L("onStateChange", e.onStateChange, h);
|
|
1085
|
+
}, C = (n) => O({ videoReady: n }), A = (n) => O({ duoState: n }), M = (n) => O({ duoError: n }), U = (n) => O({ duo: n }), T = (n) => ce(n);
|
|
1086
|
+
let b = null, V;
|
|
1087
|
+
const F = () => {
|
|
1088
|
+
V?.(), V = b && e.onPlaybackStats ? On(
|
|
1089
|
+
b,
|
|
1090
|
+
() => e.onPlaybackStats,
|
|
1091
|
+
() => e.jitterBufferTargetMs
|
|
1092
|
+
) : void 0;
|
|
1093
|
+
}, Y = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Set(), H = /* @__PURE__ */ new Set(), B = /* @__PURE__ */ new Map();
|
|
1094
|
+
let j = !1;
|
|
1095
|
+
const Se = /* @__PURE__ */ new Map(), ct = (n, u, a) => {
|
|
1096
|
+
u.stop?.(), u.stop = pn(n, a, (s) => y("Video playback fallback:", s));
|
|
1097
|
+
}, bt = () => {
|
|
1098
|
+
Se.clear();
|
|
1099
|
+
for (const [n, u] of Y)
|
|
1100
|
+
u.clear?.(), u.stop?.(), u.stop = void 0, n.srcObject = null;
|
|
1101
|
+
};
|
|
1102
|
+
let Ee = !1, ye = !1, Ue = 0, _ = null, R = null, x = null, Pe = null, he, ve, Ae, Le, me, le = 0, Fe = 0, ne = !1, de = null, z = null, ue;
|
|
1103
|
+
const Qe = new _n();
|
|
1104
|
+
let Ke = null, Be = null, ze = e.microphoneEnabled ?? !1, Ze = !1, we = null, te = null, xe = 0, lt = Promise.resolve(), pe = null, Me = !1, re = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map(), ae = /* @__PURE__ */ new Map(), ie = /* @__PURE__ */ new Map(), q = null, Ye = null, dt = 0;
|
|
1105
|
+
const We = (n) => {
|
|
1106
|
+
if (n === null && Ye === null) return;
|
|
1107
|
+
Ye = n;
|
|
1108
|
+
const u = ++dt;
|
|
1109
|
+
queueMicrotask(() => {
|
|
1110
|
+
u === dt && L("onAxSnapshotChange", e.onAxSnapshotChange, n);
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
let Ce = null, fe = /* @__PURE__ */ new Map();
|
|
1114
|
+
const be = (n, u) => new Promise((a, s) => {
|
|
1115
|
+
const S = _;
|
|
1116
|
+
if (!S || S.readyState !== WebSocket.OPEN) {
|
|
1117
|
+
s(new Error("Simulator disconnected"));
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const m = wt(), p = setTimeout(() => {
|
|
1121
|
+
fe.delete(m), s(new Error("Device control timed out"));
|
|
1122
|
+
}, 5e3);
|
|
1123
|
+
fe.set(m, { resolve: a, reject: s, timer: p });
|
|
1124
|
+
try {
|
|
1125
|
+
S.send(JSON.stringify({ type: n, id: m, ...u })), q?.bumpActivity();
|
|
1126
|
+
} catch (f) {
|
|
1127
|
+
clearTimeout(p), fe.delete(m), s(f);
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
let Oe;
|
|
1131
|
+
const ut = () => {
|
|
1132
|
+
if (Oe) return Oe;
|
|
1133
|
+
const n = be("getFoldState", {}).then(() => {
|
|
1134
|
+
if (!h.duoState) throw new Error("This instance does not support native iPhone Duo displays.");
|
|
1135
|
+
}).finally(() => {
|
|
1136
|
+
Oe === n && (Oe = void 0);
|
|
1137
|
+
});
|
|
1138
|
+
return Oe = n, n;
|
|
1139
|
+
}, De = (n) => {
|
|
1140
|
+
Ce !== n && (Ce = n, O({ connection: n }), L("onConnectionStateChange", e.onConnectionStateChange, n));
|
|
1141
|
+
}, se = (n) => {
|
|
1142
|
+
!x || x.readyState !== "open" || (x.send(Pe?.wrap(n) ?? n), q?.bumpActivity());
|
|
1143
|
+
}, Rt = () => {
|
|
1144
|
+
_ && _.readyState === WebSocket.OPEN && _.send(
|
|
1145
|
+
JSON.stringify({
|
|
1146
|
+
type: "keepAlive",
|
|
1147
|
+
sessionId: d
|
|
1148
|
+
})
|
|
1149
|
+
);
|
|
1150
|
+
}, ft = () => {
|
|
1151
|
+
he && window.clearInterval(he), he = window.setInterval(Rt, 1e4);
|
|
1152
|
+
}, Re = () => {
|
|
1153
|
+
he && (window.clearInterval(he), he = void 0);
|
|
1154
|
+
}, qe = () => {
|
|
1155
|
+
ve && (window.clearTimeout(ve), ve = void 0);
|
|
1156
|
+
}, $e = () => {
|
|
1157
|
+
Ae && (window.clearTimeout(Ae), Ae = void 0);
|
|
1158
|
+
}, Ne = () => {
|
|
1159
|
+
Le && (window.clearInterval(Le), Le = void 0);
|
|
1160
|
+
}, Ie = () => {
|
|
1161
|
+
me !== void 0 && (window.clearTimeout(me), me = void 0);
|
|
1162
|
+
}, Nt = () => {
|
|
1163
|
+
Me || (Me = !0, Ne(), C(!0), De("connected"));
|
|
1164
|
+
}, G = (n) => {
|
|
1165
|
+
for (const u of n.getTracks())
|
|
1166
|
+
try {
|
|
1167
|
+
u.stop();
|
|
1168
|
+
} catch (a) {
|
|
1169
|
+
y("track.stop() failed:", a);
|
|
1170
|
+
}
|
|
1171
|
+
}, It = () => {
|
|
1172
|
+
const n = z;
|
|
1173
|
+
n && (z = null, G(n));
|
|
1174
|
+
}, Et = (n) => {
|
|
1175
|
+
const u = lt.then(n).catch((a) => {
|
|
1176
|
+
y("microphone operation failed:", a);
|
|
1177
|
+
});
|
|
1178
|
+
return lt = u, u;
|
|
1179
|
+
}, et = () => ze || Ze, ht = (n) => {
|
|
1180
|
+
const u = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
1181
|
+
pe = u, n.send(JSON.stringify({ type: "microphoneStart", id: u }));
|
|
1182
|
+
}, tt = () => Et(() => kt()), kt = async () => {
|
|
1183
|
+
const n = xe, u = () => n === xe && et(), a = (f) => {
|
|
1184
|
+
L("onMicrophoneStateChange", e.onMicrophoneStateChange, {
|
|
1185
|
+
active: !1,
|
|
1186
|
+
error: f
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
if (!u()) return;
|
|
1190
|
+
const s = _, S = we;
|
|
1191
|
+
if (!s || s.readyState !== WebSocket.OPEN || !S || te) return;
|
|
1192
|
+
if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
|
|
1193
|
+
console.warn(
|
|
1194
|
+
"[RemoteControl] navigator.mediaDevices.getUserMedia unavailable. getUserMedia requires a secure context (https or http://localhost)."
|
|
1195
|
+
), a("Microphone capture requires a secure context (https)");
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
let m = null;
|
|
1199
|
+
try {
|
|
1200
|
+
m = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !1 });
|
|
1201
|
+
} catch (f) {
|
|
1202
|
+
console.warn("[RemoteControl] microphone getUserMedia denied/failed:", f);
|
|
1203
|
+
}
|
|
1204
|
+
if (!u()) {
|
|
1205
|
+
m && G(m);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (!m) {
|
|
1209
|
+
a("Microphone permission denied or no device available");
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const p = m.getAudioTracks()[0] ?? null;
|
|
1213
|
+
if (!p) {
|
|
1214
|
+
G(m), a("Captured stream has no audio track");
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
try {
|
|
1218
|
+
await S.replaceTrack(p);
|
|
1219
|
+
} catch (f) {
|
|
1220
|
+
y("replaceTrack(audioTrack) failed:", f), G(m), a("Failed to attach the microphone track to the connection");
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
if (!u()) {
|
|
1224
|
+
try {
|
|
1225
|
+
await S.replaceTrack(null);
|
|
1226
|
+
} catch (f) {
|
|
1227
|
+
y("replaceTrack(null) on stale mic attach failed:", f);
|
|
1228
|
+
}
|
|
1229
|
+
G(m);
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
te = m, p.onended = () => {
|
|
1233
|
+
te === m && Ve("microphone capture ended by the browser");
|
|
1234
|
+
}, ht(s), L("onMicrophoneStateChange", e.onMicrophoneStateChange, {
|
|
1235
|
+
active: !0,
|
|
1236
|
+
label: p.label || void 0
|
|
1237
|
+
});
|
|
1238
|
+
}, Ve = (n) => (++xe, pe = null, Et(async () => {
|
|
1239
|
+
const u = we, a = te;
|
|
1240
|
+
if (te = null, u && a)
|
|
1241
|
+
try {
|
|
1242
|
+
await u.replaceTrack(null);
|
|
1243
|
+
} catch (S) {
|
|
1244
|
+
y("replaceTrack(null) on mic detach failed:", S);
|
|
1245
|
+
}
|
|
1246
|
+
a && G(a);
|
|
1247
|
+
const s = _;
|
|
1248
|
+
if (a && s && s.readyState === WebSocket.OPEN) {
|
|
1249
|
+
const S = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
1250
|
+
s.send(JSON.stringify({ type: "microphoneStop", id: S }));
|
|
1251
|
+
}
|
|
1252
|
+
(a || n) && L("onMicrophoneStateChange", e.onMicrophoneStateChange, {
|
|
1253
|
+
active: !1,
|
|
1254
|
+
...n !== void 0 && { error: n }
|
|
1255
|
+
});
|
|
1256
|
+
})), mt = (n, u) => {
|
|
1257
|
+
let a;
|
|
1258
|
+
try {
|
|
1259
|
+
a = vn(u), console.info(
|
|
1260
|
+
`[RemoteControl] camera capture: ${a.camera?.width}x${a.camera?.height} @ ${a.camera?.frameRate ?? "?"}fps` + (a.camera?.label ? ` — ${a.camera.label}` : "")
|
|
1261
|
+
);
|
|
1262
|
+
} catch (s) {
|
|
1263
|
+
y("getSettings() on outbound camera track failed:", s), a = {
|
|
1264
|
+
type: "cameraResult",
|
|
1265
|
+
granted: !0,
|
|
1266
|
+
camera: {
|
|
1267
|
+
label: u.label || void 0
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
n.send(JSON.stringify(a)), L("onCameraDemandChange", e.onCameraDemandChange, !0, !0, a.camera);
|
|
1272
|
+
}, Ut = (n) => {
|
|
1273
|
+
if (!n) return;
|
|
1274
|
+
const u = n.indexOf("/"), s = (u >= 0 ? n.slice(u + 1) : n).toUpperCase();
|
|
1275
|
+
return s === "HEVC" ? "H265" : s;
|
|
1276
|
+
}, Pt = async () => {
|
|
1277
|
+
const n = de, u = e.onCameraStats;
|
|
1278
|
+
if (!n || !u) return;
|
|
1279
|
+
let a;
|
|
1280
|
+
try {
|
|
1281
|
+
a = await n.getStats();
|
|
1282
|
+
} catch {
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
let s, S, m;
|
|
1286
|
+
if (a.forEach((N) => {
|
|
1287
|
+
N.type === "outbound-rtp" && N.kind === "video" ? s = N : N.type === "remote-inbound-rtp" && N.kind === "video" && (m = N);
|
|
1288
|
+
}), s?.codecId) {
|
|
1289
|
+
const N = a.get(s.codecId);
|
|
1290
|
+
N && (S = N.mimeType);
|
|
1291
|
+
}
|
|
1292
|
+
if (!s) return;
|
|
1293
|
+
const p = s.timestamp ?? Date.now(), f = Be;
|
|
1294
|
+
let $, k, X;
|
|
1295
|
+
if (f && p > f.timestamp) {
|
|
1296
|
+
const N = (p - f.timestamp) / 1e3;
|
|
1297
|
+
if (typeof s.framesEncoded == "number" && typeof f.framesEncoded == "number" && ($ = Math.max(0, (s.framesEncoded - f.framesEncoded) / N)), typeof s.bytesSent == "number" && typeof f.bytesSent == "number" && (k = Math.max(0, (s.bytesSent - f.bytesSent) * 8 / N)), typeof s.packetsSent == "number" && typeof f.packetsSent == "number" && m && typeof m.packetsLost == "number" && typeof f.packetsLost == "number") {
|
|
1298
|
+
const v = s.packetsSent - f.packetsSent, Ge = m.packetsLost - f.packetsLost;
|
|
1299
|
+
v > 0 && (X = Math.max(0, Math.min(100, Ge / v * 100)));
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
Be = {
|
|
1303
|
+
timestamp: p,
|
|
1304
|
+
framesEncoded: s.framesEncoded,
|
|
1305
|
+
bytesSent: s.bytesSent,
|
|
1306
|
+
packetsSent: s.packetsSent,
|
|
1307
|
+
packetsLost: m?.packetsLost
|
|
1308
|
+
};
|
|
1309
|
+
const w = {
|
|
1310
|
+
codec: Ut(S),
|
|
1311
|
+
encoderImplementation: s.encoderImplementation,
|
|
1312
|
+
hardwareAccelerated: typeof s.powerEfficientEncoder == "boolean" ? s.powerEfficientEncoder : void 0,
|
|
1313
|
+
framesPerSecond: $,
|
|
1314
|
+
framesEncoded: s.framesEncoded,
|
|
1315
|
+
bitrateBps: k,
|
|
1316
|
+
width: s.frameWidth,
|
|
1317
|
+
height: s.frameHeight,
|
|
1318
|
+
qualityLimitationReason: s.qualityLimitationReason,
|
|
1319
|
+
rttMs: typeof m?.roundTripTime == "number" ? m.roundTripTime * 1e3 : void 0,
|
|
1320
|
+
packetsLostPct: X
|
|
1321
|
+
};
|
|
1322
|
+
L("onCameraStats", e.onCameraStats, w);
|
|
1323
|
+
}, pt = () => {
|
|
1324
|
+
Ke === null && (Be = null, Ke = setInterval(() => {
|
|
1325
|
+
Pt();
|
|
1326
|
+
}, 1e3));
|
|
1327
|
+
}, He = () => {
|
|
1328
|
+
Ke !== null && (clearInterval(Ke), Ke = null), Be = null, L("onCameraStats", e.onCameraStats, null);
|
|
1329
|
+
}, Lt = (n, u, a, s) => Qe.enqueue(async ({ isCurrent: S }) => {
|
|
1330
|
+
const m = () => S() && s() && _ === u && de === a;
|
|
1331
|
+
if (!m()) return;
|
|
1332
|
+
if (!n.active) {
|
|
1333
|
+
const w = z;
|
|
1334
|
+
try {
|
|
1335
|
+
await a.replaceTrack(null);
|
|
1336
|
+
} catch (N) {
|
|
1337
|
+
y("replaceTrack(null) on camera detach failed:", N);
|
|
1338
|
+
}
|
|
1339
|
+
if (z === w && (z = null, ue = void 0, w && G(w)), He(), !m()) return;
|
|
1340
|
+
L("onCameraDemandChange", e.onCameraDemandChange, !1);
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
L("onCameraDemandChange", e.onCameraDemandChange, !0);
|
|
1344
|
+
const p = z, f = p?.getVideoTracks()[0], $ = ue;
|
|
1345
|
+
if (f?.readyState === "live" && $ && !Sn($, n)) {
|
|
1346
|
+
ue = n, mt(u, f), pt();
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
if (p) {
|
|
1350
|
+
try {
|
|
1351
|
+
await a.replaceTrack(null);
|
|
1352
|
+
} catch (w) {
|
|
1353
|
+
y("replaceTrack(null) before camera switch failed:", w);
|
|
1354
|
+
}
|
|
1355
|
+
if (z === p && (z = null, ue = void 0, G(p)), He(), !m()) return;
|
|
1356
|
+
}
|
|
1357
|
+
if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
|
|
1358
|
+
if (console.warn(
|
|
1359
|
+
"[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."
|
|
1360
|
+
), !m()) return;
|
|
1361
|
+
u.send(JSON.stringify({ type: "cameraResult", granted: !1 })), L("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
let k = null;
|
|
1365
|
+
try {
|
|
1366
|
+
k = await navigator.mediaDevices.getUserMedia({
|
|
1367
|
+
video: Tn(n),
|
|
1368
|
+
audio: !1
|
|
1369
|
+
});
|
|
1370
|
+
} catch (w) {
|
|
1371
|
+
console.warn("[RemoteControl] getUserMedia denied/failed:", w);
|
|
1372
|
+
}
|
|
1373
|
+
if (!m()) {
|
|
1374
|
+
k && G(k);
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
if (!k) {
|
|
1378
|
+
u.send(JSON.stringify({ type: "cameraResult", granted: !1 })), L("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
const X = k.getVideoTracks()[0] ?? null;
|
|
1382
|
+
if (!X) {
|
|
1383
|
+
if (G(k), !m()) return;
|
|
1384
|
+
u.send(JSON.stringify({ type: "cameraResult", granted: !1 })), L("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
try {
|
|
1388
|
+
X.contentHint = "motion";
|
|
1389
|
+
} catch {
|
|
1390
|
+
}
|
|
1391
|
+
try {
|
|
1392
|
+
await a.replaceTrack(X);
|
|
1393
|
+
} catch (w) {
|
|
1394
|
+
if (y("replaceTrack(videoTrack) failed:", w), G(k), !m()) return;
|
|
1395
|
+
u.send(JSON.stringify({ type: "cameraResult", granted: !1 })), L("onCameraDemandChange", e.onCameraDemandChange, !0, !1);
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
if (!m()) {
|
|
1399
|
+
try {
|
|
1400
|
+
await a.replaceTrack(null);
|
|
1401
|
+
} catch (w) {
|
|
1402
|
+
y("replaceTrack(null) for stale camera attach failed:", w);
|
|
1403
|
+
}
|
|
1404
|
+
G(k);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
try {
|
|
1408
|
+
const w = a.getParameters();
|
|
1409
|
+
(!w.encodings || w.encodings.length === 0) && (w.encodings = [{}]), w.encodings[0].maxBitrate = 8e6, w.encodings[0].maxFramerate = 30, w.degradationPreference = "maintain-framerate", await a.setParameters(w);
|
|
1410
|
+
} catch (w) {
|
|
1411
|
+
y("setParameters on outbound camera failed:", w);
|
|
1412
|
+
}
|
|
1413
|
+
if (!m()) {
|
|
1414
|
+
try {
|
|
1415
|
+
await a.replaceTrack(null);
|
|
1416
|
+
} catch (w) {
|
|
1417
|
+
y("replaceTrack(null) for stale camera finalize failed:", w);
|
|
1418
|
+
}
|
|
1419
|
+
G(k);
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
z = k, ue = n, X.onended = () => {
|
|
1423
|
+
z === k && Qe.enqueueCurrent(async ({ isCurrent: w }) => {
|
|
1424
|
+
if (!(!w() || z !== k || !s() || _ !== u || de !== a)) {
|
|
1425
|
+
try {
|
|
1426
|
+
await a.replaceTrack(null);
|
|
1427
|
+
} catch (N) {
|
|
1428
|
+
y("replaceTrack(null) after camera ended failed:", N);
|
|
1429
|
+
}
|
|
1430
|
+
!w() || z !== k || !s() || _ !== u || de !== a || (z = null, ue = void 0, G(k), He(), u.send(JSON.stringify({ type: "cameraResult", granted: !1 })), L("onCameraDemandChange", e.onCameraDemandChange, !0, !1));
|
|
1431
|
+
}
|
|
1432
|
+
}).catch((w) => y("camera ended cleanup failed:", w));
|
|
1433
|
+
}, m() && (mt(u, X), pt());
|
|
1434
|
+
}), _e = () => {
|
|
1435
|
+
for (const n of H) n();
|
|
1436
|
+
H.clear();
|
|
1437
|
+
for (const n of B.values()) clearTimeout(n);
|
|
1438
|
+
B.clear();
|
|
1439
|
+
for (const n of ee.values())
|
|
1440
|
+
n(new Error("Simulator disconnected"));
|
|
1441
|
+
for (const n of ie.values())
|
|
1442
|
+
n(new Error("Simulator disconnected"));
|
|
1443
|
+
ee.clear(), re.clear(), ie.clear(), ae.clear(), V?.(), V = void 0, bt(), b = null;
|
|
1444
|
+
for (const n of fe.values())
|
|
1445
|
+
clearTimeout(n.timer), n.reject(new Error("Simulator disconnected"));
|
|
1446
|
+
fe.clear(), Oe = void 0, A(null), O({ controlReady: !1, videoReady: !1 }), $e(), Ie(), Ne(), q && (q.stop(), q = null), Ye !== null && We(null), Qe.invalidate(), He(), It(), ue = void 0, de = null, ++xe, Ze = !1, pe = null, te && (G(te), te = null, L("onMicrophoneStateChange", e.onMicrophoneStateChange, {
|
|
1447
|
+
active: !1
|
|
1448
|
+
})), we = null, _ && (_.onopen = null, _.onmessage = null, _.onerror = null, _.onclose = null, _.close(), _ = null), Pe?.close(), Pe = null, R && (R.onconnectionstatechange = null, R.oniceconnectionstatechange = null, R.ontrack = null, R.onicecandidate = null, R.close(), R = null), x && (x.onopen = null, x.onclose = null, x.onerror = null, x.close(), x = null);
|
|
1449
|
+
}, Ct = () => {
|
|
1450
|
+
document.hidden ? Re() : ft();
|
|
1451
|
+
}, Ft = async () => {
|
|
1452
|
+
if (e.transport) return e.transport.isTerminated?.() ?? !1;
|
|
1453
|
+
if (typeof navigator < "u" && navigator.onLine === !1)
|
|
1454
|
+
return !1;
|
|
1455
|
+
let n;
|
|
1456
|
+
try {
|
|
1457
|
+
const s = new URL(r);
|
|
1458
|
+
s.protocol = s.protocol === "wss:" ? "https:" : s.protocol === "ws:" ? "http:" : s.protocol, n = Kt(s.toString(), c);
|
|
1459
|
+
} catch {
|
|
1460
|
+
return !1;
|
|
1461
|
+
}
|
|
1462
|
+
const u = new AbortController(), a = window.setTimeout(() => u.abort(), Yn);
|
|
1463
|
+
try {
|
|
1464
|
+
return (await fetch(n, { method: "GET", cache: "no-store", signal: u.signal })).status === 404;
|
|
1465
|
+
} catch {
|
|
1466
|
+
return !1;
|
|
1467
|
+
} finally {
|
|
1468
|
+
window.clearTimeout(a);
|
|
1469
|
+
}
|
|
1470
|
+
}, Bt = () => {
|
|
1471
|
+
Ee || (Ee = !0, le += 1, qe(), $e(), Ie(), _e(), T("Instance terminated"), Re(), De("terminated"), L("onTerminated", e.onTerminated));
|
|
1472
|
+
}, xt = () => {
|
|
1473
|
+
if (Ee || ye) return;
|
|
1474
|
+
ye = !0;
|
|
1475
|
+
const n = Ue;
|
|
1476
|
+
Ft().catch(() => !1).then((u) => {
|
|
1477
|
+
n === Ue && (ye = !1, u && Bt());
|
|
1478
|
+
});
|
|
1479
|
+
}, ge = (n, u) => {
|
|
1480
|
+
if (Ee || u !== le)
|
|
1481
|
+
return;
|
|
1482
|
+
if (xt(), ne) {
|
|
1483
|
+
if (!e.autoReconnect) {
|
|
1484
|
+
T(`Connection failed after it was established: ${n}`), Re(), De("failed"), _e();
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
T(`Reconnecting after established session dropped: ${n}`), ne = !1, Fe = -1;
|
|
1488
|
+
}
|
|
1489
|
+
qe();
|
|
1490
|
+
const a = Fe + 1;
|
|
1491
|
+
if (a >= st) {
|
|
1492
|
+
T(`Connection failed after ${st} attempts: ${n}`), Re(), De("failed"), _e();
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
T(`Retrying connection (${a + 1}/${st})`), De("reconnecting"), _e(), ve = window.setTimeout(() => {
|
|
1496
|
+
ve = void 0, u === le && Ot(a);
|
|
1497
|
+
}, Kn);
|
|
1498
|
+
}, Ot = async (n = 0) => {
|
|
1499
|
+
const { openUrl: u, axPollIntervalMs: a, axMaxBackoffMs: s, androidElementTreeOptions: S } = e;
|
|
1500
|
+
if (Ee) return;
|
|
1501
|
+
const m = le + 1;
|
|
1502
|
+
le = m, Fe = n, ne = !1, n === 0 && Ce !== "reconnecting" && De("connecting"), qe(), $e(), Ne(), Me = !1, C(!1), _e();
|
|
1503
|
+
const p = () => m === le;
|
|
1504
|
+
Ae = window.setTimeout(() => {
|
|
1505
|
+
Ae = void 0, !(!p() || ne) && ge("Connection did not succeed within 15 seconds", m);
|
|
1506
|
+
}, wn);
|
|
1507
|
+
try {
|
|
1508
|
+
const f = e.transport ? await e.transport.connect() : new WebSocket(Kt(r, c));
|
|
1509
|
+
if (!p()) {
|
|
1510
|
+
f.close();
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (_ = f, await new Promise((D, i) => {
|
|
1514
|
+
let I = !1;
|
|
1515
|
+
const W = () => K(() => i(new Error("Connection stopped")));
|
|
1516
|
+
H.add(W);
|
|
1517
|
+
const g = window.setTimeout(
|
|
1518
|
+
() => K(() => i(new Error("WebSocket connection timeout"))),
|
|
1519
|
+
3e4
|
|
1520
|
+
), K = (Z) => {
|
|
1521
|
+
I || (I = !0, H.delete(W), window.clearTimeout(g), Z());
|
|
1522
|
+
};
|
|
1523
|
+
f.onopen = () => {
|
|
1524
|
+
!p() || _ !== f || K(D);
|
|
1525
|
+
}, f.onerror = (Z) => {
|
|
1526
|
+
!p() || _ !== f || (T("WebSocket error: " + Z), K(() => i(new Error("WebSocket connection failed"))));
|
|
1527
|
+
}, f.onclose = () => {
|
|
1528
|
+
!p() || _ !== f || (T("WebSocket closed"), K(() => i(new Error("WebSocket closed before connection was established"))));
|
|
1529
|
+
}, f.readyState === WebSocket.OPEN ? K(D) : f.readyState !== WebSocket.CONNECTING && K(() => i(new Error("WebSocket is closed")));
|
|
1530
|
+
}), !p() || _ !== f)
|
|
1531
|
+
return;
|
|
1532
|
+
f.onerror = (D) => {
|
|
1533
|
+
!p() || _ !== f || T("WebSocket error: " + D);
|
|
1534
|
+
}, f.onclose = () => {
|
|
1535
|
+
!p() || _ !== f || T("WebSocket closed");
|
|
1536
|
+
};
|
|
1537
|
+
const $ = new Promise((D, i) => {
|
|
1538
|
+
let I = !1;
|
|
1539
|
+
const W = () => g(() => i(new Error("Connection stopped")));
|
|
1540
|
+
H.add(W);
|
|
1541
|
+
const g = (J) => {
|
|
1542
|
+
I || (I = !0, H.delete(W), window.clearTimeout(K), f.removeEventListener("message", Z), J());
|
|
1543
|
+
}, K = window.setTimeout(
|
|
1544
|
+
() => g(() => i(new Error("RTCConfiguration timeout"))),
|
|
1545
|
+
3e4
|
|
1546
|
+
), Z = (J) => {
|
|
1547
|
+
if (!(!p() || _ !== f))
|
|
1548
|
+
try {
|
|
1549
|
+
const Q = JSON.parse(J.data);
|
|
1550
|
+
if (Q.type === "signalingError" && Q.requestType === "requestRtcConfiguration" && Q.sessionId === d) {
|
|
1551
|
+
const $t = typeof Q.error == "string" ? Q.error : "Unable to load streaming configuration";
|
|
1552
|
+
g(() => i(new Error($t)));
|
|
1553
|
+
} else Q.type === "rtcConfiguration" && g(
|
|
1554
|
+
() => D({
|
|
1555
|
+
rtcConfiguration: Q.rtcConfiguration,
|
|
1556
|
+
cameraSupported: Q.cameraSupported === !0,
|
|
1557
|
+
foldSupported: Q.foldSupported === !0
|
|
1558
|
+
})
|
|
1559
|
+
);
|
|
1560
|
+
} catch (Q) {
|
|
1561
|
+
console.error("Error handling RTC configuration:", Q), g(() => i(Q));
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
f.addEventListener("message", Z), f.send(
|
|
1565
|
+
JSON.stringify({
|
|
1566
|
+
type: "requestRtcConfiguration",
|
|
1567
|
+
sessionId: d
|
|
1568
|
+
})
|
|
1569
|
+
);
|
|
1570
|
+
}), {
|
|
1571
|
+
rtcConfiguration: k,
|
|
1572
|
+
cameraSupported: X,
|
|
1573
|
+
foldSupported: w
|
|
1574
|
+
} = await $;
|
|
1575
|
+
if (!p() || _ !== f)
|
|
1576
|
+
return;
|
|
1577
|
+
const N = E === "iphone-duo" || w;
|
|
1578
|
+
U(N);
|
|
1579
|
+
const v = new RTCPeerConnection({ ...k, iceTransportPolicy: "relay" });
|
|
1580
|
+
R = v;
|
|
1581
|
+
const Ge = { peer: v, displays: /* @__PURE__ */ new Map() };
|
|
1582
|
+
b = Ge, F(), v.addTransceiver("audio", { direction: "recvonly" });
|
|
1583
|
+
const Wt = v.addTransceiver("video", { direction: "recvonly" }), qt = N ? v.addTransceiver("video", { direction: "recvonly" }) : null, Tt = l === "ios" || X, nt = Tt ? v.addTransceiver("video", {
|
|
1584
|
+
direction: "sendonly"
|
|
1585
|
+
}) : null;
|
|
1586
|
+
if (de = nt?.sender ?? null, we = (Tt ? v.addTransceiver("audio", {
|
|
1587
|
+
direction: "sendonly"
|
|
1588
|
+
}) : null)?.sender ?? null, RTCRtpReceiver.getCapabilities) {
|
|
1589
|
+
const D = RTCRtpReceiver.getCapabilities("video");
|
|
1590
|
+
if (D && D.codecs) {
|
|
1591
|
+
const I = D.codecs.sort((W, g) => {
|
|
1592
|
+
const K = (Z) => {
|
|
1593
|
+
const J = Z.mimeType.toLowerCase();
|
|
1594
|
+
return J.includes("vp9") ? 1 : J.includes("h265") || J.includes("hevc") ? 2 : J.includes("h264") || J.includes("avc") ? 3 : 4;
|
|
1595
|
+
};
|
|
1596
|
+
return K(W) - K(g);
|
|
1597
|
+
});
|
|
1598
|
+
Wt.setCodecPreferences(I), qt?.setCodecPreferences(I), ce("Set codec preferences:", I.map((W) => W.mimeType).join(", "));
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
if (nt && RTCRtpSender.getCapabilities) {
|
|
1602
|
+
const D = RTCRtpSender.getCapabilities("video");
|
|
1603
|
+
if (D && D.codecs) {
|
|
1604
|
+
const i = /* @__PURE__ */ new Set(["42e01f", "42e028", "640c1f"]), I = (g) => {
|
|
1605
|
+
const K = g.mimeType.toLowerCase(), J = (g.sdpFmtpLine || "").toLowerCase().match(/profile-level-id=([0-9a-f]{6})/), Q = J ? J[1] : "";
|
|
1606
|
+
return K === "video/h265" || K === "video/hevc" ? 1 : K === "video/h264" && i.has(Q) ? 2 : K === "video/h264" ? 3 : K === "video/vp9" ? 4 : K === "video/vp8" ? 5 : K === "video/rtx" || K === "video/red" || K === "video/ulpfec" ? 0 : 6;
|
|
1607
|
+
}, W = [...D.codecs].sort((g, K) => I(g) - I(K));
|
|
1608
|
+
try {
|
|
1609
|
+
nt.setCodecPreferences(W), ce(
|
|
1610
|
+
"Outbound camera codec preferences:",
|
|
1611
|
+
W.map((g) => `${g.mimeType}${g.sdpFmtpLine ? `[${g.sdpFmtpLine}]` : ""}`).join(", ")
|
|
1612
|
+
);
|
|
1613
|
+
} catch (g) {
|
|
1614
|
+
y("Failed to set outbound camera codec preferences:", g);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
const oe = v.createDataChannel("control", {
|
|
1619
|
+
ordered: !0,
|
|
1620
|
+
negotiated: !0,
|
|
1621
|
+
id: 1
|
|
1622
|
+
});
|
|
1623
|
+
x = oe;
|
|
1624
|
+
const rt = !N && e.onTrace ? Dn(v, (D) => {
|
|
1625
|
+
p() && R === v && L("onTrace", e.onTrace, D);
|
|
1626
|
+
}) : null;
|
|
1627
|
+
if (Pe = rt, oe.onopen = () => {
|
|
1628
|
+
if (!p() || x !== oe || _ !== f)
|
|
1629
|
+
return;
|
|
1630
|
+
ne = !0, N && ut().catch((i) => {
|
|
1631
|
+
p() && _ === f && f.readyState === WebSocket.OPEN && M(i instanceof Error ? i.message : String(i));
|
|
1632
|
+
}), O({ controlReady: !0 }), $e(), T("Control channel opened"), q || (q = new hn({
|
|
1633
|
+
platform: l,
|
|
1634
|
+
baseIntervalMs: a,
|
|
1635
|
+
maxBackoffMs: s,
|
|
1636
|
+
androidElementTreeOptions: S,
|
|
1637
|
+
send: (i) => {
|
|
1638
|
+
if (!_ || _.readyState !== WebSocket.OPEN) return !1;
|
|
1639
|
+
try {
|
|
1640
|
+
return _.send(JSON.stringify(i)), !0;
|
|
1641
|
+
} catch {
|
|
1642
|
+
return !1;
|
|
1643
|
+
}
|
|
1644
|
+
},
|
|
1645
|
+
onSnapshot: We,
|
|
1646
|
+
onStatusChange: (i, I) => {
|
|
1647
|
+
L("onAxStatusChange", e.onAxStatusChange, i, I);
|
|
1648
|
+
}
|
|
1649
|
+
}), (e.inspectMode === !0 || e.inspectMode === "hover-only") && q.start());
|
|
1650
|
+
const D = () => {
|
|
1651
|
+
!p() || Me || x !== oe || _ !== f || f.readyState !== WebSocket.OPEN || f.send(JSON.stringify({ type: "requestFrame", sessionId: d }));
|
|
1652
|
+
};
|
|
1653
|
+
if (D(), Ne(), Le = window.setInterval(() => {
|
|
1654
|
+
if (!p() || Me || x !== oe || _ !== f || f.readyState !== WebSocket.OPEN) {
|
|
1655
|
+
Ne();
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
D();
|
|
1659
|
+
}, 250), u) {
|
|
1660
|
+
try {
|
|
1661
|
+
const i = decodeURIComponent(u);
|
|
1662
|
+
T("Opening URL"), f.send(
|
|
1663
|
+
JSON.stringify({
|
|
1664
|
+
type: "openUrl",
|
|
1665
|
+
url: i,
|
|
1666
|
+
sessionId: d
|
|
1667
|
+
})
|
|
1668
|
+
);
|
|
1669
|
+
} catch (i) {
|
|
1670
|
+
console.error({ error: i }, "Error decoding URL, falling back to the original URL"), f.send(
|
|
1671
|
+
JSON.stringify({
|
|
1672
|
+
type: "openUrl",
|
|
1673
|
+
url: u,
|
|
1674
|
+
sessionId: d
|
|
1675
|
+
})
|
|
1676
|
+
);
|
|
1677
|
+
}
|
|
1678
|
+
q?.bumpActivity();
|
|
1679
|
+
}
|
|
1680
|
+
}, oe.onclose = () => {
|
|
1681
|
+
!p() || x !== oe || (O({ controlReady: !1 }), T("Control channel closed"));
|
|
1682
|
+
}, oe.onerror = (D) => {
|
|
1683
|
+
!p() || x !== oe || (console.error("Control channel error:", D), T("Control channel error: " + D));
|
|
1684
|
+
}, v.onconnectionstatechange = () => {
|
|
1685
|
+
!p() || R !== v || (T("Connection state: " + v.connectionState), v.connectionState === "failed" && ne && ge("WebRTC connection entered failed state", m));
|
|
1686
|
+
}, v.oniceconnectionstatechange = () => {
|
|
1687
|
+
if (!p() || R !== v)
|
|
1688
|
+
return;
|
|
1689
|
+
const D = v.iceConnectionState;
|
|
1690
|
+
if (T("ICE state: " + D), D === "connected" || D === "completed") {
|
|
1691
|
+
Ie(), et() && !te && tt();
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
if (D === "failed") {
|
|
1695
|
+
Ie(), ne && ge("ICE connection entered failed state", m);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
D === "disconnected" && ne && e.autoReconnect && me === void 0 && (me = window.setTimeout(() => {
|
|
1699
|
+
me = void 0, !(!p() || R !== v) && v.iceConnectionState === "disconnected" && ge("ICE stayed disconnected past grace period", m);
|
|
1700
|
+
}, Mn));
|
|
1701
|
+
}, v.ontrack = (D) => {
|
|
1702
|
+
if (!p() || R !== v)
|
|
1703
|
+
return;
|
|
1704
|
+
vt(D.receiver, e.jitterBufferTargetMs);
|
|
1705
|
+
const i = D.track.id === "duo-inner" || D.streams.some((I) => I.id === "duo-inner");
|
|
1706
|
+
if (D.track.kind === "video" && Ge.displays.set(D.receiver, i ? "inner" : "primary"), T("Received remote track: " + D.track.kind), D.track.kind === "video") {
|
|
1707
|
+
const I = i ? "inner" : "primary", W = N ? new MediaStream([D.track]) : D.streams[0] ?? new MediaStream([D.track]);
|
|
1708
|
+
Se.set(I, W);
|
|
1709
|
+
for (const [g, K] of Y)
|
|
1710
|
+
K.display === I && ct(g, K, W);
|
|
1711
|
+
}
|
|
1712
|
+
}, v.onicecandidate = (D) => {
|
|
1713
|
+
if (!(!p() || R !== v || _ !== f))
|
|
1714
|
+
if (D.candidate && f.readyState === WebSocket.OPEN) {
|
|
1715
|
+
const i = {
|
|
1716
|
+
type: "candidate",
|
|
1717
|
+
candidate: D.candidate.candidate,
|
|
1718
|
+
sdpMid: D.candidate.sdpMid,
|
|
1719
|
+
sdpMLineIndex: D.candidate.sdpMLineIndex,
|
|
1720
|
+
sessionId: d
|
|
1721
|
+
};
|
|
1722
|
+
f.send(JSON.stringify(i)), T("Sent ICE candidate");
|
|
1723
|
+
} else
|
|
1724
|
+
T("ICE candidate gathering completed");
|
|
1725
|
+
}, f.onmessage = async (D) => {
|
|
1726
|
+
if (!p() || _ !== f)
|
|
1727
|
+
return;
|
|
1728
|
+
let i;
|
|
1729
|
+
try {
|
|
1730
|
+
i = JSON.parse(D.data);
|
|
1731
|
+
} catch (I) {
|
|
1732
|
+
y("Error parsing message:", I);
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (!q?.handleMessage(i))
|
|
1736
|
+
switch (T("Received: " + i.type), i.type) {
|
|
1737
|
+
case "performActionsResult":
|
|
1738
|
+
case "foldStateResult":
|
|
1739
|
+
case "foldStateChanged": {
|
|
1740
|
+
N && i.state && (A(i.state), M(void 0));
|
|
1741
|
+
const g = fe.get(i.id);
|
|
1742
|
+
g && (clearTimeout(g.timer), fe.delete(i.id), i.error ? g.reject(new Error(i.error)) : g.resolve());
|
|
1743
|
+
break;
|
|
1744
|
+
}
|
|
1745
|
+
case "signalingError": {
|
|
1746
|
+
if (i.requestType !== "offer" || i.sessionId !== d)
|
|
1747
|
+
break;
|
|
1748
|
+
const g = typeof i.error == "string" ? i.error : "Unable to establish the streaming connection";
|
|
1749
|
+
T("Error: " + g), ge(g, m);
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
case "answer":
|
|
1753
|
+
if (!R || R !== v) {
|
|
1754
|
+
T("No peer connection, skipping answer");
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
if (rt?.accept(i.latencyTraceVersion), await v.setRemoteDescription(
|
|
1758
|
+
new RTCSessionDescription({
|
|
1759
|
+
type: "answer",
|
|
1760
|
+
sdp: i.sdp
|
|
1761
|
+
})
|
|
1762
|
+
), !p() || R !== v)
|
|
1763
|
+
return;
|
|
1764
|
+
T("Set remote description");
|
|
1765
|
+
break;
|
|
1766
|
+
case "candidate":
|
|
1767
|
+
if (!R || R !== v) {
|
|
1768
|
+
T("No peer connection, skipping candidate");
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
if (await v.addIceCandidate(
|
|
1772
|
+
new RTCIceCandidate({
|
|
1773
|
+
candidate: i.candidate,
|
|
1774
|
+
sdpMid: i.sdpMid,
|
|
1775
|
+
sdpMLineIndex: i.sdpMLineIndex
|
|
1776
|
+
})
|
|
1777
|
+
), !p() || R !== v)
|
|
1778
|
+
return;
|
|
1779
|
+
T("Added ICE candidate");
|
|
1780
|
+
break;
|
|
1781
|
+
case "screenshot":
|
|
1782
|
+
case "screenshotResult": {
|
|
1783
|
+
if (typeof i.id != "string") {
|
|
1784
|
+
y("Received invalid screenshot success message:", i);
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
const g = bn(i);
|
|
1788
|
+
if (g) {
|
|
1789
|
+
const J = ee.get(i.id);
|
|
1790
|
+
if (typeof J != "function") {
|
|
1791
|
+
y(`Received screenshot error for unknown or handled id: ${i.id}`);
|
|
1792
|
+
break;
|
|
1793
|
+
}
|
|
1794
|
+
y(`Received screenshot error for id ${i.id}: ${g}`), J(new Error(g)), re.delete(i.id), ee.delete(i.id), clearTimeout(B.get(i.id)), B.delete(i.id);
|
|
1795
|
+
break;
|
|
1796
|
+
}
|
|
1797
|
+
const K = Rn(i);
|
|
1798
|
+
if (!K) {
|
|
1799
|
+
y("Received screenshot message without image data:", i);
|
|
1800
|
+
break;
|
|
1801
|
+
}
|
|
1802
|
+
const Z = re.get(i.id);
|
|
1803
|
+
if (typeof Z != "function") {
|
|
1804
|
+
y(`Received screenshot data for unknown or handled id: ${i.id}`);
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
ce(`Received screenshot data for id ${i.id}`), Z(K), re.delete(i.id), ee.delete(i.id), clearTimeout(B.get(i.id)), B.delete(i.id);
|
|
1808
|
+
break;
|
|
1809
|
+
}
|
|
1810
|
+
case "screenshotError":
|
|
1811
|
+
if (typeof i.id != "string" || typeof i.message != "string") {
|
|
1812
|
+
y("Received invalid screenshot error message:", i);
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
const I = ee.get(i.id);
|
|
1816
|
+
if (typeof I != "function") {
|
|
1817
|
+
y(`Received screenshot error for unknown or handled id: ${i.id}`);
|
|
1818
|
+
break;
|
|
1819
|
+
}
|
|
1820
|
+
y(`Received screenshot error for id ${i.id}: ${i.message}`), I(new Error(i.message)), re.delete(i.id), ee.delete(i.id), clearTimeout(B.get(i.id)), B.delete(i.id);
|
|
1821
|
+
break;
|
|
1822
|
+
case "cameraRequest": {
|
|
1823
|
+
const g = de;
|
|
1824
|
+
if (!g)
|
|
1825
|
+
break;
|
|
1826
|
+
const K = gn(i);
|
|
1827
|
+
if (!K) {
|
|
1828
|
+
y("Received invalid cameraRequest:", i);
|
|
1829
|
+
break;
|
|
1830
|
+
}
|
|
1831
|
+
console.info("[RemoteControl] cameraRequest received:", K.active, K.facingMode), await Lt(K, f, g, p);
|
|
1832
|
+
break;
|
|
1833
|
+
}
|
|
1834
|
+
case "microphoneRequest": {
|
|
1835
|
+
if (!we)
|
|
1836
|
+
break;
|
|
1837
|
+
const g = i.active === !0;
|
|
1838
|
+
if (Ze = g, console.info("[RemoteControl] microphoneRequest received, active=", g), !g) {
|
|
1839
|
+
ze || await Ve();
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
if (te) {
|
|
1843
|
+
ht(f);
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
await tt();
|
|
1847
|
+
break;
|
|
1848
|
+
}
|
|
1849
|
+
case "microphoneStartResult": {
|
|
1850
|
+
if (pe === null || i.id !== pe)
|
|
1851
|
+
break;
|
|
1852
|
+
pe = null, typeof i.error == "string" && (console.warn("[RemoteControl] microphoneStart rejected by host:", i.error), Ve(i.error));
|
|
1853
|
+
break;
|
|
1854
|
+
}
|
|
1855
|
+
case "terminateAppResult":
|
|
1856
|
+
if (typeof i.id != "string") {
|
|
1857
|
+
y("Received invalid terminateApp result message:", i);
|
|
1858
|
+
break;
|
|
1859
|
+
}
|
|
1860
|
+
if (typeof i.error == "string") {
|
|
1861
|
+
const g = ie.get(i.id);
|
|
1862
|
+
if (typeof g != "function") {
|
|
1863
|
+
y(`Received terminateApp error for unknown or handled id: ${i.id}`);
|
|
1864
|
+
break;
|
|
1865
|
+
}
|
|
1866
|
+
y(`Received terminateApp error for id ${i.id}: ${i.error}`), g(new Error(i.error)), ae.delete(i.id), ie.delete(i.id), clearTimeout(B.get(i.id)), B.delete(i.id);
|
|
1867
|
+
break;
|
|
1868
|
+
}
|
|
1869
|
+
const W = ae.get(i.id);
|
|
1870
|
+
if (typeof W != "function") {
|
|
1871
|
+
y(`Received terminateApp result for unknown or handled id: ${i.id}`);
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
ce(`Received terminateApp success for id ${i.id}`), W(), ae.delete(i.id), ie.delete(i.id), clearTimeout(B.get(i.id)), B.delete(i.id);
|
|
1875
|
+
break;
|
|
1876
|
+
default:
|
|
1877
|
+
y(`Received unhandled message type: ${i.type}`, i);
|
|
1878
|
+
break;
|
|
1879
|
+
}
|
|
1880
|
+
}, R === v) {
|
|
1881
|
+
const D = await v.createOffer({
|
|
1882
|
+
offerToReceiveVideo: !0,
|
|
1883
|
+
offerToReceiveAudio: !1
|
|
1884
|
+
});
|
|
1885
|
+
if (!p() || R !== v || (await v.setLocalDescription(D), !p() || R !== v))
|
|
1886
|
+
return;
|
|
1887
|
+
p() && _ === f && f.readyState === WebSocket.OPEN && f.send(
|
|
1888
|
+
JSON.stringify({
|
|
1889
|
+
type: "offer",
|
|
1890
|
+
...N ? { displayStreams: !0 } : {},
|
|
1891
|
+
...rt ? { latencyTraceVersion: 1 } : {},
|
|
1892
|
+
sdp: D.sdp,
|
|
1893
|
+
sessionId: d
|
|
1894
|
+
})
|
|
1895
|
+
), T("Sent offer");
|
|
1896
|
+
}
|
|
1897
|
+
} catch (f) {
|
|
1898
|
+
if (!p() || f instanceof Error && f.message === "Connection stopped")
|
|
1899
|
+
return;
|
|
1900
|
+
const $ = f instanceof Error ? f.message : String(f);
|
|
1901
|
+
T("Error: " + $), ge($, m);
|
|
1902
|
+
}
|
|
1903
|
+
}, Dt = () => {
|
|
1904
|
+
if (j) throw new Error("Device stream is disposed");
|
|
1905
|
+
Ue++, ye = !1, We(null), Ce !== "reconnecting" && (Ce = null), document.addEventListener("visibilitychange", Ct), document.hidden || ft(), Ee = !1, Ot(0);
|
|
1906
|
+
}, _t = () => {
|
|
1907
|
+
Ue++, ye = !1, Re(), document.removeEventListener("visibilitychange", Ct), le += 1, Fe = 0, ne = !1, qe(), Ie(), _e(), Ce = null, O({ connection: "idle", videoReady: !1, controlReady: !1 }), T("Stopped");
|
|
1908
|
+
}, gt = (n, u = "primary") => {
|
|
1909
|
+
if (j) throw new Error("Device stream is disposed");
|
|
1910
|
+
if (Y.has(n)) throw new Error("Video element is already attached");
|
|
1911
|
+
const a = { display: u };
|
|
1912
|
+
Y.set(n, a);
|
|
1913
|
+
const s = () => {
|
|
1914
|
+
u === "primary" && Se.has(u) && Nt();
|
|
1915
|
+
};
|
|
1916
|
+
n.addEventListener("loadeddata", s);
|
|
1917
|
+
const S = Se.get(u);
|
|
1918
|
+
S && ct(n, a, S);
|
|
1919
|
+
let m = !1;
|
|
1920
|
+
const p = () => {
|
|
1921
|
+
m || (m = !0, P.delete(p), n.removeEventListener("loadeddata", s), a.stop?.(), Y.delete(n), n.srcObject = null);
|
|
1922
|
+
};
|
|
1923
|
+
return P.add(p), p;
|
|
1924
|
+
};
|
|
1925
|
+
return {
|
|
1926
|
+
start: Dt,
|
|
1927
|
+
stop: _t,
|
|
1928
|
+
attachVideo: gt,
|
|
1929
|
+
attachFrameSink: (n, u = "primary") => {
|
|
1930
|
+
const a = document.createElement("video");
|
|
1931
|
+
a.muted = !0, a.playsInline = !0, a.autoplay = !0;
|
|
1932
|
+
const s = gt(a, u);
|
|
1933
|
+
let S = !1, m = 0, p = 0;
|
|
1934
|
+
const f = () => {
|
|
1935
|
+
a.cancelVideoFrameCallback?.(m), cancelAnimationFrame(p);
|
|
1936
|
+
}, $ = () => {
|
|
1937
|
+
S || !a.srcObject || (a.readyState >= 2 && a.videoWidth > 0 && L(
|
|
1938
|
+
"present",
|
|
1939
|
+
(...w) => n.present(...w),
|
|
1940
|
+
a,
|
|
1941
|
+
a.videoWidth,
|
|
1942
|
+
a.videoHeight,
|
|
1943
|
+
u
|
|
1944
|
+
), !(S || !a.srcObject) && (a.requestVideoFrameCallback ? m = a.requestVideoFrameCallback($) : p = requestAnimationFrame($)));
|
|
1945
|
+
}, k = () => {
|
|
1946
|
+
f(), $();
|
|
1947
|
+
};
|
|
1948
|
+
Y.get(a).clear = f, a.addEventListener("loadeddata", k);
|
|
1949
|
+
const X = () => {
|
|
1950
|
+
S || (S = !0, P.delete(X), f(), a.removeEventListener("loadeddata", k), s(), a.remove());
|
|
1951
|
+
};
|
|
1952
|
+
return P.delete(s), P.add(X), a.readyState >= 2 && k(), X;
|
|
1953
|
+
},
|
|
1954
|
+
dispose: () => {
|
|
1955
|
+
if (!j) {
|
|
1956
|
+
j = !0, _t();
|
|
1957
|
+
for (const n of P) n();
|
|
1958
|
+
P.clear();
|
|
1959
|
+
}
|
|
1960
|
+
},
|
|
1961
|
+
getState: () => h,
|
|
1962
|
+
updateOptions: (n) => {
|
|
1963
|
+
if (j) throw new Error("Device stream is disposed");
|
|
1964
|
+
const u = e;
|
|
1965
|
+
if (e = { ...e, ...n }, u.jitterBufferTargetMs !== e.jitterBufferTargetMs)
|
|
1966
|
+
for (const a of R?.getTransceivers() ?? [])
|
|
1967
|
+
(a.currentDirection === "recvonly" || a.currentDirection === "sendrecv") && vt(a.receiver, e.jitterBufferTargetMs);
|
|
1968
|
+
!!u.onPlaybackStats != !!e.onPlaybackStats && F(), !!u.microphoneEnabled != !!e.microphoneEnabled && (ze = e.microphoneEnabled ?? !1, et() ? tt() : Ve()), !!u.inspectMode != !!e.inspectMode && (e.inspectMode ? q?.start() : (q?.stop(), Ye !== null && We(null)));
|
|
1969
|
+
},
|
|
1970
|
+
sendControl: se,
|
|
1971
|
+
sendTouch: (n, u, a, s, S, m = 0) => se(
|
|
1972
|
+
Ht(
|
|
1973
|
+
n === "begin" ? 0 : n === "end" ? 1 : 2,
|
|
1974
|
+
m,
|
|
1975
|
+
s,
|
|
1976
|
+
S,
|
|
1977
|
+
u,
|
|
1978
|
+
a,
|
|
1979
|
+
n === "end" ? 0 : 1
|
|
1980
|
+
)
|
|
1981
|
+
),
|
|
1982
|
+
sendText: (n) => se(Gt(n)),
|
|
1983
|
+
sendDisplayTouch: (n, u, a, s) => se(jt(n, u, a, s)),
|
|
1984
|
+
sendDuoControl: be,
|
|
1985
|
+
pressButton: (n) => {
|
|
1986
|
+
if (l === "ios") {
|
|
1987
|
+
if (!h.controlReady || n === "back") return;
|
|
1988
|
+
const a = n === "power" ? "lock" : "home", s = [
|
|
1989
|
+
{ type: "buttonDown", button: a },
|
|
1990
|
+
{ type: "buttonUp", button: a }
|
|
1991
|
+
], S = n === "recents" ? [...s, { type: "wait", durationMs: 100 }, ...s] : s;
|
|
1992
|
+
be("performActions", { actions: S }).catch(
|
|
1993
|
+
(m) => console.warn("[DeviceStream] Button command failed:", m)
|
|
1994
|
+
);
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1997
|
+
const u = { home: 3, back: 4, recents: 187, power: 26 }[n];
|
|
1998
|
+
se(it(0, u, 0, 0)), se(it(1, u, 0, 0));
|
|
1999
|
+
},
|
|
2000
|
+
rotate: () => {
|
|
2001
|
+
if (l === "android") {
|
|
2002
|
+
se(new Uint8Array([11]).buffer);
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
if (!h.controlReady) return;
|
|
2006
|
+
if (h.duo) {
|
|
2007
|
+
(async () => {
|
|
2008
|
+
h.duoState || await ut();
|
|
2009
|
+
const p = h.duoState?.orientation;
|
|
2010
|
+
if (!p) throw new Error("Duo orientation unavailable");
|
|
2011
|
+
const f = ["portrait", "landscape-left", "pud", "landscape-right"], $ = f.indexOf(p);
|
|
2012
|
+
await be("setDuoOrientation", { orientation: f[($ + 1) % f.length] });
|
|
2013
|
+
})().catch((p) => console.warn("[DeviceStream] Rotation command failed:", p));
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
const n = [...Y].find(
|
|
2017
|
+
([m, p]) => p.display === "primary" && m.videoWidth > 0
|
|
2018
|
+
)?.[0], u = Se.get("primary")?.getVideoTracks()[0]?.getSettings(), a = n?.videoWidth ?? u?.width ?? 0, s = n?.videoHeight ?? u?.height ?? 0, S = a > s ? "Portrait" : "Landscape";
|
|
2019
|
+
be("performActions", { actions: [{ type: "setOrientation", orientation: S }] }).catch(
|
|
2020
|
+
(m) => console.warn("[DeviceStream] Rotation command failed:", m)
|
|
2021
|
+
);
|
|
2022
|
+
},
|
|
2023
|
+
bumpActivity: () => q?.bumpActivity(),
|
|
2024
|
+
getAxStatus: () => q?.getStatus() ?? "idle",
|
|
2025
|
+
openUrl: (n) => {
|
|
2026
|
+
if (!_ || _.readyState !== WebSocket.OPEN) {
|
|
2027
|
+
y("WebSocket not open, cannot send open_url command.");
|
|
2028
|
+
return;
|
|
2029
|
+
}
|
|
2030
|
+
try {
|
|
2031
|
+
const u = decodeURIComponent(n);
|
|
2032
|
+
T("Opening URL"), _.send(
|
|
2033
|
+
JSON.stringify({
|
|
2034
|
+
type: "openUrl",
|
|
2035
|
+
url: u,
|
|
2036
|
+
sessionId: d
|
|
2037
|
+
})
|
|
2038
|
+
);
|
|
2039
|
+
} catch (u) {
|
|
2040
|
+
y("Error decoding or sending URL :", { error: u, url: n }), _.send(
|
|
2041
|
+
JSON.stringify({
|
|
2042
|
+
type: "openUrl",
|
|
2043
|
+
url: n,
|
|
2044
|
+
sessionId: d
|
|
2045
|
+
})
|
|
2046
|
+
);
|
|
2047
|
+
}
|
|
2048
|
+
q?.bumpActivity();
|
|
2049
|
+
},
|
|
2050
|
+
sendKeyEvent: (n) => {
|
|
2051
|
+
if (!x || x.readyState !== "open") {
|
|
2052
|
+
y("Data channel not ready for imperative key command:", x?.readyState);
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
const u = Vt[n.code];
|
|
2056
|
+
if (!u) {
|
|
2057
|
+
y(`Unknown event.code for imperative command: ${n.code}`);
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
let a = o.META_NONE;
|
|
2061
|
+
n.shiftKey && (a |= o.META_SHIFT_ON), n.altKey && (a |= o.META_ALT_ON), n.ctrlKey && (a |= o.META_CTRL_ON), n.metaKey && (a |= o.META_META_ON);
|
|
2062
|
+
const s = n.type === "keydown" ? o.ACTION_DOWN : o.ACTION_UP;
|
|
2063
|
+
ce(
|
|
2064
|
+
`Sending Imperative Key Command: code=${n.code}, keycode=${u}, action=${s}, meta=${a}`
|
|
2065
|
+
);
|
|
2066
|
+
const S = it(
|
|
2067
|
+
s,
|
|
2068
|
+
u,
|
|
2069
|
+
0,
|
|
2070
|
+
// repeat count, typically 0 for single presses
|
|
2071
|
+
a
|
|
2072
|
+
);
|
|
2073
|
+
S && se(S);
|
|
2074
|
+
},
|
|
2075
|
+
screenshot: (n) => new Promise((u, a) => {
|
|
2076
|
+
if (!_ || _.readyState !== WebSocket.OPEN)
|
|
2077
|
+
return y("WebSocket not open, cannot send screenshot command."), a(new Error("WebSocket is not connected or connection is not open."));
|
|
2078
|
+
const s = `ui-ss-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, S = {
|
|
2079
|
+
type: n ? "screenshotDisplay" : "screenshot",
|
|
2080
|
+
...n ? { display: n } : {},
|
|
2081
|
+
id: s
|
|
2082
|
+
};
|
|
2083
|
+
re.set(s, u), ee.set(s, a), ce("Sending screenshot request:", S);
|
|
2084
|
+
try {
|
|
2085
|
+
_.send(JSON.stringify(S));
|
|
2086
|
+
} catch (m) {
|
|
2087
|
+
y("Failed to send screenshot request immediately:", m), re.delete(s), ee.delete(s), a(m);
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
B.set(
|
|
2091
|
+
s,
|
|
2092
|
+
setTimeout(() => {
|
|
2093
|
+
B.delete(s), re.has(s) && (y(`Screenshot request timed out for id ${s}`), ee.get(s)?.(new Error("Screenshot request timed out")), re.delete(s), ee.delete(s));
|
|
2094
|
+
}, 3e4)
|
|
2095
|
+
);
|
|
2096
|
+
}),
|
|
2097
|
+
terminateApp: (n) => new Promise((u, a) => {
|
|
2098
|
+
if (!_ || _.readyState !== WebSocket.OPEN)
|
|
2099
|
+
return y("WebSocket not open, cannot send terminateApp command."), a(new Error("WebSocket is not connected or connection is not open."));
|
|
2100
|
+
const s = `ui-term-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, S = {
|
|
2101
|
+
type: "terminateApp",
|
|
2102
|
+
id: s,
|
|
2103
|
+
bundleId: n
|
|
2104
|
+
};
|
|
2105
|
+
ae.set(s, u), ie.set(s, a), ce("Sending terminateApp request:", S);
|
|
2106
|
+
try {
|
|
2107
|
+
_.send(JSON.stringify(S));
|
|
2108
|
+
} catch (m) {
|
|
2109
|
+
y("Failed to send terminateApp request immediately:", m), ae.delete(s), ie.delete(s), a(m);
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
q?.bumpActivity(), B.set(
|
|
2113
|
+
s,
|
|
2114
|
+
setTimeout(() => {
|
|
2115
|
+
B.delete(s), ae.has(s) && (y(`terminateApp request timed out for id ${s}`), ie.get(s)?.(new Error("terminateApp request timed out")), ae.delete(s), ie.delete(s));
|
|
2116
|
+
}, 3e4)
|
|
2117
|
+
);
|
|
2118
|
+
}),
|
|
2119
|
+
reconnect: () => Dt(),
|
|
2120
|
+
refreshAxTree: async () => {
|
|
2121
|
+
const n = q;
|
|
2122
|
+
if (!n)
|
|
2123
|
+
throw new Error("Inspect mode is not active");
|
|
2124
|
+
return n.refresh();
|
|
2125
|
+
},
|
|
2126
|
+
getAxSnapshot: () => Ye
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
const bn = (t) => typeof t.message == "string" ? t.message : typeof t.error == "string" ? t.error : null, Rn = (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;
|
|
2130
|
+
export {
|
|
2131
|
+
ot as A,
|
|
2132
|
+
jt as B,
|
|
2133
|
+
Xe as C,
|
|
2134
|
+
Un as D,
|
|
2135
|
+
Bn as H,
|
|
2136
|
+
$n as a,
|
|
2137
|
+
Vn as b,
|
|
2138
|
+
Hn as c,
|
|
2139
|
+
on as d,
|
|
2140
|
+
an as e,
|
|
2141
|
+
qn as f,
|
|
2142
|
+
en as g,
|
|
2143
|
+
sn as h,
|
|
2144
|
+
An as i,
|
|
2145
|
+
Gn as j,
|
|
2146
|
+
ce as k,
|
|
2147
|
+
y as l,
|
|
2148
|
+
Gt as m,
|
|
2149
|
+
rn as n,
|
|
2150
|
+
it as o,
|
|
2151
|
+
o as p,
|
|
2152
|
+
Ht as q,
|
|
2153
|
+
Vt as r,
|
|
2154
|
+
L as s,
|
|
2155
|
+
Je as t,
|
|
2156
|
+
kn as u,
|
|
2157
|
+
Wn as v,
|
|
2158
|
+
xn as w,
|
|
2159
|
+
Pn as x,
|
|
2160
|
+
Fn as y,
|
|
2161
|
+
Ln as z
|
|
2162
|
+
};
|