@devries-cameron20 / t3code Mirror · read-only / commits / b28bb8fc9d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 04:30 UTC

fix(mobile): use H.264 for iOS previews and keep Close reachable (#28622)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 5, 2026 at 06:45 UTC b28bb8fc9d582ca7cc95aebb9fd6ceb24cc28884
4 files changed +140 -32
apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
+14 -11
@@ -88,7 +88,7 @@ export function DevicePreviewScreen({
88 }) {
89 const embedded = onMaximize !== undefined;
90 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.
92 const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
93 const { themeVariables } = useAppearancePreferences();
94 const focused = useIsFocused();
@@ -106,7 +106,7 @@ export function DevicePreviewScreen({
106 const preview = selectedThreadDevicePreview(previews, selectedKey);
107 const onInputConnected = async (connected: boolean) => {
108 setInputConnected(connected);
109 - if (connected && !embedded) setControlsVisible(false);
109 + if (!connected) setControlsVisible(true);
110 };
111 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- closes the focused route through the navigator once the thread has no device previews
112 useEffect(() => {
@@ -348,20 +348,23 @@ export function DevicePreviewScreen({
348 </View>
349 </Animated.View>
350 ) : (
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"
354 style={{
355 top: Math.max(insets.top, 12),
356 transform: [{ translateX: (handleBounds.left - handleBounds.right) / 2 }],
357 }}
361 - onPress={() => setControlsVisible(true)}
358 >
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>
368 )}
369 </View>
370 );
apps/mobile/src/features/devices/device-stream.browser.test.ts new
+108
@@ -0,0 +1,108 @@
1 +import { 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 + it.each([
86 + { supported: true, image: "" },
87 + { supported: false, image: "/api/device-hub/vendor/serve-sim/helper/sim/stream.mjpeg" },
88 + ])(
89 + "streams H.264 when WebCodecs decodes it, else MJPEG (supported: $supported)",
90 + async ({ supported, image }) => {
91 + try {
92 + const { configured, requested, videoBodies } = viewerFixture(supported);
93 + await vi.advanceTimersByTimeAsync(0);
94 + expect(requested).toContain("/api/device-hub/vendor/serve-sim/helper/sim/stream.avcc");
95 + videoBodies[0]!.enqueue(new Uint8Array(envelope(1, [1, 0x64, 0x00, 0x33])));
96 + await vi.advanceTimersByTimeAsync(0);
97 + expect(configured).toEqual(supported ? ["avc1.640033"] : []);
98 + const img = document.querySelector("img")!;
99 + expect(img.src && new URL(img.src).pathname).toBe(image);
100 + expect(img.style.display).toBe(supported ? "none" : "block");
101 + } finally {
102 + stop();
103 + vi.useRealTimers();
104 + vi.unstubAllGlobals();
105 + }
106 + },
107 + );
108 +});
apps/mobile/src/features/devices/device-stream.browser.ts
+17 -21
@@ -130,28 +130,24 @@ export function start(configuration: DeviceStreamConfiguration) {
130 const unauthorized = () => {
131 if (activeClient === client) post({ type: "unauthorized" });
132 };
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";
139 },
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 + });
151 activeClient = client;
152 client.setMjpegImage(image);
153 const touch = (event: PointerEvent, phase: "begin" | "move" | "end") => {
apps/mobile/vite.config.ts
+1
@@ -43,6 +43,7 @@ const reactTests = [
43 "src/features/home/home-list-options.test.tsx",
44 "src/features/workspace/useSearchScrollRestoration.test.tsx",
45 "src/features/connection/ConnectionsNewRouteScreen.test.tsx",
46 + "src/features/devices/device-stream.browser.test.ts",
47 ];
48
49 const sourceRoot = `${normalizePath(NodeURL.fileURLToPath(new URL("./src", import.meta.url)))}/`;