Skip to content

Commit

Permalink
refactor(web): improve HLS stream validation and handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bhyoo99 committed Dec 28, 2024
1 parent 98de22b commit a9b4f52
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Video.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,22 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
}, [rate]);

useEffect(() => {
if (!src?.uri || !nativeRef.current || !Hls.isSupported()) {
if (!nativeRef.current || typeof src?.uri !== 'string') {
return;
}

const isHlsStream =
typeof src.uri === 'string' &&
(src.uri.includes('m3u8') || src.type === 'm3u8');
const isHlsUrl = src.uri.endsWith('.m3u8') || src.type === 'm3u8';

if (!isHlsStream) {
if (!isHlsUrl) {
return;
}

const hls = new Hls();
hls.loadSource(src.uri);
hls.attachMedia(nativeRef.current);

if (Hls.isSupported()) {
hls.loadSource(src.uri);
hls.attachMedia(nativeRef.current);
}

return () => {
hls.destroy();
Expand Down

0 comments on commit a9b4f52

Please sign in to comment.