fix wheplayer
This commit is contained in:
+16
-3
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user