clean URL WebRTC for liveview

This commit is contained in:
2026-04-28 22:39:20 +07:00
parent 185b75087d
commit 5e1f529ed7
+3 -2
View File
@@ -30,15 +30,16 @@ export async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
}
function normalizeLoopbackHost(rawUrl: string): string {
const cleaned = rawUrl.trim().replace(/^['"`\s]+|['"`\s]+$/g, "");
try {
const url = new URL(rawUrl, window.location.origin);
const url = new URL(cleaned, window.location.origin);
const loopbacks = new Set(["127.0.0.1", "localhost", "::1"]);
if (loopbacks.has(url.hostname) && !loopbacks.has(window.location.hostname)) {
url.hostname = window.location.hostname;
}
return url.toString().replace(/\/+$/, "");
} catch {
return rawUrl.replace(/\/+$/, "");
return cleaned.replace(/\/+$/, "");
}
}