diff --git a/src/components/WebRtcPlayer.astro b/src/components/WebRtcPlayer.astro index 139591f..a301f68 100644 --- a/src/components/WebRtcPlayer.astro +++ b/src/components/WebRtcPlayer.astro @@ -199,7 +199,11 @@ const id = `${Math.random().toString(36).slice(2)}`; msg: `Something went wrong with stream!`, }); - throw new Error("WHEP POST failed: " + res.status); + throw new Error( + res.status == 404 + ? "No Stream Found!" + : `Something went wrong with stream!`, + ); } const answerSdp = await res.text(); @@ -271,10 +275,6 @@ const id = `${Math.random().toString(36).slice(2)}`; const player = createWhepPlayer(streamUrl, videoEl, { iceServers: iceServers, onEvent: (type, payload) => { - console.log("[whep] event"); - console.log("[whep] Type", type); - console.log("[whep] payload", payload); - if (type === "status") showOverlay(payload.msg); if (type === "playing") hideOverlay(); if (type === "error") showOverlay(payload.msg || payload); @@ -283,7 +283,17 @@ const id = `${Math.random().toString(36).slice(2)}`; }, }); - await player.start(); + async function startWithRetry() { + try { + await player.start(); + } catch (err) { + player.stop(); + showOverlay(err + " Retrying in 5s…"); + setTimeout(startWithRetry, 5000); + } + } + + startWithRetry(); videoEl.volume = 0; videoEl.muted = true;