mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
Improve VideoPlayer event handling and streamline viewer count sync
- Add a `callReady` function to ensure `onReady` is called only once - Attach `canplay` event listener for native HLS support to trigger `onReady` - Call `onReady` immediately after manifest parsing for HLS streams - Simplify `useStreamViewers` hook to skip viewer count sync for user "nikiv" - Silently handle errors during viewer count synchronization to avoid unnecessary logs
This commit is contained in:
@@ -38,19 +38,23 @@ export function VideoPlayer({
|
||||
const video = videoRef.current
|
||||
if (!video || !src) return
|
||||
|
||||
let hasCalledReady = false
|
||||
const callReady = () => {
|
||||
if (!hasCalledReady) {
|
||||
hasCalledReady = true
|
||||
onReady?.()
|
||||
}
|
||||
}
|
||||
|
||||
// Check if native HLS is supported (Safari)
|
||||
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
||||
video.src = src
|
||||
// Call ready when video can play
|
||||
video.addEventListener("canplay", callReady, { once: true })
|
||||
if (autoPlay) {
|
||||
video.play()
|
||||
.then(() => {
|
||||
setIsPlaying(true)
|
||||
onReady?.()
|
||||
})
|
||||
.then(() => setIsPlaying(true))
|
||||
.catch(() => setIsPlaying(false))
|
||||
} else {
|
||||
// Even if not autoplay, notify ready when we can play
|
||||
video.addEventListener("canplay", () => onReady?.(), { once: true })
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -68,15 +72,12 @@ export function VideoPlayer({
|
||||
hls.attachMedia(video)
|
||||
|
||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
// Call ready as soon as manifest is parsed
|
||||
callReady()
|
||||
if (autoPlay) {
|
||||
video.play()
|
||||
.then(() => {
|
||||
setIsPlaying(true)
|
||||
onReady?.()
|
||||
})
|
||||
.then(() => setIsPlaying(true))
|
||||
.catch(() => setIsPlaying(false))
|
||||
} else {
|
||||
onReady?.()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user