fix(#1701): fix episodes events

keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
Andrei Dekterev 4 years ago committed by Andrei Dekterev
parent ead11c2793
commit 0bf37fd2b9
  1. 28
      src/features/MatchPage/components/LiveMatch/helpers.tsx
  2. 1
      src/features/MatchPage/components/LiveMatch/hooks/index.tsx
  3. 5
      src/features/MatchPage/components/LiveMatch/hooks/useChapters.tsx
  4. 3
      src/features/StreamPlayer/components/ProgressBar/helpers/calculateChapterStyles/index.tsx
  5. 2
      src/features/StreamPlayer/hooks/index.tsx
  6. 9
      src/requests/getMatchInfo.tsx

@ -5,6 +5,7 @@ import concat from 'lodash/concat'
import type { Episodes } from 'requests/getMatchPlaylists' import type { Episodes } from 'requests/getMatchPlaylists'
import type { Chapters, Chapter } from 'features/StreamPlayer/types' import type { Chapters, Chapter } from 'features/StreamPlayer/types'
import type { MatchInfo, VideoBound } from 'requests/getMatchInfo'
import type { MatchPlaylistOption, PlaylistOption } from '../../types' import type { MatchPlaylistOption, PlaylistOption } from '../../types'
import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' import { FULL_GAME_KEY } from '../../helpers/buildPlaylists'
@ -32,7 +33,11 @@ const getFullMatchChapters = (url: string, playlist: MatchPlaylistOption) => {
/** /**
* Формирует эпизоды плейлистов матча и игроков * Формирует эпизоды плейлистов матча и игроков
* */ * */
const getPlaylistChapters = (url: string, episodes: Episodes) => reduce( const getPlaylistChapters = (
profile: MatchInfo,
url: string,
episodes: Episodes,
) => reduce(
episodes, episodes,
( (
acc: Chapters, acc: Chapters,
@ -41,15 +46,20 @@ const getPlaylistChapters = (url: string, episodes: Episodes) => reduce(
) => { ) => {
if (episode.s >= episode.e) return acc if (episode.s >= episode.e) return acc
const bound = profile!.video_bounds!.filter(
(ep: VideoBound) => Number(ep.h) === Number(episode.h),
)
const episodeDuration = (episode.e - episode.s) * 1000 const episodeDuration = (episode.e - episode.s) * 1000
const prevVideoEndMs = last(acc)?.endMs || 0 const prevVideoEndMs = (last(acc)?.endMs ?? bound[0].s * 1000) || 0
const nextChapter: Chapter = { const nextChapter: Chapter = {
duration: episodeDuration, duration: episodeDuration,
endMs: prevVideoEndMs + episodeDuration, endMs: prevVideoEndMs + episodeDuration,
endOffsetMs: episode.e * 1000, endOffsetMs: prevVideoEndMs + episode.e * 1000,
index, index,
startMs: prevVideoEndMs, startMs: 0,
startOffsetMs: episode.s * 1000, startOffsetMs: prevVideoEndMs + episode.s * 1000,
url, url,
} }
return concat(acc, nextChapter) return concat(acc, nextChapter)
@ -58,6 +68,7 @@ const getPlaylistChapters = (url: string, episodes: Episodes) => reduce(
) )
type Args = { type Args = {
profile: MatchInfo,
selectedPlaylist?: PlaylistOption, selectedPlaylist?: PlaylistOption,
url: string, url: string,
} }
@ -66,6 +77,7 @@ type Args = {
* Формирует список эпизодов из выбранного плейлиста для плеера * Формирует список эпизодов из выбранного плейлиста для плеера
*/ */
export const buildChapters = ({ export const buildChapters = ({
profile,
selectedPlaylist, selectedPlaylist,
url, url,
}: Args): Chapters => { }: Args): Chapters => {
@ -73,5 +85,9 @@ export const buildChapters = ({
if (selectedPlaylist.id === FULL_GAME_KEY) { if (selectedPlaylist.id === FULL_GAME_KEY) {
return getFullMatchChapters(url, selectedPlaylist) return getFullMatchChapters(url, selectedPlaylist)
} }
return getPlaylistChapters(url, selectedPlaylist.episodes) return getPlaylistChapters(
profile,
url,
selectedPlaylist.episodes,
)
} }

@ -30,6 +30,7 @@ export const useLiveMatch = () => {
) )
const { chapters } = useChapters({ const { chapters } = useChapters({
profile,
selectedPlaylist, selectedPlaylist,
url: `${API_ROOT}/video/stream/${sportType}/${matchId}.m3u8`, url: `${API_ROOT}/video/stream/${sportType}/${matchId}.m3u8`,
}) })

@ -1,24 +1,29 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import type { PlaylistOption } from 'features/MatchPage/types' import type { PlaylistOption } from 'features/MatchPage/types'
import type { MatchInfo } from 'requests/getMatchInfo'
import { buildChapters } from '../helpers' import { buildChapters } from '../helpers'
type Args = { type Args = {
profile: MatchInfo,
selectedPlaylist?: PlaylistOption, selectedPlaylist?: PlaylistOption,
url: string, url: string,
} }
export const useChapters = ({ export const useChapters = ({
profile,
selectedPlaylist, selectedPlaylist,
url, url,
}: Args) => { }: Args) => {
const chapters = useMemo( const chapters = useMemo(
() => buildChapters({ () => buildChapters({
profile,
selectedPlaylist, selectedPlaylist,
url, url,
}), }),
[ [
profile,
selectedPlaylist, selectedPlaylist,
url, url,
], ],

@ -44,7 +44,8 @@ export const calculateChapterStyles = ({
})), })),
)(chapters) )(chapters)
const chapter = chapters[activeChapterIndex] const chapter = chapters[activeChapterIndex] ?? chapters[0]
const activeChapter = { const activeChapter = {
...chapter, ...chapter,
loaded: calculateChapterProgress(loadedProgress, chapter), loaded: calculateChapterProgress(loadedProgress, chapter),

@ -90,7 +90,7 @@ export const useVideoPlayer = ({
} = usePlayingHandlers(setPlayerState, chapters) } = usePlayingHandlers(setPlayerState, chapters)
const getActiveChapter = useCallback( const getActiveChapter = useCallback(
(index: number = activeChapterIndex) => chapters[index], (index: number = activeChapterIndex) => chapters[index] ?? chapters[0],
[chapters, activeChapterIndex], [chapters, activeChapterIndex],
) )

@ -16,6 +16,14 @@ export type Team = {
score: number, score: number,
} }
export type VideoBound = {
e: number,
h: number,
s: number,
}
type VideoBounds = Array<VideoBound>
export type MatchInfo = { export type MatchInfo = {
access?: boolean, access?: boolean,
calc: boolean, calc: boolean,
@ -33,6 +41,7 @@ export type MatchInfo = {
name_eng: string, name_eng: string,
name_rus: string, name_rus: string,
}, },
video_bounds?: VideoBounds,
youtube_link?: string, youtube_link?: string,
} | null } | null

Loading…
Cancel
Save