From 6002643f365e1bfbcd8aee9770b63953c30073ef Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Wed, 22 Feb 2023 18:53:01 +0700 Subject: [PATCH] fix(#339): remove-interval-request-getMatch-info --- src/features/MatchPage/store/hooks/index.tsx | 12 ------ src/features/StreamPlayer/hooks/index.tsx | 44 +++++++++++++------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/features/MatchPage/store/hooks/index.tsx b/src/features/MatchPage/store/hooks/index.tsx index 852e0566..84e472dc 100644 --- a/src/features/MatchPage/store/hooks/index.tsx +++ b/src/features/MatchPage/store/hooks/index.tsx @@ -8,7 +8,6 @@ import includes from 'lodash/includes' import filter from 'lodash/filter' import isEmpty from 'lodash/isEmpty' -import { FULL_GAME_KEY } from 'features/MatchPage/helpers/buildPlaylists' import { useAuthStore } from 'features/AuthStore' import type { MatchInfo } from 'requests/getMatchInfo' @@ -120,17 +119,6 @@ export const useMatchPage = () => { userInfo, ]) - useEffect(() => { - let getIntervalMatch: ReturnType - if (matchProfile?.live && selectedPlaylist?.id === FULL_GAME_KEY - ) { - getIntervalMatch = setInterval( - () => getMatchInfo(sportType, matchId).then(setMatchProfile), 5000, - ) - } - return () => clearInterval(getIntervalMatch) - }) - const isStarted = useMemo(() => ( profile?.date ? parseDate(profile.date) < new Date() diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index 41b52413..7702f9ef 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -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) => {