fix(#339): remove-interval-request-getMatch-info

pull/94/head
Andrei Dekterev 3 years ago committed by Gitea
parent af5be4bfab
commit 6002643f36
  1. 12
      src/features/MatchPage/store/hooks/index.tsx
  2. 44
      src/features/StreamPlayer/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<typeof setInterval>
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()

@ -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) => {

Loading…
Cancel
Save