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

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

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

Loading…
Cancel
Save