Fix HLS live check to handle fetch errors and improve polling logic

This commit is contained in:
Nikita
2025-12-24 18:49:49 -08:00
parent 03362955f0
commit 7c678b3110

View File

@@ -274,10 +274,9 @@ function StreamPage() {
}
}
setStreamReady(false)
setHlsLive(null)
const checkHlsLive = () => {
console.log("[HLS Check] Fetching manifest:", activePlayback.url)
fetch(activePlayback.url)
fetch(activePlayback.url, { cache: "no-store" })
.then(async (res) => {
if (isActive) {
console.log("[HLS Check] Response status:", res.status, res.ok)
@@ -301,9 +300,19 @@ function StreamPage() {
setHlsLive(false)
}
})
}
// Initial check
setStreamReady(false)
setHlsLive(null)
checkHlsLive()
// Poll every 5 seconds to detect when stream goes live
const interval = setInterval(checkHlsLive, 5000)
return () => {
isActive = false
clearInterval(interval)
}
}, [
activePlayback?.type,
@@ -341,11 +350,13 @@ function StreamPage() {
}
}, [activePlayback?.type, stream?.hls_url])
// For nikiv, use streamLive from the polled API status
// For nikiv, primarily use HLS live check from Cloudflare
// Fall back to streamLive status if HLS check hasn't completed
// For other users, use stream?.is_live from the database
const isLiveStatus = username === "nikiv" ? streamLive : Boolean(stream?.is_live)
const isActuallyLive =
isLiveStatus && (activePlayback?.type !== "hls" || hlsLive !== false)
const isLiveStatus = username === "nikiv"
? (hlsLive === true || (hlsLive === null && streamLive))
: Boolean(stream?.is_live)
const isActuallyLive = isLiveStatus
const shouldFetchSpotify = username === "nikiv" && !isActuallyLive
// Debug logging for stream status