fix(#299): fix isLiveTime for check Live

pull/144/head
Andrei Dekterev 3 years ago
parent 27002909a5
commit 9376098b61
  1. 1
      src/features/StreamPlayer/helpers/index.tsx
  2. 18
      src/features/StreamPlayer/hooks/index.tsx

@ -11,3 +11,4 @@ export const findChapterByProgress = (chapters: Chapters, progressMs: number) =>
))
)
}

@ -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,

Loading…
Cancel
Save