This commit is contained in:
eric
2026-03-29 03:08:07 -05:00
parent fbdcf4cc73
commit 895dafc0e0
2 changed files with 39 additions and 6 deletions

View File

@@ -142,6 +142,13 @@ type Props = {
const SCRCPY_URL = "https://github.com/Genymobile/scrcpy";
const ESCRCPY_URL = "https://github.com/viarotel-org/escrcpy";
/** 与 LiveControlApp 一致apiBase 为空时用根相对路径(同域 FastAPI 托管静态页)。 */
function apiUrl(apiBase: string, path: string): string {
const p = path.startsWith("/") ? path : `/${path}`;
const b = (apiBase || "").trim().replace(/\/$/, "");
return b ? `${b}${p}` : p;
}
export function LiveAndroidStreamConsole({
t,
apiBase,
@@ -188,10 +195,9 @@ export function LiveAndroidStreamConsole({
const activeTransport = devices.find((d) => d.serial === serial)?.transport;
const useFastShot = liveMs > 0;
const shotUrl =
apiBase && serial
? `${apiBase}/android/screenshot?serial=${encodeURIComponent(serial)}&ts=${frameTs}${useFastShot ? "&fast=1" : ""}`
: "";
const shotUrl = serial
? `${apiUrl(apiBase, "/android/screenshot")}?serial=${encodeURIComponent(serial)}&ts=${frameTs}${useFastShot ? "&fast=1" : ""}`
: "";
const bumpFrame = useCallback(() => {
setFrameTs((n) => n + 1);
@@ -230,7 +236,9 @@ export function LiveAndroidStreamConsole({
let cancelled = false;
void (async () => {
try {
const res = await fetch(`${apiBase}/android/display_metrics?serial=${encodeURIComponent(serial)}`);
const res = await fetch(
`${apiUrl(apiBase, "/android/display_metrics")}?serial=${encodeURIComponent(serial)}`,
);
const data = (await res.json()) as { width?: number; height?: number };
if (!res.ok || cancelled) return;
if (typeof data.width === "number" && typeof data.height === "number") {
@@ -259,7 +267,7 @@ export function LiveAndroidStreamConsole({
let cancelled = false;
void (async () => {
try {
const res = await fetch(`${apiBase}/android/scrcpy/info`);
const res = await fetch(apiUrl(apiBase, "/android/scrcpy/info"));
const data = (await res.json()) as {
server_jar?: boolean;
adb_ok?: boolean;