Skip to content

Commit

Permalink
Fix SSR issues with Hls.isSupported()
Browse files Browse the repository at this point in the history
Check if `window` is defined before `Hls.isSupported()`.

Fixes issue [#1863](video-dev/hls.js#1863)
  • Loading branch information
fcisio committed Jun 10, 2022
1 parent 739acb5 commit f212fb5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function ReactHlsPlayer({
}

// Check for Media Source support
if (Hls.isSupported()) {
_initPlayer();
if (typeof window !== 'undefined') {
Hls.isSupported() && _initPlayer();
}

return () => {
Expand All @@ -80,7 +80,9 @@ function ReactHlsPlayer({
}, [autoPlay, hlsConfig, playerRef, src]);

// If Media Source is supported, use HLS.js to play video
if (Hls.isSupported()) return <video ref={playerRef} {...props} />;
if (typeof window !== 'undefined') {
if (Hls.isSupported()) return <video ref={playerRef} {...props} />;
}

// Fallback to using a regular video player if HLS is supported by default in the user's browser
return <video ref={playerRef} src={src} autoPlay={autoPlay} {...props} />;
Expand Down

0 comments on commit f212fb5

Please sign in to comment.