|
|
|
|
@ -10,6 +10,8 @@ import size from 'lodash/size' |
|
|
|
|
import isNumber from 'lodash/isNumber' |
|
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
|
|
|
|
|
|
import Hls from 'hls.js' |
|
|
|
|
|
|
|
|
|
import { isIOS } from 'config/userAgent' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
@ -37,6 +39,7 @@ import { useProgressChangeHandler } from './useProgressChangeHandler' |
|
|
|
|
import { usePlayingHandlers } from './usePlayingHandlers' |
|
|
|
|
import { useDuration } from './useDuration' |
|
|
|
|
import { useAudioTrack } from './useAudioTrack' |
|
|
|
|
import { FULL_GAME_KEY } from '../../MatchPage/helpers/buildPlaylists' |
|
|
|
|
|
|
|
|
|
export type PlayerState = typeof initialState |
|
|
|
|
|
|
|
|
|
@ -125,6 +128,16 @@ export const useVideoPlayer = ({ |
|
|
|
|
togglePlaying, |
|
|
|
|
} = usePlayingHandlers(setPlayerState, chapters) |
|
|
|
|
|
|
|
|
|
const restartVideo = () => { |
|
|
|
|
onPlaylistSelect({ |
|
|
|
|
duration: 0, |
|
|
|
|
episodes: [], |
|
|
|
|
id: FULL_GAME_KEY, |
|
|
|
|
lexic: 13028, |
|
|
|
|
type: 0, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getActiveChapter = useCallback( |
|
|
|
|
(index: number = activeChapterIndex) => chapters[index], |
|
|
|
|
[chapters, activeChapterIndex], |
|
|
|
|
@ -231,20 +244,15 @@ export const useVideoPlayer = ({ |
|
|
|
|
const backToLive = useCallback(() => { |
|
|
|
|
if (!duration) return |
|
|
|
|
|
|
|
|
|
if (selectedPlaylist?.id !== 'full_game') { |
|
|
|
|
onPlaylistSelect({ |
|
|
|
|
duration: 0, |
|
|
|
|
episodes: [], |
|
|
|
|
id: 'full_game', |
|
|
|
|
lexic: 13028, |
|
|
|
|
type: 0, |
|
|
|
|
}) |
|
|
|
|
if (selectedPlaylist?.id !== FULL_GAME_KEY) { |
|
|
|
|
restartVideo() |
|
|
|
|
setIsLiveTime(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const liveProgressMs = Math.max(duration - 30000, 0) |
|
|
|
|
setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 }) |
|
|
|
|
if (liveProgressMs > 0) setIsLiveTime(false) |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [ |
|
|
|
|
duration, |
|
|
|
|
onPlaylistSelect, |
|
|
|
|
@ -255,14 +263,8 @@ export const useVideoPlayer = ({ |
|
|
|
|
const backToPausedTime = useCallback(() => { |
|
|
|
|
if (!duration) return |
|
|
|
|
|
|
|
|
|
if (selectedPlaylist?.id !== 'full_game') { |
|
|
|
|
onPlaylistSelect({ |
|
|
|
|
duration: 0, |
|
|
|
|
episodes: [], |
|
|
|
|
id: 'full_game', |
|
|
|
|
lexic: 13028, |
|
|
|
|
type: 0, |
|
|
|
|
}) |
|
|
|
|
if (selectedPlaylist?.id !== FULL_GAME_KEY) { |
|
|
|
|
restartVideo() |
|
|
|
|
setIsPausedTime(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -403,6 +405,16 @@ export const useVideoPlayer = ({ |
|
|
|
|
stopPlaying, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
/* воспроизводим плейлист полного матча с начала при завершении трансляции */ |
|
|
|
|
if (isLive) hls?.on(Hls.Events.BUFFER_EOS, restartVideo) |
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
|
hls?.off(Hls.Events.BUFFER_EOS, restartVideo) |
|
|
|
|
} |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [hls, isLive]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (!navigator.serviceWorker || !isIOS) return undefined |
|
|
|
|
const listener = (event: MessageEvent) => { |
|
|
|
|
|