|
|
|
|
@ -1,21 +1,65 @@ |
|
|
|
|
import { |
|
|
|
|
useSportNameParam, |
|
|
|
|
usePageId, |
|
|
|
|
} from 'hooks' |
|
|
|
|
import { useCallback, useEffect } from 'react' |
|
|
|
|
|
|
|
|
|
import { API_ROOT } from 'config' |
|
|
|
|
|
|
|
|
|
import type { MatchInfo } from 'requests/getMatchInfo' |
|
|
|
|
|
|
|
|
|
import { usePageParams } from 'hooks/usePageParams' |
|
|
|
|
import { useInterval } from 'hooks/useInterval' |
|
|
|
|
|
|
|
|
|
import { usePlayerProgressReporter } from 'features/MatchPage/hooks/usePlayerProgressReporter' |
|
|
|
|
import { useLastPlayPosition } from 'features/MatchPage/hooks/useLastPlayPosition' |
|
|
|
|
import { useUrlParam } from 'features/MatchPage/hooks/useUrlParam' |
|
|
|
|
import { MATCH_UPDATE_INTERVAL } from 'features/MatchPage/config' |
|
|
|
|
import { useMatchPopupStore } from 'features/MatchPopup' |
|
|
|
|
|
|
|
|
|
import { useEvents } from '../../FinishedMatch/hooks/useEvents' |
|
|
|
|
|
|
|
|
|
export const useLiveMatch = (profile: MatchInfo) => { |
|
|
|
|
const { |
|
|
|
|
fetchMatchPlaylists, |
|
|
|
|
handlePlaylistClick, |
|
|
|
|
matchPlaylists, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
} = useMatchPopupStore() |
|
|
|
|
|
|
|
|
|
export const useLiveMatch = () => { |
|
|
|
|
const { sportType } = useSportNameParam() |
|
|
|
|
const matchId = usePageId() |
|
|
|
|
const { events, fetchMatchEvents } = useEvents() |
|
|
|
|
|
|
|
|
|
const { profileId: matchId, sportType } = usePageParams() |
|
|
|
|
const resume = useUrlParam() |
|
|
|
|
|
|
|
|
|
const fetchMatchData = useCallback(() => { |
|
|
|
|
if (profile) { |
|
|
|
|
const match = { |
|
|
|
|
...profile, |
|
|
|
|
id: matchId, |
|
|
|
|
sportType, |
|
|
|
|
team1: profile.team1, |
|
|
|
|
team2: profile.team2, |
|
|
|
|
} |
|
|
|
|
fetchMatchPlaylists(match) |
|
|
|
|
fetchMatchEvents() |
|
|
|
|
} |
|
|
|
|
}, [ |
|
|
|
|
matchId, |
|
|
|
|
profile, |
|
|
|
|
sportType, |
|
|
|
|
fetchMatchPlaylists, |
|
|
|
|
fetchMatchEvents, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
useEffect(fetchMatchData, [fetchMatchData]) |
|
|
|
|
useInterval({ |
|
|
|
|
callback: fetchMatchData, |
|
|
|
|
intervalDuration: MATCH_UPDATE_INTERVAL, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
events, |
|
|
|
|
matchPlaylists, |
|
|
|
|
onPlaylistSelect: handlePlaylistClick, |
|
|
|
|
resume, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
streamUrl: `${API_ROOT}/video/stream/${sportType}/${matchId}.m3u8`, |
|
|
|
|
...usePlayerProgressReporter(), |
|
|
|
|
...useLastPlayPosition(), |
|
|
|
|
|