fix(#3099): save match stats 5 sec

tunisia.insports.tv
Rakov Roman 3 years ago
parent 8e19b230cc
commit 407a9d9261
  1. 11
      src/features/MultiSourcePlayer/hooks/index.tsx
  2. 11
      src/features/StreamPlayer/hooks/index.tsx
  3. 4
      src/requests/saveMatchStats.tsx

@ -22,9 +22,9 @@ import {
} from 'hooks'
import {
intervalMs,
MatchInfo,
saveMatchStats,
VIEW_INTERVAL_MS,
} from 'requests'
import { useProgressChangeHandler } from './useProgressChangeHandler'
@ -74,6 +74,9 @@ export const useMultiSourcePlayer = ({
const { profileId, sportType } = usePageParams()
/** время для сохранения статистики просмотра матча */
const timeForStatistics = useRef(0)
const numberOfChapters = size(chapters)
const [
{
@ -195,6 +198,8 @@ export const useMultiSourcePlayer = ({
const chapter = getActiveChapter()
const value = Math.max(playedMs - chapter.startOffsetMs, 0)
timeForStatistics.current = (value + chapter.startMs) / 1000
setPlayerState({ playedProgress: value })
}
@ -283,11 +288,11 @@ export const useMultiSourcePlayer = ({
callback: () => {
saveMatchStats({
matchId: profileId,
matchSecond: videoRef.current?.currentTime!,
matchSecond: timeForStatistics.current,
sportType,
})
},
intervalDuration: intervalMs,
intervalDuration: VIEW_INTERVAL_MS,
startImmediate: false,
})

@ -1,5 +1,6 @@
import type { MouseEvent } from 'react'
import {
useRef,
useCallback,
useEffect,
useState,
@ -25,7 +26,7 @@ import { useNoNetworkPopupStore } from 'features/NoNetworkPopup'
import { useLiveMatch } from 'features/MatchPage/components/LiveMatch/hooks'
import { useLexicsStore } from 'features/LexicsStore'
import { intervalMs, saveMatchStats } from 'requests'
import { VIEW_INTERVAL_MS, saveMatchStats } from 'requests'
import { REWIND_SECONDS } from '../config'
import { useHlsPlayer } from './useHlsPlayer'
@ -96,6 +97,9 @@ export const useVideoPlayer = ({
const { lang } = useLexicsStore()
const { profileId, sportType } = usePageParams()
/** время для сохранения статистики просмотра матча */
const timeForStatistics = useRef(0)
const { url } = chapters[0] ?? { url: '' }
const numberOfChapters = size(chapters)
const { hls, videoRef } = useHlsPlayer({
@ -219,6 +223,7 @@ export const useVideoPlayer = ({
const chapter = getActiveChapter()
const value = Math.max(playedMs - chapter.startOffsetMs, 0)
setPlayerState({ playedProgress: value })
timeForStatistics.current = (value + chapter.startMs) / 1000
progressChangeCallback(value / 1000)
}
@ -443,11 +448,11 @@ export const useVideoPlayer = ({
callback: () => {
saveMatchStats({
matchId: profileId,
matchSecond: videoRef.current?.currentTime!,
matchSecond: timeForStatistics.current,
sportType,
})
},
intervalDuration: intervalMs,
intervalDuration: VIEW_INTERVAL_MS,
startImmediate: false,
})

@ -8,7 +8,7 @@ type Props = {
sportType: SportTypes,
}
export const intervalMs = 15000
export const VIEW_INTERVAL_MS = 5000
export const saveMatchStats = ({
matchId,
@ -19,7 +19,7 @@ export const saveMatchStats = ({
const config = {
body: {
interval: intervalMs / 1000,
interval: VIEW_INTERVAL_MS / 1000,
match_id: matchId,
second: matchSecond,
sport_id: sportType,

Loading…
Cancel
Save