fix whep player

This commit is contained in:
2026-05-05 15:26:04 +07:00
parent 419e91523a
commit 16c35803a7
+11 -1
View File
@@ -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/<id>".
// 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;
}