fix(#299): fix isLiveTime for check Live #144

Merged
andrey.dekterev merged 1 commits from IN-319-check-icon into develop 3 years ago
  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 = { export type Props = {
chapters: Chapters, chapters: Chapters,
isLive: boolean, isLive: boolean,
isLiveTime?: boolean,
onDurationChange?: (duration: number) => void, onDurationChange?: (duration: number) => void,
onPlayingChange: (playing: boolean) => void, onPlayingChange: (playing: boolean) => void,
onProgressChange: (seconds: number) => void, onProgressChange: (seconds: number) => void,
@ -113,7 +112,7 @@ export const useVideoPlayer = ({
resumeFrom, resumeFrom,
src: url, src: url,
}) })
const [isLiveTime, setIsLiveTime] = useState(false) const [isLivePlaying, setIsLivePlaying] = useState(false)
const [isPausedTime, setIsPausedTime] = useState(false) const [isPausedTime, setIsPausedTime] = useState(false)
const [pausedProgress, setPausedProgress] = useState(0) const [pausedProgress, setPausedProgress] = useState(0)
@ -212,6 +211,10 @@ export const useVideoPlayer = ({
setPlayerState({ playing: true }) setPlayerState({ playing: true })
} }
const checkLive = () => chapters[0]?.isFullMatchChapter
&& isLive
&& playedProgress > duration - BUFFERING_TIME * 1.5
const onDuration = (durationSeconds: number) => { const onDuration = (durationSeconds: number) => {
setPlayerState({ duration: toMilliSeconds(durationSeconds) }) setPlayerState({ duration: toMilliSeconds(durationSeconds) })
onDurationChange?.(durationSeconds) onDurationChange?.(durationSeconds)
@ -244,12 +247,12 @@ export const useVideoPlayer = ({
if (selectedPlaylist?.id !== FULL_GAME_KEY) { if (selectedPlaylist?.id !== FULL_GAME_KEY) {
restartVideo() restartVideo()
setIsLiveTime(true) setIsLivePlaying(true)
} }
const liveProgressMs = Math.max(fullMatchDuration - BUFFERING_TIME, 0) const liveProgressMs = Math.max(fullMatchDuration - BUFFERING_TIME, 0)
setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 }) setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 })
if (liveProgressMs > 0) setIsLiveTime(false) if (liveProgressMs > 0) setIsLivePlaying(false)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [ }, [
duration, duration,
@ -287,11 +290,11 @@ export const useVideoPlayer = ({
}, [selectedPlaylist]) }, [selectedPlaylist])
useEffect(() => { useEffect(() => {
if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) { if (duration && isLivePlaying && chapters[0]?.isFullMatchChapter) {
backToLive() backToLive()
} }
// eslint-disable-next-line // eslint-disable-next-line
}, [duration, isLiveTime]) }, [duration, isLivePlaying])
useEffect(() => { useEffect(() => {
if (duration if (duration
@ -358,7 +361,6 @@ export const useVideoPlayer = ({
]) ])
useEffect(() => { useEffect(() => {
setIsLiveTime(playedProgress > duration - BUFFERING_TIME)
if ((chapters[0]?.isFullMatchChapter) || isEmpty(chapters)) return if ((chapters[0]?.isFullMatchChapter) || isEmpty(chapters)) return
const { duration: chapterDuration } = getActiveChapter() const { duration: chapterDuration } = getActiveChapter()
@ -494,7 +496,7 @@ export const useVideoPlayer = ({
isFullscreen, isFullscreen,
isLastChapterPlaying, isLastChapterPlaying,
isLive, isLive,
isLiveTime, isLiveTime: checkLive(),
loadedProgress, loadedProgress,
numberOfChapters, numberOfChapters,
onDuration, onDuration,

Loading…
Cancel
Save