From ea00f09c7e8219696ced3f481c76e124da60d18e Mon Sep 17 00:00:00 2001 From: Rakov Date: Tue, 16 May 2023 13:36:31 +0300 Subject: [PATCH 1/4] fix(#578): back to live fix --- .../components/LiveMatch/hooks/index.tsx | 2 +- src/features/StreamPlayer/hooks/index.tsx | 148 +++++++++++++----- 2 files changed, 111 insertions(+), 39 deletions(-) diff --git a/src/features/MatchPage/components/LiveMatch/hooks/index.tsx b/src/features/MatchPage/components/LiveMatch/hooks/index.tsx index d6b63df5..d2dc0c41 100644 --- a/src/features/MatchPage/components/LiveMatch/hooks/index.tsx +++ b/src/features/MatchPage/components/LiveMatch/hooks/index.tsx @@ -31,7 +31,7 @@ export const useLiveMatch = () => { const matchesLastWatchSecond: MatchSecondType | null = lastSecondLS && JSON.parse(lastSecondLS) // undefined означает, что юзер будет смотреть лайв return profile && !profile.live - ? matchesLastWatchSecond?.[sportType]?.[matchId]?.lastWatchSecond || 0 + ? matchesLastWatchSecond?.[sportType]?.[matchId]?.lastWatchSecond : undefined // eslint-disable-next-line react-hooks/exhaustive-deps }, [profile]) diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index abe8ae2f..63b3eddf 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -139,8 +139,11 @@ export const useVideoPlayer = ({ resumeFrom: resumeTimeWithOffset, src: url, }) - // временно закоментил, если ничего не сломается, удалю - // const [isLivePlaying, setIsLivePlaying] = useState(false) + + // eslint-disable-next-line no-unsafe-optional-chaining + const videoRefDurationMs = videoRef.current?.duration! * 1000 + + const [isLivePlaying, setIsLivePlaying] = useState(false) const [isPausedTime, setIsPausedTime] = useState(false) const pausedProgress = useRef(0) @@ -194,9 +197,20 @@ export const useVideoPlayer = ({ const chaptersDuration = useDuration(chapters) - const duration = (isLive && chapters[0]?.isFullMatchChapter) - ? fullMatchDuration - getActiveChapter().startOffsetMs + const duration = useMemo(() => (( + isLive + && chapters[0]?.isFullMatchChapter + && Number.isFinite(videoRefDurationMs) + ) + ? videoRefDurationMs - getActiveChapter().startOffsetMs : chaptersDuration + ), [ + chapters, + chaptersDuration, + getActiveChapter, + isLive, + videoRefDurationMs, + ]) const { onReady, @@ -206,9 +220,9 @@ export const useVideoPlayer = ({ togglePlaying, } = usePlayingHandlers(setPlayerState, chapters) - const restartVideo = () => { + const restartVideo = useCallback(() => { onPlaylistSelect(matchPlaylists.match[0]) - } + }, [matchPlaylists.match, onPlaylistSelect]) const { isFullscreen, @@ -282,9 +296,21 @@ export const useVideoPlayer = ({ setPlayerState({ playing: true }) } - const checkLive = () => chapters[0]?.isFullMatchChapter - && isLive - && playedProgress > duration - BUFFERING_TIME * 1.5 + const isLiveTime = useMemo(() => { + const matchDuration = duration === 0 && Number.isFinite(videoRefDurationMs) + ? videoRefDurationMs + : duration + + return chapters[0]?.isFullMatchChapter + && isLive + && playedProgress > matchDuration - BUFFERING_TIME * 1.5 + }, [ + chapters, + duration, + isLive, + playedProgress, + videoRefDurationMs, + ]) const onDuration = (durationSeconds: number) => { setPlayerState({ duration: toMilliSeconds(durationSeconds) }) @@ -318,19 +344,26 @@ export const useVideoPlayer = ({ if (selectedPlaylist?.id !== FULL_GAME_KEY) { restartVideo() - // setIsLivePlaying(true) + setIsLivePlaying(true) + return } + const matchDuration = fullMatchDuration === 0 && Number.isFinite(videoRefDurationMs) + ? videoRefDurationMs + : fullMatchDuration - const liveProgressMs = Math.max(fullMatchDuration - BUFFERING_TIME, 0) + const liveProgressMs = Math.max(matchDuration - BUFFERING_TIME, 0) setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 }) - // if (liveProgressMs > 0) setIsLivePlaying(false) - // eslint-disable-next-line react-hooks/exhaustive-deps + if (liveProgressMs > 0 && isLiveTime) setIsLivePlaying(false) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ duration, - onPlaylistSelect, selectedPlaylist, setPlayerState, matchPlaylists.match, + isLiveTime, + fullMatchDuration, + videoRefDurationMs, + restartVideo, ]) const backToPausedTime = useCallback(() => { @@ -339,19 +372,14 @@ export const useVideoPlayer = ({ if (selectedPlaylist?.id !== FULL_GAME_KEY) { restartVideo() setIsPausedTime(true) + return } - - const liveProgressMs = Math.max(duration - BUFFERING_TIME, 0) - - setPlayerState({ playedProgress: pausedProgress.current, seek: pausedProgress.current / 1000 }) - if (liveProgressMs > 0) setIsPausedTime(false) - // eslint-disable-next-line + setIsPausedTime(false) + // eslint-disable-next-line }, [ duration, - onPlaylistSelect, selectedPlaylist, - setPlayerState, - matchPlaylists.match, + restartVideo, ]) const stopPlayingEpisodes = () => { @@ -373,22 +401,17 @@ export const useVideoPlayer = ({ }, [selectedPlaylist]) useEffect(() => { - if (duration && isUndefined(resumeFrom) && chaptersProps[0]?.isFullMatchChapter) { + if ( + isLive + && isNumber(duration) + && isUndefined(resumeFrom) + && chaptersProps[0]?.isFullMatchChapter + ) { backToLive() } // eslint-disable-next-line }, []) - useEffect(() => { - if (duration - && isPausedTime - && chapters[0]?.isFullMatchChapter - ) { - backToPausedTime() - } - // eslint-disable-next-line - }, [duration, isPausedTime]) - useEventListener({ callback: (e: KeyboardEvent) => { if (isOpen) return @@ -434,7 +457,12 @@ export const useVideoPlayer = ({ && chapters[0]?.url.match(regURL)?.[0] === chaptersProps[0]?.url.match(regURL)?.[0]) || (isEmpty(chapters) || isEmpty(chaptersProps))) return - if (!isUndefined(resumeFrom) && chaptersProps[0].isFullMatchChapter) { + if ( + !isUndefined(resumeFrom) + && chaptersProps[0].isFullMatchChapter + && !isLivePlaying + && !isPausedTime + ) { setPlayerState({ ...initialState, chapters: chaptersProps, @@ -444,6 +472,42 @@ export const useVideoPlayer = ({ return } + if ( + chaptersProps[0].isFullMatchChapter + && isLive + && selectedPlaylist.id === FULL_GAME_KEY + && isLivePlaying + && !isPausedTime + ) { + setIsLivePlaying(false) + setPlayerState({ + ...initialState, + chapters: chaptersProps, + duration: videoRefDurationMs, + playing: true, + seek: Number.isFinite(videoRefDurationMs) + ? (videoRefDurationMs - BUFFERING_TIME) / 1000 + : 0, + }) + return + } + + if ( + chaptersProps[0].isFullMatchChapter + && selectedPlaylist.id === FULL_GAME_KEY + && isPausedTime + && !isLivePlaying + ) { + setIsPausedTime(false) + setPlayerState({ + ...initialState, + chapters: chaptersProps, + duration: videoRefDurationMs, + playing: true, + seek: pausedProgress.current / 1000, + }) + return + } setPlayerState({ ...initialState, chapters: chaptersProps, @@ -456,10 +520,18 @@ export const useVideoPlayer = ({ chaptersProps, isLive, setPlayerState, + isPausedTime, + isLivePlaying, + videoRef, + selectedPlaylist, ]) useEffect(() => { - if ((chapters[0]?.isFullMatchChapter) || isEmpty(chapters)) return + if (( + chapters[0]?.isFullMatchChapter) + || isEmpty(chapters) + || selectedPlaylist.id === FULL_GAME_KEY + ) return const { duration: chapterDuration } = getActiveChapter() if (playedProgress >= chapterDuration && !seeking && !isPlayFilterEpisodes) { @@ -590,12 +662,12 @@ export const useVideoPlayer = ({ buffering, chapters, currentPlayingOrder, - duration, + duration: duration || videoRefDurationMs, isFirstChapterPlaying, isFullscreen, isLastChapterPlaying, isLive, - isLiveTime: checkLive(), + isLiveTime, loadedProgress, numberOfChapters, onDuration, -- 2.30.2 From a56c44521b32005fd51db37cf38e987b24e3353f Mon Sep 17 00:00:00 2001 From: Ruslan Khayrullin Date: Mon, 15 May 2023 18:01:56 +0500 Subject: [PATCH 2/4] feat(in-600): remove mp4 player --- package-lock.json | 62 --- package.json | 1 - .../components/FinishedMatch/helpers.tsx | 139 ----- .../components/FinishedMatch/hooks/index.tsx | 71 --- .../FinishedMatch/hooks/useChapters.tsx | 46 -- .../FinishedMatch/hooks/useEpisodes.tsx | 71 --- .../FinishedMatch/hooks/usePlayerLogger.tsx | 72 --- .../components/FinishedMatch/index.tsx | 74 --- .../components/FinishedMatch/styled.tsx | 26 - .../MatchPage/components/LiveMatch/index.tsx | 23 +- src/features/MatchPage/index.tsx | 11 +- .../MatchPage/store/hooks/useMatchData.tsx | 7 +- src/features/MatchPopup/store/hooks/index.tsx | 5 +- .../components/Matches/index.tsx | 4 +- .../__tests__/index.tsx | 47 -- .../helpers/calculateChapterStyles/index.tsx | 59 --- .../components/ProgressBar/hooks.tsx | 51 -- .../components/ProgressBar/index.tsx | 52 -- .../components/ProgressBar/stories.tsx | 126 ----- .../components/ProgressBar/styled.tsx | 20 - .../components/Settings/hooks.tsx | 27 - .../components/Settings/index.tsx | 47 -- .../components/Settings/styled.tsx | 78 --- src/features/MultiSourcePlayer/config.tsx | 5 - .../MultiSourcePlayer/helpers/index.tsx | 35 -- .../MultiSourcePlayer/hooks/index.tsx | 494 ------------------ .../hooks/usePlayingHandlers.tsx | 102 ---- .../hooks/useProgressChangeHandler.tsx | 51 -- .../hooks/useVideoQuality.tsx | 38 -- src/features/MultiSourcePlayer/index.tsx | 268 ---------- src/features/MultiSourcePlayer/styled.tsx | 48 -- src/features/MultiSourcePlayer/types.tsx | 20 - .../Components/ControlsMobile/index.tsx | 2 +- .../Controls/Components/ControlsWeb/index.tsx | 6 +- .../components/Controls/index.tsx | 53 +- .../components/Settings/index.tsx | 2 +- .../components/Settings/styled.tsx | 4 +- .../components/YoutubePlayer/index.tsx | 51 -- src/features/StreamPlayer/hooks/index.tsx | 2 +- src/features/StreamPlayer/styled.tsx | 11 +- src/hooks/index.tsx | 1 + .../hooks/useDuration.tsx | 2 +- 42 files changed, 43 insertions(+), 2271 deletions(-) delete mode 100644 src/features/MatchPage/components/FinishedMatch/helpers.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/index.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/usePlayerLogger.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/index.tsx delete mode 100644 src/features/MatchPage/components/FinishedMatch/styled.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterStyles/__tests__/index.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterStyles/index.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/index.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/stories.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/styled.tsx delete mode 100644 src/features/MultiSourcePlayer/components/Settings/hooks.tsx delete mode 100644 src/features/MultiSourcePlayer/components/Settings/index.tsx delete mode 100644 src/features/MultiSourcePlayer/components/Settings/styled.tsx delete mode 100644 src/features/MultiSourcePlayer/config.tsx delete mode 100644 src/features/MultiSourcePlayer/helpers/index.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/index.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/usePlayingHandlers.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/useProgressChangeHandler.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/useVideoQuality.tsx delete mode 100644 src/features/MultiSourcePlayer/index.tsx delete mode 100644 src/features/MultiSourcePlayer/styled.tsx delete mode 100644 src/features/MultiSourcePlayer/types.tsx delete mode 100644 src/features/StreamPlayer/components/YoutubePlayer/index.tsx rename src/{features/MultiSourcePlayer => }/hooks/useDuration.tsx (75%) diff --git a/package-lock.json b/package-lock.json index f57f25ae..be12c447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17293,11 +17293,6 @@ "wrap-ansi": "^7.0.0" } }, - "load-script": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/load-script/-/load-script-1.0.0.tgz", - "integrity": "sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA==" - }, "loader-runner": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz", @@ -21154,33 +21149,6 @@ "memoize-one": ">=3.1.1 <6" } }, - "react-youtube": { - "version": "7.14.0", - "resolved": "https://registry.npmjs.org/react-youtube/-/react-youtube-7.14.0.tgz", - "integrity": "sha512-SUHZ4F4pd1EHmQu0CV0KSQvAs5KHOT5cfYaq4WLCcDbU8fBo1ouTXaAOIASWbrz8fHwg+G1evfoSIYpV2AwSAg==", - "requires": { - "fast-deep-equal": "3.1.3", - "prop-types": "15.7.2", - "youtube-player": "5.5.2" - }, - "dependencies": { - "prop-types": { - "version": "15.7.2", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", - "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", - "requires": { - "loose-envify": "^1.4.0", - "object-assign": "^4.1.1", - "react-is": "^16.8.1" - } - }, - "react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - } - } - }, "read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -22493,11 +22461,6 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, - "sister": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/sister/-/sister-3.0.2.tgz", - "integrity": "sha512-p19rtTs+NksBRKW9qn0UhZ8/TUI9BPw9lmtHny+Y3TinWlOa9jWh9xB0AtPSdmOy49NJJJSSe0Ey4C7h0TrcYA==" - }, "sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -26154,31 +26117,6 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" }, - "youtube-player": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/youtube-player/-/youtube-player-5.5.2.tgz", - "integrity": "sha512-ZGtsemSpXnDky2AUYWgxjaopgB+shFHgXVpiJFeNB5nWEugpW1KWYDaHKuLqh2b67r24GtP6HoSW5swvf0fFIQ==", - "requires": { - "debug": "^2.6.6", - "load-script": "^1.0.0", - "sister": "^3.0.0" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" - } - } - }, "zwitch": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-1.0.5.tgz", diff --git a/package.json b/package.json index 48ea4a1d..8e59a5b2 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "react-router-dom": "^5.2.0", "react-scripts": "^5.0.1", "react-window": "^1.8.6", - "react-youtube": "^7.14.0", "recoil": "^0.7.4", "screenfull": "^5.0.2", "styled-components": "^5.3.3", diff --git a/src/features/MatchPage/components/FinishedMatch/helpers.tsx b/src/features/MatchPage/components/FinishedMatch/helpers.tsx deleted file mode 100644 index f99f3fb0..00000000 --- a/src/features/MatchPage/components/FinishedMatch/helpers.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import map from 'lodash/map' -import last from 'lodash/last' -import uniq from 'lodash/uniq' -import filter from 'lodash/filter' -import reduce from 'lodash/reduce' -import concat from 'lodash/concat' -import orderBy from 'lodash/orderBy' -import isEmpty from 'lodash/isEmpty' -import groupBy from 'lodash/groupBy' - -import type { - Videos, - Episodes, - Episode, -} from 'requests' - -import type { Chapters, Urls } from 'features/MultiSourcePlayer/types' - -import type { PlaylistOption } from '../../types' -import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' - -const getUniquePeriods = (videos: Videos) => uniq(map(videos, ({ period }) => period)) - -type Video = { - duration: number, - period: number, - urls: Urls, -} - -const getVideoByPeriod = (videos: Videos, period: number) => { - const videosWithSamePeriod = filter(videos, { period }) - if (isEmpty(videosWithSamePeriod)) return null - - const urls = reduce( - videosWithSamePeriod, - (acc: Urls, video) => ({ - ...acc, - [video.quality]: video.url, - }), - {}, - ) - const [video] = videosWithSamePeriod - return { - duration: video.duration, - period: video.period, - urls, - } -} - -const getVideoByPeriods = (videos: Videos, periods: Array) => ( - reduce( - periods, - (acc: Array