From 9376098b61d850052412b2285e071661c2a465b2 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Thu, 30 Mar 2023 00:33:36 +0700 Subject: [PATCH] fix(#299): fix isLiveTime for check Live --- src/features/StreamPlayer/helpers/index.tsx | 1 + src/features/StreamPlayer/hooks/index.tsx | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/features/StreamPlayer/helpers/index.tsx b/src/features/StreamPlayer/helpers/index.tsx index 854ce2c3..f97e78e4 100644 --- a/src/features/StreamPlayer/helpers/index.tsx +++ b/src/features/StreamPlayer/helpers/index.tsx @@ -11,3 +11,4 @@ export const findChapterByProgress = (chapters: Chapters, progressMs: number) => )) ) } + diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index 5ce8444d..3865ee1a 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -62,7 +62,6 @@ const initialState = { export type Props = { chapters: Chapters, isLive: boolean, - isLiveTime?: boolean, onDurationChange?: (duration: number) => void, onPlayingChange: (playing: boolean) => void, onProgressChange: (seconds: number) => void, @@ -113,7 +112,7 @@ export const useVideoPlayer = ({ resumeFrom, src: url, }) - const [isLiveTime, setIsLiveTime] = useState(false) + const [isLivePlaying, setIsLivePlaying] = useState(false) const [isPausedTime, setIsPausedTime] = useState(false) const [pausedProgress, setPausedProgress] = useState(0) @@ -212,6 +211,10 @@ export const useVideoPlayer = ({ setPlayerState({ playing: true }) } + const checkLive = () => chapters[0]?.isFullMatchChapter + && isLive + && playedProgress > duration - BUFFERING_TIME * 1.5 + const onDuration = (durationSeconds: number) => { setPlayerState({ duration: toMilliSeconds(durationSeconds) }) onDurationChange?.(durationSeconds) @@ -244,12 +247,12 @@ export const useVideoPlayer = ({ if (selectedPlaylist?.id !== FULL_GAME_KEY) { restartVideo() - setIsLiveTime(true) + setIsLivePlaying(true) } const liveProgressMs = Math.max(fullMatchDuration - BUFFERING_TIME, 0) setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 }) - if (liveProgressMs > 0) setIsLiveTime(false) + if (liveProgressMs > 0) setIsLivePlaying(false) // eslint-disable-next-line react-hooks/exhaustive-deps }, [ duration, @@ -287,11 +290,11 @@ export const useVideoPlayer = ({ }, [selectedPlaylist]) useEffect(() => { - if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) { + if (duration && isLivePlaying && chapters[0]?.isFullMatchChapter) { backToLive() } // eslint-disable-next-line - }, [duration, isLiveTime]) + }, [duration, isLivePlaying]) useEffect(() => { if (duration @@ -358,7 +361,6 @@ export const useVideoPlayer = ({ ]) useEffect(() => { - setIsLiveTime(playedProgress > duration - BUFFERING_TIME) if ((chapters[0]?.isFullMatchChapter) || isEmpty(chapters)) return const { duration: chapterDuration } = getActiveChapter() @@ -494,7 +496,7 @@ export const useVideoPlayer = ({ isFullscreen, isLastChapterPlaying, isLive, - isLiveTime, + isLiveTime: checkLive(), loadedProgress, numberOfChapters, onDuration,