fix wheplayer

This commit is contained in:
2026-04-28 17:24:26 +07:00
parent ecd9845e14
commit 8ad28090eb
5 changed files with 121 additions and 21 deletions
+16 -3
View File
@@ -29,8 +29,21 @@ export async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
return (await res.json()) as T;
}
export function getMediamtxWebrtcBaseUrl(configUrl?: string) {
const env = import.meta.env.VITE_MEDIAMTX_WEBRTC_URL as string | undefined;
return env ?? configUrl ?? "http://localhost:8889";
function normalizeLoopbackHost(rawUrl: string): string {
try {
const url = new URL(rawUrl, 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(/\/+$/, "");
}
}
export function getMediamtxWebrtcBaseUrl(configUrl?: string) {
const env = import.meta.env.VITE_MEDIAMTX_WEBRTC_URL as string | undefined;
return normalizeLoopbackHost(env ?? configUrl ?? "http://localhost:8889");
}