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 23, 03:00 UTC
fix(mobile): load iOS device streams over HTTP on Android (#14284)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Adel Khial committed
Oct 19, 2026 at 06:29 UTC
2b5a87909883b1abd4732b68630eb6dcef789344
3 files changed
+36
-3
apps/mobile/src/features/devices/DeviceStreamWebView.tsx
+5
-2
@@ -16,6 +16,7 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
16
import { AppText } from "../../components/ui/AppText";
17
18
import {
19
+ deviceStreamBaseUrl,
20
deviceStreamDocument,
21
deviceStreamMessage,
22
type DeviceStreamConfiguration,
@@ -51,6 +52,7 @@ export function DeviceStreamWebView({
52
key={`${attempt}:${configuration}`}
53
ref={ref}
54
configuration={configuration}
55
+ baseUrl={deviceStreamBaseUrl(Platform.OS, props.platform, props.access.httpBase)}
56
background={props.colors.background}
57
onUnauthorized={props.onUnauthorized}
58
onInputConnected={props.onInputConnected}
@@ -76,6 +78,7 @@ export function DeviceStreamWebView({
78
function DeviceStreamDocumentView({
79
ref,
80
configuration,
81
+ baseUrl,
82
background,
83
onUnauthorized,
84
onInputConnected,
@@ -84,6 +87,7 @@ function DeviceStreamDocumentView({
87
onRecoverProcess,
88
}: NativeStreamBridge & {
89
readonly configuration: string;
90
+ readonly baseUrl: string;
91
readonly background: string;
92
readonly onRetry: () => void;
93
readonly onStreaming: () => void;
@@ -113,8 +117,7 @@ function DeviceStreamDocumentView({
117
}, [started]);
118
const source = {
119
html: deviceStreamDocument(configuration, deviceStreamScript),
116
- // Android WebCodecs needs a secure document; streams still use the environment's URLs.
117
- baseUrl: Platform.OS === "android" ? "https://localhost/" : "file:///",
120
+ baseUrl,
121
};
122
const command = (button: keyof DeviceStreamRef) => {
123
webView.current?.injectJavaScript(
apps/mobile/src/features/devices/device-stream-document.test.ts
+17
-1
@@ -1,9 +1,25 @@
1
import * as NodeVM from "node:vm";
2
import { describe, expect, it, vi } from "vite-plus/test";
3
4
-import { deviceStreamDocument, deviceStreamMessage } from "./device-stream-document";
4
+import {
5
+ deviceStreamBaseUrl,
6
+ deviceStreamDocument,
7
+ deviceStreamMessage,
8
+} from "./device-stream-document";
9
10
describe("native device stream document", () => {
11
+ it.each([
12
+ ["android", "ios", "http://192.168.1.10:3773/api/device-hub", "http://192.168.1.10:3773/"],
13
+ ["android", "ios", "https://env.example/t3/api/device-hub", "https://env.example/"],
14
+ ["android", "android", "http://192.168.1.10:3773/api/device-hub", "https://localhost/"],
15
+ ["ios", "ios", "http://192.168.1.10:3773/api/device-hub", "file:///"],
16
+ ] as const)(
17
+ "uses a %s viewer base URL for %s targets on %s",
18
+ (viewer, target, httpBase, expected) => {
19
+ expect(deviceStreamBaseUrl(viewer, target, httpBase)).toBe(expected);
20
+ },
21
+ );
22
+
23
it("keeps ticket and device values from terminating the embedded script", () => {
24
const deviceId = '</script><script>alert("device")</script>';
25
const configuration = JSON.stringify({ deviceId, ticket: "<ticket>" });
apps/mobile/src/features/devices/device-stream-document.ts
+14
@@ -1,5 +1,6 @@
1
import type { DeviceHubAccess } from "@t3tools/client-runtime/device/hub-access";
2
import type { DevicePlatform } from "@t3tools/contracts";
3
+import type { PlatformOSType } from "react-native";
4
5
export interface DeviceStreamConfiguration {
6
readonly access: DeviceHubAccess;
@@ -15,6 +16,19 @@ export interface DeviceStreamConfiguration {
16
};
17
}
18
19
+export function deviceStreamBaseUrl(
20
+ viewerPlatform: PlatformOSType,
21
+ devicePlatform: DevicePlatform,
22
+ httpBase: string,
23
+) {
24
+ if (viewerPlatform !== "android") return "file:///";
25
+ // Android targets stream through WebCodecs, which needs a secure context. iOS targets
26
+ // stream an MJPEG image from the environment, which a synthetic https document blocks as
27
+ // mixed content on plain-http environments even with mixedContentMode="always".
28
+ if (devicePlatform === "android") return "https://localhost/";
29
+ return `${new URL(httpBase).origin}/`;
30
+}
31
+
32
export function deviceStreamDocument(configuration: string, script: string) {
33
const safeConfiguration = configuration.replace(/</g, "\\u003c");
34
const safeScript = script.replace(/<\/script/gi, "<\\/script");