From f212fb5d41361b63d5b57449c63663cac405e928 Mon Sep 17 00:00:00 2001
From: Francis Champagne <46095852+fcisio@users.noreply.github.com>
Date: Fri, 10 Jun 2022 15:39:36 -0400
Subject: [PATCH] Fix SSR issues with Hls.isSupported()
Check if `window` is defined before `Hls.isSupported()`.
Fixes issue [#1863](https://github.com/video-dev/hls.js/issues/1863)
---
src/index.tsx | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/index.tsx b/src/index.tsx
index f2a304c..b3a3304 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -68,8 +68,8 @@ function ReactHlsPlayer({
}
// Check for Media Source support
- if (Hls.isSupported()) {
- _initPlayer();
+ if (typeof window !== 'undefined') {
+ Hls.isSupported() && _initPlayer();
}
return () => {
@@ -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 ;
+ if (typeof window !== 'undefined') {
+ if (Hls.isSupported()) return ;
+ }
// Fallback to using a regular video player if HLS is supported by default in the user's browser
return ;