@aixnn/aixautots 0.6.4 → 0.6.5

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.
Files changed (51) hide show
  1. package/dist/{automation-queue-BxrSIkG3.d.ts → automation-queue-aYRO9JLj.d.ts} +2 -2
  2. package/dist/chunk-7CN37G3W.js +102 -0
  3. package/dist/{chunk-JTFZSFFA.js → chunk-7H4CYM42.js} +414 -5
  4. package/dist/{chunk-M4DO7SSZ.js → chunk-D7J4EQTA.js} +1 -1
  5. package/dist/{chunk-B2BOVLI6.js → chunk-F76N3GOA.js} +1077 -313
  6. package/dist/{chunk-SAB5CH2K.js → chunk-FBWJUW4X.js} +578 -141
  7. package/dist/{chunk-T3QVYTOT.js → chunk-IFARWPMU.js} +364 -0
  8. package/dist/{chunk-UJO7BJUV.js → chunk-LMSN6Z3N.js} +668 -104
  9. package/dist/{chunk-Q63FQ7B5.js → chunk-LWTL4AIC.js} +254 -13
  10. package/dist/{chunk-YFF7VLNT.js → chunk-SKTL6ACT.js} +40 -2
  11. package/dist/{chunk-BYL2S2H6.js → chunk-X5KVYWUK.js} +4 -5
  12. package/dist/{chunk-NGW34POA.js → chunk-YWA47ARA.js} +318 -15
  13. package/dist/{config-CLi5IhmO.d.ts → config-B7t1Ln3w.d.ts} +177 -8
  14. package/dist/core/index.d.ts +21 -16
  15. package/dist/core/index.js +2 -4
  16. package/dist/{device-normalize-BaThgnH7.d.ts → device-normalize-CuGflfZA.d.ts} +1 -1
  17. package/dist/device-session-OFGN4KUD.js +1 -0
  18. package/dist/i18n/index.js +1 -1
  19. package/dist/{mirror-session-BP7Rd3Jk.d.ts → mirror-session-DK0OQvA3.d.ts} +11 -3
  20. package/dist/react/index.d.ts +10 -8
  21. package/dist/react/index.js +3 -6
  22. package/dist/{script-debugger-DtUGxK9i.d.ts → script-debugger-6hoLEwEz.d.ts} +1 -1
  23. package/dist/{task-agent-runner-DzV_OUZ7.d.ts → task-agent-runner-BwRW88rl.d.ts} +5 -3
  24. package/dist/{types-C2WXVcam.d.ts → types-BbtVr3QM.d.ts} +34 -3
  25. package/dist/ui/billing.d.ts +1 -1
  26. package/dist/ui/billing.js +5 -9
  27. package/dist/ui/device-create.d.ts +4 -3
  28. package/dist/ui/device-create.js +7 -9
  29. package/dist/ui/device-mirror.d.ts +16 -2
  30. package/dist/ui/device-mirror.js +6 -8
  31. package/dist/ui/devices.d.ts +5 -5
  32. package/dist/ui/devices.js +10 -13
  33. package/dist/ui/editor.d.ts +2 -2
  34. package/dist/ui/editor.js +7 -11
  35. package/dist/ui/index.d.ts +4 -4
  36. package/dist/ui/index.js +9 -15
  37. package/dist/ui/inspector.js +5 -9
  38. package/dist/ui/market.js +4 -7
  39. package/dist/ui/mirror.d.ts +3 -3
  40. package/dist/ui/primitives/index.d.ts +1 -1
  41. package/dist/ui/primitives/index.js +1 -2
  42. package/dist/ui/script-studio.js +6 -10
  43. package/dist/ui/scripts.d.ts +1 -1
  44. package/dist/ui/scripts.js +5 -9
  45. package/dist/ui/tasks.js +10 -13
  46. package/package.json +1 -1
  47. package/dist/chunk-A5VNENHD.js +0 -229
  48. package/dist/chunk-BUW45GM2.js +0 -341
  49. package/dist/chunk-H37NHOYU.js +0 -44
  50. package/dist/chunk-LAZ3RQ7X.js +0 -668
  51. package/dist/device-session-CVT7OY4H.js +0 -2
