fix(#727): save match stats fix

pull/289/head
Rakov 2 years ago
parent bef03ff120
commit 2a95f32aeb
  1. 32
      src/features/StreamPlayer/hooks/index.tsx
  2. 19
      src/requests/saveMatchStats.tsx

@ -116,6 +116,7 @@ export const useVideoPlayer = ({
playingOrder,
playingProgress,
playNextEpisode,
profile,
selectedPlaylist,
setCircleAnimation,
setIsFullScreen,
@ -651,15 +652,28 @@ export const useVideoPlayer = ({
// ведем статистику просмотра матча
const { start: startCollectingStats, stop: stopCollectingStats } = useInterval({
callback: useCallback(() => {
if (timeForStatistics.current !== 0) {
saveMatchStats({
matchId: profileId,
matchSecond: timeForStatistics.current,
sportType,
})
}
}, [profileId, sportType]),
callback: useCallback(
() => {
if (timeForStatistics.current !== 0) {
saveMatchStats({
matchDate: profile?.date,
matchId: profileId,
matchSecond: timeForStatistics.current,
seasonId: profile?.season.id,
sportType,
teamFirst: profile?.team1.id,
teamSecond: profile?.team2.id,
tournamentId: profile?.tournament.id,
})
}
},
[profile?.date,
profile?.season.id,
profile?.team1.id, profile?.team2.id,
profile?.tournament.id,
profileId, sportType,
],
),
intervalDuration: VIEW_INTERVAL_MS,
startImmediate: false,
})

@ -3,26 +3,41 @@ import { VIEWS_API } from 'config'
import { callApi } from 'helpers'
type Props = {
matchDate?: string,
matchId: number,
matchSecond: number,
seasonId?: number,
sportType: number,
teamFirst?: number,
teamSecond?: number,
tournamentId?: number,
}
export const VIEW_INTERVAL_MS = 5000
export const saveMatchStats = ({
matchDate,
matchId,
matchSecond,
seasonId,
sportType,
teamFirst,
teamSecond,
tournamentId,
}: Props) => {
const url = `${VIEWS_API}/user/view`
const url = `${VIEWS_API}/v2/user/view`
const config = {
body: {
interval: VIEW_INTERVAL_MS / 1000,
duration: VIEW_INTERVAL_MS / 1000,
match_date: matchDate,
match_id: matchId,
season: seasonId,
second: matchSecond,
sport_id: sportType,
team1: teamFirst,
team2: teamSecond,
tournament: tournamentId,
},
}

Loading…
Cancel
Save