mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-11 22:40:32 +01:00
Fix HLS live check to handle fetch errors and improve polling logic
This commit is contained in:
@@ -274,36 +274,45 @@ function StreamPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setStreamReady(false)
|
const checkHlsLive = () => {
|
||||||
setHlsLive(null)
|
console.log("[HLS Check] Fetching manifest:", activePlayback.url)
|
||||||
console.log("[HLS Check] Fetching manifest:", activePlayback.url)
|
fetch(activePlayback.url, { cache: "no-store" })
|
||||||
fetch(activePlayback.url)
|
.then(async (res) => {
|
||||||
.then(async (res) => {
|
if (isActive) {
|
||||||
if (isActive) {
|
console.log("[HLS Check] Response status:", res.status, res.ok)
|
||||||
console.log("[HLS Check] Response status:", res.status, res.ok)
|
if (!res.ok) {
|
||||||
if (!res.ok) {
|
setStreamReady(false)
|
||||||
|
setHlsLive(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const manifest = await res.text()
|
||||||
|
if (!isActive) return
|
||||||
|
const live = isHlsPlaylistLive(manifest)
|
||||||
|
console.log("[HLS Check] Manifest live check:", { live, manifestLength: manifest.length, first200: manifest.slice(0, 200) })
|
||||||
|
setStreamReady(live)
|
||||||
|
setHlsLive(live)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("[HLS Check] Fetch error:", err)
|
||||||
|
if (isActive) {
|
||||||
setStreamReady(false)
|
setStreamReady(false)
|
||||||
setHlsLive(false)
|
setHlsLive(false)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
const manifest = await res.text()
|
})
|
||||||
if (!isActive) return
|
}
|
||||||
const live = isHlsPlaylistLive(manifest)
|
|
||||||
console.log("[HLS Check] Manifest live check:", { live, manifestLength: manifest.length, first200: manifest.slice(0, 200) })
|
// Initial check
|
||||||
setStreamReady(live)
|
setStreamReady(false)
|
||||||
setHlsLive(live)
|
setHlsLive(null)
|
||||||
}
|
checkHlsLive()
|
||||||
})
|
|
||||||
.catch((err) => {
|
// Poll every 5 seconds to detect when stream goes live
|
||||||
console.error("[HLS Check] Fetch error:", err)
|
const interval = setInterval(checkHlsLive, 5000)
|
||||||
if (isActive) {
|
|
||||||
setStreamReady(false)
|
|
||||||
setHlsLive(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isActive = false
|
isActive = false
|
||||||
|
clearInterval(interval)
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
activePlayback?.type,
|
activePlayback?.type,
|
||||||
@@ -341,11 +350,13 @@ function StreamPage() {
|
|||||||
}
|
}
|
||||||
}, [activePlayback?.type, stream?.hls_url])
|
}, [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
|
// For other users, use stream?.is_live from the database
|
||||||
const isLiveStatus = username === "nikiv" ? streamLive : Boolean(stream?.is_live)
|
const isLiveStatus = username === "nikiv"
|
||||||
const isActuallyLive =
|
? (hlsLive === true || (hlsLive === null && streamLive))
|
||||||
isLiveStatus && (activePlayback?.type !== "hls" || hlsLive !== false)
|
: Boolean(stream?.is_live)
|
||||||
|
const isActuallyLive = isLiveStatus
|
||||||
const shouldFetchSpotify = username === "nikiv" && !isActuallyLive
|
const shouldFetchSpotify = username === "nikiv" && !isActuallyLive
|
||||||
|
|
||||||
// Debug logging for stream status
|
// Debug logging for stream status
|
||||||
|
|||||||
Reference in New Issue
Block a user