refactor(1162): stream url change (#373)

keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent 18749aad54
commit f9e175039f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/features/MatchPage/components/LiveMatch/hooks/index.tsx
  2. 4
      src/features/MatchPage/components/LiveMatch/index.tsx
  3. 26
      src/requests/getLiveVideos.tsx
  4. 1
      src/requests/index.tsx

@ -1,13 +1,10 @@
import { useEffect, useState } from 'react'
import type { LiveVideos } from 'requests'
import { getLiveVideos } from 'requests'
import {
useSportNameParam,
usePageId,
} from 'hooks'
import { API_ROOT } from 'config'
import { usePlayerProgressReporter } from 'features/MatchPage/hooks/usePlayerProgressReporter'
import { useLastPlayPosition } from 'features/MatchPage/hooks/useLastPlayPosition'
import { useUrlParam } from 'features/MatchPage/hooks/useUrlParam'
@ -17,16 +14,9 @@ export const useLiveMatch = () => {
const matchId = usePageId()
const resume = useUrlParam()
const [liveVideos, setLiveVideos] = useState<LiveVideos>([])
useEffect(() => {
getLiveVideos(sportType, matchId).then(setLiveVideos)
},
[sportType, matchId])
return {
matchUrl: liveVideos[0] || '',
resume,
streamUrl: `${API_ROOT}/video/stream/${sportType}/${matchId}.m3u8`,
...usePlayerProgressReporter(),
...useLastPlayPosition(),
}

@ -15,10 +15,10 @@ type Props = {
export const LiveMatch = ({ profile }: Props) => {
const {
matchUrl,
onPlayerProgressChange,
onPlayingChange,
resume,
streamUrl,
} = useLiveMatch()
return (
@ -26,7 +26,7 @@ export const LiveMatch = ({ profile }: Props) => {
<Container>
<MatchProfileCard profile={profile} />
<StreamPlayer
url={matchUrl}
url={streamUrl}
onPlayingChange={onPlayingChange}
onProgressChange={onPlayerProgressChange}
resumeFrom={resume}

@ -1,26 +0,0 @@
import isEmpty from 'lodash/isEmpty'
import { API_ROOT, SportTypes } from 'config'
import { callApi } from 'helpers'
export type LiveVideos = Array<string>
export const getLiveVideos = (
sportType: SportTypes,
matchId: number,
): Promise<LiveVideos> => {
const config = {
body: {
match_id: matchId,
sport_id: sportType,
},
}
return callApi({
config,
url: `${API_ROOT}/video/stream`,
}).then((videos: LiveVideos) => {
if (isEmpty(videos)) return Promise.reject()
return videos
})
}

@ -18,7 +18,6 @@ export * from './reportPlayerProgress'
export * from './getVideos'
export * from './saveUserInfo'
export * from './getPlayerInfo'
export * from './getLiveVideos'
export * from './getMatchLastWatchSeconds'
export * from './getMatchesPreviewImages'
export * from './getSportActions'

Loading…
Cancel
Save