diff --git a/src/features/MultiSourcePlayer/hooks/index.tsx b/src/features/MultiSourcePlayer/hooks/index.tsx index 25a261fb..22022292 100644 --- a/src/features/MultiSourcePlayer/hooks/index.tsx +++ b/src/features/MultiSourcePlayer/hooks/index.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, }) diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index 28573a8b..f552a7e3 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -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, }) diff --git a/src/requests/saveMatchStats.tsx b/src/requests/saveMatchStats.tsx index 2307ecad..fba03804 100644 --- a/src/requests/saveMatchStats.tsx +++ b/src/requests/saveMatchStats.tsx @@ -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,