@@ -1,7 +1,7 @@
1
1
  import { MirrorView, ControlBar } from './chunk-E7WMHM63.js';
2
- import { useMirror, useDevices } from './chunk-Q63FQ7B5.js';
3
- import { Popover } from './chunk-H37NHOYU.js';
4
- import { useClient } from './chunk-A5VNENHD.js';
2
+ import { useAixT } from './chunk-IFARWPMU.js';
3
+ import { Popover, Button } from './chunk-SKTL6ACT.js';
4
+ import { useMirror, useClient, useDevices } from './chunk-LWTL4AIC.js';
5
5
  import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
6
6
  import { Check, Settings2, VolumeX, Volume2, RotateCw, Minimize2, Maximize2, X, Rocket, Loader2, Square, Video, Download } from 'lucide-react';
7
7
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -302,6 +302,298 @@ function DeviceBootSplash({ error, expectedMs = 3e3, platform = "android", class
302
302
  }
303
303
  );
304
304
  }
305
+
306
+ // src/ui/device-mirror/screenshot-request.ts
307
+ var pending = /* @__PURE__ */ new WeakMap();
308
+ function requestPreviewFrame(client, deviceId) {
309
+ const scope = client.cfg ?? client;
310
+ let devices = pending.get(scope);
311
+ if (!devices) {
312
+ devices = /* @__PURE__ */ new Map();
313
+ pending.set(scope, devices);
314
+ }
315
+ const existing = devices.get(deviceId);
316
+ if (existing) return existing;
317
+ const controller = new AbortController();
318
+ const timeout = setTimeout(() => controller.abort(), 2e4);
319
+ const request = Promise.resolve().then(() => client.devices.op(deviceId, { op: "screenshot", thumb: true }, { signal: controller.signal })).finally(() => {
320
+ clearTimeout(timeout);
321
+ if (devices.get(deviceId) === request) devices.delete(deviceId);
322
+ });
323
+ devices.set(deviceId, request);
324
+ return request;
325
+ }
326
+ function IosScreenshotPreview({ deviceId, onSize, videoAspect, className }) {
327
+ const client = useClient();
328
+ const t = useAixT();
329
+ const [running, setRunning] = useState(false);
330
+ const [visible, setVisible] = useState(() => typeof document === "undefined" || !document.hidden);
331
+ const [inView, setInView] = useState(true);
332
+ const [frame, setFrame] = useState(null);
333
+ const [busy, setBusy] = useState(false);
334
+ const [error, setError] = useState("");
335
+ const [now, setNow] = useState(Date.now());
336
+ const [refresh, setRefresh] = useState(0);
337
+ const consumedRefresh = useRef(0);
338
+ const element = useRef(null);
339
+ useEffect(() => {
340
+ const update = () => setVisible(!document.hidden);
341
+ document.addEventListener("visibilitychange", update);
342
+ const observer = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver((entries) => setInView(entries.some((e) => e.isIntersecting)));
343
+ if (element.current) observer?.observe(element.current);
344
+ return () => {
345
+ document.removeEventListener("visibilitychange", update);
346
+ observer?.disconnect();
347
+ };
348
+ }, []);
349
+ useEffect(() => {
350
+ if (!visible || !inView || !frame) return;
351
+ const timer = setInterval(() => setNow(Date.now()), 1e3);
352
+ return () => clearInterval(timer);
353
+ }, [visible, inView, !!frame]);
354
+ useEffect(() => {
355
+ if (!visible || !inView || !running && refresh === consumedRefresh.current) {
356
+ setBusy(false);
357
+ return;
358
+ }
359
+ consumedRefresh.current = refresh;
360
+ let active = true;
361
+ let timer;
362
+ const capture = async () => {
363
+ setBusy(true);
364
+ try {
365
+ const result = await requestPreviewFrame(client, deviceId);
366
+ if (!active) return;
367
+ const url = result.jpeg_base64 ? `data:image/jpeg;base64,${result.jpeg_base64}` : result.png_base64 ? `data:image/png;base64,${result.png_base64}` : null;
368
+ if (!url) throw new Error(t("preview.empty"));
369
+ const received = Date.now();
370
+ const capturedAt = result.captured_at ? Date.parse(result.captured_at) : NaN;
371
+ setFrame({ url, at: Number.isFinite(capturedAt) ? Math.min(received, capturedAt) : received, captured: Number.isFinite(capturedAt), source: result.source });
372
+ setNow(received);
373
+ setError("");
374
+ if (running) timer = setTimeout(() => void capture(), 1e3);
375
+ } catch (e) {
376
+ if (active) {
377
+ setError(e instanceof Error ? e.message : String(e));
378
+ setRunning(false);
379
+ }
380
+ } finally {
381
+ if (active) setBusy(false);
382
+ }
383
+ };
384
+ void capture();
385
+ return () => {
386
+ active = false;
387
+ clearTimeout(timer);
388
+ };
389
+ }, [client, deviceId, running, refresh, visible, inView]);
390
+ return /* @__PURE__ */ jsxs("div", { ref: element, className: `flex min-h-0 flex-1 flex-col gap-3 ${className ?? ""}`, children: [
391
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
392
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "min-h-11", onClick: () => {
393
+ setRefresh(0);
394
+ setRunning((value) => !value);
395
+ }, children: t(running ? "preview.stop" : "preview.start") }),
396
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "min-h-11", variant: "secondary", disabled: busy || running || !visible || !inView, onClick: () => setRefresh((value) => value + 1), children: t("preview.refresh") })
397
+ ] }),
398
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("preview.explanation") }),
399
+ /* @__PURE__ */ jsx("div", { "aria-busy": busy, className: "flex min-h-0 flex-1 items-center justify-center overflow-hidden rounded-md bg-secondary", style: videoAspect ? { aspectRatio: videoAspect } : { minHeight: 160 }, children: frame ? /* @__PURE__ */ jsx("img", { src: frame.url, alt: t("preview.image"), className: "max-h-full max-w-full object-contain", onLoad: (event) => {
400
+ const image = event.currentTarget;
401
+ if (image.naturalWidth && image.naturalHeight) onSize?.({ width: image.naturalWidth, height: image.naturalHeight });
402
+ }, onError: () => {
403
+ setError(t("preview.decodeFailed"));
404
+ setRunning(false);
405
+ } }) : /* @__PURE__ */ jsx("p", { className: "p-4 text-center text-sm text-muted-foreground", children: t(busy ? "preview.loading" : "preview.emptyState") }) }),
406
+ /* @__PURE__ */ jsxs("p", { role: "status", className: "text-xs text-muted-foreground", children: [
407
+ !visible || !inView ? t("preview.hidden") : busy ? t("preview.loading") : running ? t("preview.running") : t("preview.stopped"),
408
+ frame && ` \xB7 ${t(frame.captured ? "preview.age" : "preview.receivedAge", { seconds: Math.max(0, Math.floor((now - frame.at) / 1e3)) })}`,
409
+ frame?.source && ` \xB7 ${t("preview.source", { source: frame.source })}`
410
+ ] }),
411
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-sm text-destructive", children: t("preview.failed", { error }) })
412
+ ] });
413
+ }
414
+ function parseIosMediaCapabilities(value) {
415
+ if (!value || typeof value !== "object") return null;
416
+ const row = value;
417
+ if (row.webrtc_video !== true || typeof row.generation !== "string" || !row.generation.trim()) return null;
418
+ return {
419
+ webrtc_video: true,
420
+ generation: row.generation,
421
+ control: row.control === true,
422
+ audio: row.audio === true,
423
+ control_commands: Array.isArray(row.control_commands) ? row.control_commands.filter((v) => typeof v === "string") : []
424
+ };
425
+ }
426
+ function useIosMediaCapabilities(deviceId, supplied, visible) {
427
+ const client = useClient();
428
+ const [observed, setObserved] = useState(null);
429
+ useEffect(() => {
430
+ if (supplied !== void 0) return;
431
+ if (!visible) {
432
+ setObserved(null);
433
+ return;
434
+ }
435
+ let active = true;
436
+ let timer;
437
+ let controller;
438
+ const check = async () => {
439
+ controller = new AbortController();
440
+ const deadline = setTimeout(() => controller?.abort(), 15e3);
441
+ try {
442
+ const rows = await client.devices.list({ signal: controller.signal });
443
+ const device = rows.find((row) => row.external_id === deviceId || row.id === deviceId);
444
+ if (active) setObserved(device?.online === true ? parseIosMediaCapabilities(device.meta?.ios_media) : null);
445
+ } catch {
446
+ if (active) setObserved(null);
447
+ } finally {
448
+ clearTimeout(deadline);
449
+ if (active) timer = setTimeout(() => void check(), 1e4);
450
+ }
451
+ };
452
+ void check();
453
+ return () => {
454
+ active = false;
455
+ clearTimeout(timer);
456
+ controller?.abort();
457
+ };
458
+ }, [client, deviceId, supplied, visible]);
459
+ return supplied === void 0 ? observed : parseIosMediaCapabilities(supplied);
460
+ }
461
+ function IosMediaSurface(props) {
462
+ const t = useAixT();
463
+ const [mode, setMode] = useState(props.iosMedia === "screenshot" ? "screenshot" : "video");
464
+ const [visible, setVisible] = useState(() => typeof document === "undefined" || !document.hidden);
465
+ const [inView, setInView] = useState(true);
466
+ const [failure, setFailure] = useState(null);
467
+ const [attempt, setAttempt] = useState(0);
468
+ const container = useRef(null);
469
+ const caps = useIosMediaCapabilities(props.deviceId, props.iosMediaCapabilities, visible && inView);
470
+ useEffect(() => {
471
+ setMode(props.iosMedia === "screenshot" ? "screenshot" : "video");
472
+ }, [props.iosMedia]);
473
+ useEffect(() => {
474
+ const update = () => setVisible(!document.hidden);
475
+ document.addEventListener("visibilitychange", update);
476
+ const observer = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver((entries) => setInView(entries.some((e) => e.isIntersecting)));
477
+ if (container.current) observer?.observe(container.current);
478
+ return () => {
479
+ document.removeEventListener("visibilitychange", update);
480
+ observer?.disconnect();
481
+ };
482
+ }, []);
483
+ const video = mode === "video" && caps && failure?.generation !== caps.generation;
484
+ const fail = useCallback((reason) => {
485
+ if (caps) setFailure({ generation: caps.generation, reason });
486
+ }, [caps?.generation]);
487
+ return /* @__PURE__ */ jsxs("div", { ref: container, className: `flex min-h-0 flex-1 flex-col gap-2 ${props.className ?? ""}`, children: [
488
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", role: "group", "aria-label": t("iosVideo.mode"), children: [
489
+ /* @__PURE__ */ jsx(
490
+ Button,
491
+ {
492
+ size: "sm",
493
+ className: "min-h-11",
494
+ variant: video ? "primary" : "secondary",
495
+ disabled: !caps,
496
+ "aria-pressed": !!video,
497
+ onClick: () => {
498
+ setMode("video");
499
+ setFailure(null);
500
+ setAttempt((value) => value + 1);
501
+ },
502
+ children: t(failure && caps && failure.generation === caps.generation ? "iosVideo.retry" : "iosVideo.video")
503
+ }
504
+ ),
505
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "min-h-11", variant: !video ? "primary" : "secondary", "aria-pressed": !video, onClick: () => setMode("screenshot"), children: t("iosVideo.screenshot") })
506
+ ] }),
507
+ video ? visible && inView ? /* @__PURE__ */ jsx(IosVideoViewer, { ...props, caps, onFailure: fail }, `${props.deviceId}:${caps.generation}:${attempt}`) : /* @__PURE__ */ jsx("p", { role: "status", className: "text-sm text-muted-foreground", children: t("iosVideo.hidden") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
508
+ /* @__PURE__ */ jsx("p", { role: "status", className: "text-xs text-muted-foreground", children: failure && caps && failure.generation === caps.generation ? t("iosVideo.fallback", { reason: t(`iosVideo.reason.${failure.reason}`) }) : !caps ? t("iosVideo.unavailable") : t("iosVideo.selectedScreenshot") }),
509
+ /* @__PURE__ */ jsx(IosScreenshotPreview, { ...props })
510
+ ] })
511
+ ] });
512
+ }
513
+ var IOS_KEYS = /* @__PURE__ */ new Set(["enter", "backspace", "delete", "tab", "escape", "up", "down", "left", "right", "space", "home"]);
514
+ var IOS_COMMANDS = /* @__PURE__ */ new Set(["tap", "swipe", "text", "home", "key"]);
515
+ function IosVideoViewer({ deviceId, onSize, videoAspect, caps, onFailure }) {
516
+ const t = useAixT();
517
+ const { stream, error, connectionState, controlReady, session } = useMirror(deviceId);
518
+ const [size, setSize] = useState({ width: 1080, height: 2340 });
519
+ const [hasFrame, setHasFrame] = useState(false);
520
+ const [text, setText] = useState("");
521
+ const [inputError, setInputError] = useState(false);
522
+ const failureRef = useRef(onFailure);
523
+ failureRef.current = onFailure;
524
+ useEffect(() => {
525
+ setHasFrame(false);
526
+ }, [stream]);
527
+ useEffect(() => {
528
+ if (hasFrame) return;
529
+ const timeout = setTimeout(() => failureRef.current("first_frame_timeout"), 2e4);
530
+ return () => clearTimeout(timeout);
531
+ }, [hasFrame]);
532
+ useEffect(() => {
533
+ if (error) failureRef.current("connection_error");
534
+ else if (["disconnected", "failed", "closed"].includes(connectionState)) failureRef.current("connection_lost");
535
+ }, [error, connectionState]);
536
+ useEffect(() => {
537
+ const tracks = stream?.getVideoTracks() ?? [];
538
+ const ended = () => failureRef.current("video_ended");
539
+ if (tracks.some((track) => track.readyState === "ended")) ended();
540
+ tracks.forEach((track) => track.addEventListener?.("ended", ended));
541
+ return () => tracks.forEach((track) => track.removeEventListener?.("ended", ended));
542
+ }, [stream]);
543
+ const canControl = hasFrame && caps.control && caps.control_commands.some((command) => IOS_COMMANDS.has(command)) && controlReady && connectionState === "connected";
544
+ const input = useCallback((message) => {
545
+ if (!canControl || !session?.controlReady || !IOS_COMMANDS.has(message.t) || !caps.control_commands.includes(message.t)) return;
546
+ if (message.t === "key" && !IOS_KEYS.has(message.code)) return;
547
+ try {
548
+ session.sendInput(message);
549
+ setInputError(false);
550
+ } catch {
551
+ setInputError(true);
552
+ }
553
+ }, [canControl, session, caps.control_commands]);
554
+ const report = (value) => {
555
+ setSize(value);
556
+ onSize?.(value);
557
+ };
558
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
559
+ /* @__PURE__ */ jsxs("p", { role: "status", className: "text-xs text-muted-foreground", children: [
560
+ t(!hasFrame ? "iosVideo.connecting" : canControl ? "iosVideo.controlReady" : "iosVideo.readOnly"),
561
+ " \xB7 ",
562
+ t("iosVideo.silent")
563
+ ] }),
564
+ /* @__PURE__ */ jsxs("div", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden rounded-md bg-secondary", style: videoAspect ? { aspectRatio: videoAspect } : { minHeight: 160 }, children: [
565
+ /* @__PURE__ */ jsx(
566
+ MirrorView,
567
+ {
568
+ stream,
569
+ deviceSize: size,
570
+ onInput: canControl ? input : void 0,
571
+ keyboard: canControl && (caps.control_commands.includes("key") || caps.control_commands.includes("text")),
572
+ autoFocus: false,
573
+ continuousTouch: false,
574
+ volume: 0,
575
+ onFirstFrame: (value) => {
576
+ report(value);
577
+ setHasFrame(true);
578
+ },
579
+ onResize: report,
580
+ className: "h-full w-full"
581
+ },
582
+ canControl ? "control" : "view"
583
+ ),
584
+ !hasFrame && /* @__PURE__ */ jsx("p", { className: "pointer-events-none absolute inset-0 flex items-center justify-center p-4 text-center text-sm text-muted-foreground", children: t("iosVideo.connecting") })
585
+ ] }),
586
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
587
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "min-h-11", disabled: !canControl || !caps.control_commands.includes("home"), onClick: () => input({ t: "home" }), children: "Home" }),
588
+ /* @__PURE__ */ jsxs("label", { className: "flex min-w-0 flex-1 items-center gap-2 text-xs", children: [
589
+ t("iosVideo.text"),
590
+ /* @__PURE__ */ jsx("input", { className: "min-h-11 min-w-0 flex-1 rounded border border-border bg-background px-2 text-sm", value: text, disabled: !canControl || !caps.control_commands.includes("text"), onChange: (event) => setText(event.target.value) })
591
+ ] }),
592
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "min-h-11", disabled: !canControl || !caps.control_commands.includes("text") || !text, onClick: () => input({ t: "text", value: text }), children: t("iosVideo.send") })
593
+ ] }),
594
+ inputError && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-sm text-destructive", children: t("iosVideo.inputUnknown") })
595
+ ] });
596
+ }
305
597
  function useClipboardSync(deviceId, active) {
306
598
  const client = useClient();
307
599
  const [error, setError] = useState(null);
@@ -314,7 +606,7 @@ function useClipboardSync(deviceId, active) {
314
606
  if (!active) return;
315
607
  let stopped = false;
316
608
  let busy = false;
317
- let pending = false;
609
+ let pending2 = false;
318
610
  let generation = 0;
319
611
  let preferred;
320
612
  let copyVersion = 0;
@@ -325,7 +617,7 @@ function useClipboardSync(deviceId, active) {
325
617
  const visible = () => !stopped && document.hasFocus() && document.visibilityState !== "hidden";
326
618
  const poll = async () => {
327
619
  if (busy) {
328
- pending = true;
620
+ pending2 = true;
329
621
  return;
330
622
  }
331
623
  busy = true;
@@ -343,7 +635,7 @@ function useClipboardSync(deviceId, active) {
343
635
  if (!visible() || version !== generation) return;
344
636
  const latest = await navigator.clipboard.readText();
345
637
  if (!visible() || version !== generation || latest !== host) {
346
- pending = true;
638
+ pending2 = true;
347
639
  return;
348
640
  }
349
641
  if (local === void 0 || remote === void 0) {
@@ -385,8 +677,8 @@ function useClipboardSync(deviceId, active) {
385
677
  } finally {
386
678
  busy = false;
387
679
  if (!stopped) {
388
- timer = setTimeout(poll, pending ? 0 : 700);
389
- pending = false;
680
+ timer = setTimeout(poll, pending2 ? 0 : 700);
681
+ pending2 = false;
390
682
  }
391
683
  }
392
684
  };
@@ -449,7 +741,11 @@ var DEFAULT_SIZE = { width: 1080, height: 2340 };
449
741
  var AUTO_QUALITY_FIRST_CHECK_MS = 2e3;
450
742
  var AUTO_QUALITY_INTERVAL_MS = 8e3;
451
743
  var AUTO_QUALITY_MIN_SWITCH_INTERVAL_MS = 15e3;
452
- function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, shortcutBar, className }) {
744
+ function MirrorSurface(props) {
745
+ if (props.platform === "ios") return /* @__PURE__ */ jsx(IosMediaSurface, { ...props }, props.deviceId);
746
+ return /* @__PURE__ */ jsx(WebRtcMirrorSurface, { ...props });
747
+ }
748
+ function WebRtcMirrorSurface({ deviceId, platform = "android", onSize, videoAspect, shortcutBar, className }) {
453
749
  const { stream, error, sendInput, setQuality, session } = useMirror(deviceId);
454
750
  const [pasteContent, setPasteContent] = useState("");
455
751
  const { error: clipboardError, conflict: clipboardConflict, resolveConflict } = useClipboardSync(deviceId, !!stream);
@@ -457,7 +753,6 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
457
753
  const [hasFrame, setHasFrame] = useState(false);
458
754
  useEffect(() => {
459
755
  setHasFrame(false);
460
- setVolume(0);
461
756
  }, [deviceId, stream]);
462
757
  useEffect(() => {
463
758
  setPasteContent("");
@@ -476,11 +771,21 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
476
771
  );
477
772
  const landscape = size.width > size.height;
478
773
  const [volume, setVolume] = useState(0);
774
+ const audioEnabled = volume > 0;
479
775
  const audioEnabledRef = useRef(false);
776
+ useEffect(() => {
777
+ if (stream && audioEnabled) {
778
+ sendInput({ t: "audio", enabled: true });
779
+ audioEnabledRef.current = true;
780
+ } else if (!audioEnabled && audioEnabledRef.current) {
781
+ sendInput({ t: "audio", enabled: false });
782
+ audioEnabledRef.current = false;
783
+ }
784
+ }, [stream, audioEnabled, sendInput]);
480
785
  useEffect(() => () => {
481
786
  if (audioEnabledRef.current) sendInput({ t: "audio", enabled: false });
482
787
  audioEnabledRef.current = false;
483
- }, [stream, sendInput]);
788
+ }, [sendInput]);
484
789
  const [hasAudio, setHasAudio] = useState(false);
485
790
  useEffect(() => {
486
791
  const update = () => setHasAudio(!!stream?.getAudioTracks().some((t) => t.readyState === "live"));
@@ -605,7 +910,7 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
605
910
  ControlBar,
606
911
  {
607
912
  platform,
608
- onBack: () => sendInput({ t: "back" }),
913
+ onBack: platform === "android" ? () => sendInput({ t: "back" }) : void 0,
609
914
  onHome: () => sendInput({ t: "home" }),
610
915
  onMenu: () => sendInput({ t: "key", code: "app_switch" })
611
916
  }
@@ -668,8 +973,6 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
668
973
  disabled: !stream,
669
974
  onChange: (e) => {
670
975
  const next = Number(e.target.value);
671
- if (audioEnabledRef.current !== next > 0) sendInput({ t: "audio", enabled: next > 0 });
672
- audioEnabledRef.current = next > 0;
673
976
  setVolume(next);
674
977
  }
675
978
  }
@@ -842,4 +1145,4 @@ function DeviceMirror({ deviceId, deviceName, platform = "android", shortcutBar,
842
1145
  );
843
1146
  }
844
1147
 
845
- export { DeviceBootSplash, DeviceMirror, MirrorSurface };
1148
+ export { DeviceBootSplash, DeviceMirror, MirrorSurface, parseIosMediaCapabilities, requestPreviewFrame };