diff --git a/src/hooks/useWhepPlayer.ts b/src/hooks/useWhepPlayer.ts index dfd4841..7ca5c4d 100644 --- a/src/hooks/useWhepPlayer.ts +++ b/src/hooks/useWhepPlayer.ts @@ -157,7 +157,17 @@ export function useWhepPlayer({ const location = res.headers.get("location") || res.headers.get("Location"); if (location) { try { - sessionUrlRef.current = new URL(location, whepUrl).toString(); + const baseUrl = new URL(whepUrl); + if (location.startsWith("/")) { + // MediaMTX can return absolute paths like "/cam1/whep/". + // If WHEP is behind a prefix (e.g. "/mtx"), preserve that prefix for DELETE. + const parts = baseUrl.pathname.split("/").filter(Boolean); + const prefix = parts.slice(0, -2).join("/"); + const normalized = prefix ? `/${prefix}${location}` : location; + sessionUrlRef.current = new URL(normalized, baseUrl.origin).toString(); + } else { + sessionUrlRef.current = new URL(location, whepUrl).toString(); + } } catch { sessionUrlRef.current = location; }