diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-09-05 16:03:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 16:03:00 +0100 |
commit | 428607d9a31f7da94ccc3b44b4499a67f2ffbd1f (patch) | |
tree | 10261a8ce4fa20691f1c845b3a364d433ef0ea0b /src/view/com/util/post-embeds/VideoEmbedInner | |
parent | 60b74f7ab82328de5ec9cea7c40e1db705d40d6b (diff) | |
download | voidsky-428607d9a31f7da94ccc3b44b4499a67f2ffbd1f.tar.zst |
[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
Diffstat (limited to 'src/view/com/util/post-embeds/VideoEmbedInner')
-rw-r--r-- | src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx index 77295c00c..a30c0e1e9 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx @@ -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') + } +} |