diff --git a/src/features/MatchPage/store/hooks/index.tsx b/src/features/MatchPage/store/hooks/index.tsx index d0c0b76a..938da6e2 100644 --- a/src/features/MatchPage/store/hooks/index.tsx +++ b/src/features/MatchPage/store/hooks/index.tsx @@ -8,12 +8,13 @@ import includes from 'lodash/includes' import filter from 'lodash/filter' import isEmpty from 'lodash/isEmpty' -import { useToggle } from 'hooks' +import { FULL_GAME_KEY } from 'features/MatchPage/helpers/buildPlaylists' import type { MatchInfo } from 'requests/getMatchInfo' import { getMatchInfo } from 'requests/getMatchInfo' import { usePageParams } from 'hooks/usePageParams' +import { useToggle } from 'hooks/useToggle' import { parseDate } from 'helpers/parseDate' @@ -63,6 +64,17 @@ export const useMatchPage = () => { return () => clearInterval(getIntervalMatch) }, [matchProfile, sportType, matchId]) + useEffect(() => { + let getIntervalMatch: ReturnType + if (matchProfile?.live && selectedPlaylist?.id === FULL_GAME_KEY + ) { + getIntervalMatch = setInterval( + () => getMatchInfo(sportType, matchId).then(setMatchProfile), 5000, + ) + } + return () => clearInterval(getIntervalMatch) + }) + const { events, handlePlaylistClick, diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index c9d7460a..f552a7e3 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -102,7 +102,11 @@ export const useVideoPlayer = ({ const { url } = chapters[0] ?? { url: '' } const numberOfChapters = size(chapters) - const { hls, videoRef } = useHlsPlayer(url, resumeFrom) + const { hls, videoRef } = useHlsPlayer({ + isLive, + resumeFrom, + src: url, + }) const [isLiveTime, setIsLiveTime] = useState(false) const [isPausedTime, setIsPausedTime] = useState(false) const [pausedProgress, setPausedProgress] = useState(0) diff --git a/src/features/StreamPlayer/hooks/useHlsPlayer.tsx b/src/features/StreamPlayer/hooks/useHlsPlayer.tsx index 34c995c4..f48ef002 100644 --- a/src/features/StreamPlayer/hooks/useHlsPlayer.tsx +++ b/src/features/StreamPlayer/hooks/useHlsPlayer.tsx @@ -9,7 +9,17 @@ import isNumber from 'lodash/isNumber' import { streamConfig } from '../config' -export const useHlsPlayer = (src: string, resumeFrom?: number) => { +type useHlsPlayerType = { + isLive?: boolean, + resumeFrom?: number, + src: string, +} + +export const useHlsPlayer = ({ + isLive, + resumeFrom, + src, +}: useHlsPlayerType) => { const hls = useMemo(() => { if (!Hls.isSupported()) return null @@ -35,6 +45,7 @@ export const useHlsPlayer = (src: string, resumeFrom?: number) => { return { hls, + isLive, videoRef, } }