Skip to content

Commit 43edc9a

Browse files
PR Batch Testerclaude
andcommitted
fix(mobile): stream iOS simulators as H.264 and keep Close reachable
The mobile viewer forced MJPEG for every iOS simulator, even when the WebView can decode serve-sim's H.264 stream. It now uses the shared client's WebCodecs check and keeps the existing MJPEG fallback. The fullscreen preview no longer hides its controls when input connects, shows them again when input drops, and replaces the tap-only grabber with a pill that holds Close and a Show controls button. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0bc95fc commit 43edc9a

4 files changed

Lines changed: 140 additions & 32 deletions

File tree

‎apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function DevicePreviewScreen({
8888
}) {
8989
const embedded = onMaximize !== undefined;
9090
const insets = useSafeAreaInsets();
91-
// NativeColumnContent already insets the sides, so only a book fold moves the reveal handle.
91+
// NativeColumnContent already insets the sides, so only a book fold moves the hidden-controls pill.
9292
const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
9393
const { themeVariables } = useAppearancePreferences();
9494
const focused = useIsFocused();
@@ -106,7 +106,7 @@ export function DevicePreviewScreen({
106106
const preview = selectedThreadDevicePreview(previews, selectedKey);
107107
const onInputConnected = async (connected: boolean) => {
108108
setInputConnected(connected);
109-
if (connected && !embedded) setControlsVisible(false);
109+
if (!connected) setControlsVisible(true);
110110
};
111111
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- closes the focused route through the navigator once the thread has no device previews
112112
useEffect(() => {
@@ -348,20 +348,23 @@ export function DevicePreviewScreen({
348348
</View>
349349
</Animated.View>
350350
) : (
351-
<Pressable
352-
accessibilityRole="button"
353-
accessibilityLabel="Show device controls"
354-
accessibilityHint="Shaking the phone also shows them"
355-
hitSlop={12}
356-
className="absolute h-11 w-16 items-center justify-center self-center"
351+
<View
352+
pointerEvents="box-none"
353+
className="absolute self-center"
357354
style={{
358355
top: Math.max(insets.top, 12),
359356
transform: [{ translateX: (handleBounds.left - handleBounds.right) / 2 }],
360357
}}
361-
onPress={() => setControlsVisible(true)}
362358
>
363-
<View className="h-1.5 w-10 rounded-full bg-white/40" />
364-
</Pressable>
359+
<GlassSurface className="flex-row items-center gap-1 p-1">
360+
<SheetCloseButton accessibilityLabel="Close device preview" onClose={onClose} />
361+
<ControlPill
362+
accessibilityLabel="Show device controls"
363+
icon="chevron.down"
364+
onPress={() => setControlsVisible(true)}
365+
/>
366+
</GlassSurface>
367+
</View>
365368
)}
366369
</View>
367370
);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
2+
3+
import { start, stop } from "./device-stream.browser";
4+
5+
const envelope = (tag: number, payload: number[]) => {
6+
const length = 1 + payload.length;
7+
return [
8+
length >>> 24,
9+
(length >>> 16) & 0xff,
10+
(length >>> 8) & 0xff,
11+
length & 0xff,
12+
tag,
13+
...payload,
14+
];
15+
};
16+
17+
function viewerFixture(supported: boolean) {
18+
vi.useFakeTimers();
19+
const configured: string[] = [];
20+
vi.stubGlobal(
21+
"VideoDecoder",
22+
class {
23+
static isConfigSupported = async () => ({ supported });
24+
state = "unconfigured";
25+
decodeQueueSize = 0;
26+
configure(config: VideoDecoderConfig) {
27+
configured.push(config.codec);
28+
this.state = "configured";
29+
}
30+
decode() {}
31+
close() {
32+
this.state = "closed";
33+
}
34+
},
35+
);
36+
vi.stubGlobal("EncodedVideoChunk", vi.fn());
37+
vi.stubGlobal(
38+
"WebSocket",
39+
class {
40+
static OPEN = 1;
41+
readyState = 0;
42+
send() {}
43+
close() {}
44+
},
45+
);
46+
const videoBodies: ReadableStreamDefaultController<Uint8Array>[] = [];
47+
const requested: string[] = [];
48+
vi.stubGlobal("fetch", (url: string, init: RequestInit) => {
49+
requested.push(new URL(url).pathname);
50+
if (!url.includes("stream.avcc")) return Promise.resolve(new Response(null));
51+
return Promise.resolve(
52+
new Response(
53+
new ReadableStream<Uint8Array>({
54+
start(body) {
55+
videoBodies.push(body);
56+
init.signal?.addEventListener("abort", () => body.error(new Error("aborted")));
57+
},
58+
}),
59+
),
60+
);
61+
});
62+
vi.stubGlobal("ReactNativeWebView", { postMessage() {} });
63+
start({
64+
platform: "ios",
65+
deviceId: "sim",
66+
access: {
67+
httpBase: "https://environment.test/api/device-hub",
68+
wsBase: "wss://environment.test/api/device-hub",
69+
credentials: false,
70+
query: {},
71+
},
72+
colors: {
73+
background: "black",
74+
foreground: "white",
75+
muted: "gray",
76+
buttonBackground: "black",
77+
buttonForeground: "white",
78+
buttonBorder: "gray",
79+
},
80+
});
81+
return { configured, requested, videoBodies };
82+
}
83+
84+
describe("native iOS simulator viewer", () => {
85+
afterEach(() => {
86+
stop();
87+
vi.useRealTimers();
88+
vi.unstubAllGlobals();
89+
});
90+
91+
it.each([
92+
{ supported: true, image: "" },
93+
{ supported: false, image: "/api/device-hub/vendor/serve-sim/helper/sim/stream.mjpeg" },
94+
])(
95+
"streams H.264 when WebCodecs decodes it, else MJPEG (supported: $supported)",
96+
async ({ supported, image }) => {
97+
const { configured, requested, videoBodies } = viewerFixture(supported);
98+
await vi.advanceTimersByTimeAsync(0);
99+
expect(requested).toContain("/api/device-hub/vendor/serve-sim/helper/sim/stream.avcc");
100+
videoBodies[0]!.enqueue(new Uint8Array(envelope(1, [1, 0x64, 0x00, 0x33])));
101+
await vi.advanceTimersByTimeAsync(0);
102+
expect(configured).toEqual(supported ? ["avc1.640033"] : []);
103+
const img = document.querySelector("img")!;
104+
expect(img.src && new URL(img.src).pathname).toBe(image);
105+
expect(img.style.display).toBe(supported ? "none" : "block");
106+
},
107+
);
108+
});

‎apps/mobile/src/features/devices/device-stream.browser.ts‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,24 @@ export function start(configuration: DeviceStreamConfiguration) {
130130
const unauthorized = () => {
131131
if (activeClient === client) post({ type: "unauthorized" });
132132
};
133-
const client = createDeviceStreamClient(
134-
{ ...configuration, preferMjpeg: platform === "ios" },
135-
canvas,
136-
{
137-
onStatus: reportStatus,
138-
onScreen: layout,
139-
onMjpegFallback: () => {
140-
canvas.style.display = "none";
141-
image.style.display = "block";
142-
},
143-
onCanvasVideo: () => {
144-
image.style.display = "none";
145-
canvas.style.display = "";
146-
},
147-
onUnauthorized: unauthorized,
148-
onInputConnected: (connected) => {
149-
inputConnected = connected;
150-
inputStatus.style.display = streaming && !connected ? "block" : "none";
151-
post({ type: "input", connected });
152-
},
133+
const client = createDeviceStreamClient(configuration, canvas, {
134+
onStatus: reportStatus,
135+
onScreen: layout,
136+
onMjpegFallback: () => {
137+
canvas.style.display = "none";
138+
image.style.display = "block";
153139
},
154-
);
140+
onCanvasVideo: () => {
141+
image.style.display = "none";
142+
canvas.style.display = "";
143+
},
144+
onUnauthorized: unauthorized,
145+
onInputConnected: (connected) => {
146+
inputConnected = connected;
147+
inputStatus.style.display = streaming && !connected ? "block" : "none";
148+
post({ type: "input", connected });
149+
},
150+
});
155151
activeClient = client;
156152
client.setMjpegImage(image);
157153
const touch = (event: PointerEvent, phase: "begin" | "move" | "end") => {

‎apps/mobile/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const reactTests = [
3939
"src/features/home/home-list-options.test.tsx",
4040
"src/features/workspace/useSearchScrollRestoration.test.tsx",
4141
"src/features/connection/ConnectionsNewRouteScreen.test.tsx",
42+
"src/features/devices/device-stream.browser.test.ts",
4243
];
4344

4445
const sourceRoot = `${normalizePath(NodeURL.fileURLToPath(new URL("./src", import.meta.url)))}/`;

0 commit comments

Comments
 (0)