From 16c35803a7ff3ca55e735a1cfe2835bae39ac3b0 Mon Sep 17 00:00:00 2001 From: Tony Tran Date: Tue, 5 May 2026 15:26:04 +0700 Subject: [PATCH] fix whep player --- src/hooks/useWhepPlayer.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; }