[Video] throw HLS errors to be caught by error boundary (#5166)

* throw HLS errors to be caught by error boundary

* wording tweak

* do the same on native

* fix type error
This commit is contained in:
Samuel Newman 2024-09-05 16:03:00 +01:00 committed by GitHub
parent 60b74f7ab8
commit 428607d9a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 55 additions and 19 deletions

View file

@ -23,6 +23,12 @@ export function VideoEmbedInnerWeb({
const [hasSubtitleTrack, setHasSubtitleTrack] = useState(false)
const figId = useId()
// send error up to error boundary
const [error, setError] = useState<Error | null>(null)
if (error) {
throw error
}
const hlsRef = useRef<Hls | undefined>(undefined)
useEffect(() => {
@ -38,12 +44,25 @@ export function VideoEmbedInnerWeb({
// initial value, later on it's managed by Controls
hls.autoLevelCapping = 0
hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, (event, data) => {
hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, (_event, data) => {
if (data.subtitleTracks.length > 0) {
setHasSubtitleTrack(true)
}
})
hls.on(Hls.Events.ERROR, (_event, data) => {
if (data.fatal) {
if (
data.details === 'manifestLoadError' &&
data.response?.code === 404
) {
setError(new VideoNotFoundError())
} else {
setError(data.error)
}
}
})
return () => {
hlsRef.current = undefined
hls.detachMedia()
@ -104,3 +123,9 @@ export class HLSUnsupportedError extends Error {
super('HLS is not supported')
}
}
export class VideoNotFoundError extends Error {
constructor() {
super('Video not found')
}
}