|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
import type { MouseEvent } from 'react' |
|
|
|
|
import { |
|
|
|
|
MouseEvent, |
|
|
|
|
useMemo, |
|
|
|
|
useRef, |
|
|
|
|
useCallback, |
|
|
|
|
useEffect, |
|
|
|
|
@ -9,6 +10,7 @@ import { |
|
|
|
|
import size from 'lodash/size' |
|
|
|
|
import isNumber from 'lodash/isNumber' |
|
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
|
import isUndefined from 'lodash/isUndefined' |
|
|
|
|
|
|
|
|
|
import Hls from 'hls.js' |
|
|
|
|
|
|
|
|
|
@ -105,14 +107,23 @@ export const useVideoPlayer = ({ |
|
|
|
|
/** время для сохранения статистики просмотра матча */ |
|
|
|
|
const timeForStatistics = useRef(0) |
|
|
|
|
|
|
|
|
|
const resumeTimeWithOffset = useMemo(() => { |
|
|
|
|
const chapterWithOffset = chapters[0].startOffsetMs / 1000 |
|
|
|
|
return !isUndefined(resumeFrom) && isLive && chapters[0].isFullMatchChapter |
|
|
|
|
? resumeFrom + chapterWithOffset |
|
|
|
|
: resumeFrom |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [resumeFrom]) |
|
|
|
|
|
|
|
|
|
const { url } = chapters[0] ?? { url: '' } |
|
|
|
|
const numberOfChapters = size(chapters) |
|
|
|
|
const { hls, videoRef } = useHlsPlayer({ |
|
|
|
|
isLive, |
|
|
|
|
resumeFrom, |
|
|
|
|
resumeFrom: resumeTimeWithOffset, |
|
|
|
|
src: url, |
|
|
|
|
}) |
|
|
|
|
const [isLivePlaying, setIsLivePlaying] = useState(false) |
|
|
|
|
// временно закоментил, если ничего не сломается, удалю
|
|
|
|
|
// const [isLivePlaying, setIsLivePlaying] = useState(false)
|
|
|
|
|
const [isPausedTime, setIsPausedTime] = useState(false) |
|
|
|
|
const [pausedProgress, setPausedProgress] = useState(0) |
|
|
|
|
|
|
|
|
|
@ -247,12 +258,12 @@ export const useVideoPlayer = ({ |
|
|
|
|
|
|
|
|
|
if (selectedPlaylist?.id !== FULL_GAME_KEY) { |
|
|
|
|
restartVideo() |
|
|
|
|
setIsLivePlaying(true) |
|
|
|
|
// setIsLivePlaying(true)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const liveProgressMs = Math.max(fullMatchDuration - BUFFERING_TIME, 0) |
|
|
|
|
setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 }) |
|
|
|
|
if (liveProgressMs > 0) setIsLivePlaying(false) |
|
|
|
|
// if (liveProgressMs > 0) setIsLivePlaying(false)
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [ |
|
|
|
|
duration, |
|
|
|
|
@ -290,11 +301,11 @@ export const useVideoPlayer = ({ |
|
|
|
|
}, [selectedPlaylist]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (duration && isLivePlaying && chapters[0]?.isFullMatchChapter) { |
|
|
|
|
if (duration && isUndefined(resumeFrom) && chaptersProps[0]?.isFullMatchChapter) { |
|
|
|
|
backToLive() |
|
|
|
|
} |
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
}, [duration, isLivePlaying]) |
|
|
|
|
}, [chaptersProps]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (duration |
|
|
|
|
@ -321,12 +332,16 @@ export const useVideoPlayer = ({ |
|
|
|
|
}, [seek, setPlayerState]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
onPlayingChange(playing) |
|
|
|
|
onPlayingChange(selectedPlaylist?.id === FULL_GAME_KEY ? playing : false) |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [playing, selectedPlaylist]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (playing) { |
|
|
|
|
setPlayerState({ buffering: false }) |
|
|
|
|
} |
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
}, [playing, onPlayingChange]) |
|
|
|
|
}, [playing]) |
|
|
|
|
|
|
|
|
|
const regURL = /\d{6,20}/gi |
|
|
|
|
|
|
|
|
|
@ -346,6 +361,16 @@ export const useVideoPlayer = ({ |
|
|
|
|
&& chapters[0]?.url.match(regURL)?.[0] === chaptersProps[0]?.url.match(regURL)?.[0]) |
|
|
|
|
|| (isEmpty(chapters) || isEmpty(chaptersProps))) return |
|
|
|
|
|
|
|
|
|
if (!isUndefined(resumeFrom) && chaptersProps[0].isFullMatchChapter) { |
|
|
|
|
setPlayerState({ |
|
|
|
|
...initialState, |
|
|
|
|
chapters: chaptersProps, |
|
|
|
|
playing: true, |
|
|
|
|
seek: resumeFrom + chaptersProps[0].startOffsetMs / 1000, |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setPlayerState({ |
|
|
|
|
...initialState, |
|
|
|
|
chapters: chaptersProps, |
|
|
|
|
|