Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Fix SSR issues with Hls.isSupported() #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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