Skip to content

Commit 942c7a9

Browse files
check for fullscreen before initializing new stream player
1 parent ec2c48a commit 942c7a9

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/components/streamFeed/StreamPlayer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useRef, useState } from 'react'
2+
import { useFullscreen } from '../../hooks/useFullscreen'
23
import { useInitPlayer } from '../../hooks/useInitPlayer'
3-
import { useUpdatePlayerHeight } from '../../hooks/useUpdatePlayerHeight'
44
import { useSetPlayerHeight } from '../../hooks/useSetPlayerHeight'
5+
import { useUpdatePlayerHeight } from '../../hooks/useUpdatePlayerHeight'
56

67
interface StreamPlayerProps {
78
channel: string
@@ -13,7 +14,8 @@ const StreamPlayer: React.FC<StreamPlayerProps> = ({ channel }) => {
1314
const [height, setHeight] = useState(0)
1415
const volume = 0.5
1516

16-
useUpdatePlayerHeight(containerRef, setHeight)
17+
const isFullscreen = useFullscreen()
18+
useUpdatePlayerHeight(containerRef, isFullscreen, setHeight)
1719
useInitPlayer(channel, containerRef, height, playerRef, volume)
1820
useSetPlayerHeight(height, playerRef)
1921

src/hooks/useFullscreen.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useEffect, useState } from 'react'
2+
3+
export const useFullscreen = () => {
4+
const [isFullscreen, setIsFullscreen] = useState(false)
5+
6+
useEffect(() => {
7+
const handler = () => {
8+
setIsFullscreen(!!document.fullscreenElement)
9+
}
10+
document.addEventListener('fullscreenchange', handler)
11+
return () => document.removeEventListener('fullscreenchange', handler)
12+
}, [])
13+
14+
return isFullscreen
15+
}

src/hooks/useUpdatePlayerHeight.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import { useEffect } from 'react'
22

33
export const useUpdatePlayerHeight = (
44
containerRef: React.MutableRefObject<HTMLDivElement | null>,
5+
isFullscreen: boolean,
56
setHeight: (value: React.SetStateAction<number>) => void
67
) => {
78
useEffect(() => {
89
const updateHeight = () => {
9-
if (containerRef.current) {
10+
if (containerRef.current && !isFullscreen) {
1011
const width = containerRef.current.offsetWidth
1112
setHeight(Math.round((width * 9) / 16))
1213
}
1314
}
15+
1416
updateHeight()
1517
window.addEventListener('resize', updateHeight)
1618
return () => window.removeEventListener('resize', updateHeight)
17-
}, [containerRef, setHeight])
19+
}, [containerRef, isFullscreen, setHeight])
1820
}

0 commit comments

Comments
 (0)