|
|
|
|
@ -1,7 +1,6 @@ |
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */ |
|
|
|
|
import { |
|
|
|
|
Fragment, |
|
|
|
|
memo, |
|
|
|
|
useEffect, |
|
|
|
|
useRef, |
|
|
|
|
useState, |
|
|
|
|
@ -16,13 +15,9 @@ import { Container } from './styled' |
|
|
|
|
import { CastPlayer } from './CastVideos' |
|
|
|
|
import { useMatchPageStore } from '../MatchPage/store' |
|
|
|
|
|
|
|
|
|
type Props = { |
|
|
|
|
src?: string, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const NO_DEVICES_AVAILABLE = 'NO_DEVICES_AVAILABLE' |
|
|
|
|
|
|
|
|
|
export const ChromeCast = memo(({ src } : Props) => { |
|
|
|
|
export const ChromeCast = () => { |
|
|
|
|
const [isCastAvailable, setIsCastAvailable] = useState(false) |
|
|
|
|
|
|
|
|
|
const { profile } = useMatchPageStore() |
|
|
|
|
@ -32,8 +27,7 @@ export const ChromeCast = memo(({ src } : Props) => { |
|
|
|
|
const GoogleCastLauncher = (document as any).createElement('google-cast-launcher') |
|
|
|
|
GoogleCastLauncher.setAttribute('id', 'castbutton') |
|
|
|
|
|
|
|
|
|
const baseUrl = src ?? `${API_ROOT}/video/chromecast/stream/${sportType}/${matchId}.m3u8` |
|
|
|
|
const urlWithToken = (/\d.m3u8/.test(baseUrl)) ? `${baseUrl}?access_token=${readToken()}` : baseUrl |
|
|
|
|
const baseUrl = `${API_ROOT}/v1/broadcasts/${sportType}/${matchId}/master.m3u8?access_token=${readToken()}` |
|
|
|
|
|
|
|
|
|
const teamsInfo = `${profile?.team1.name_eng} - ${profile?.team2.name_eng}` |
|
|
|
|
|
|
|
|
|
@ -55,7 +49,7 @@ export const ChromeCast = memo(({ src } : Props) => { |
|
|
|
|
|
|
|
|
|
document.body.appendChild(script) |
|
|
|
|
|
|
|
|
|
const castPlayer = new CastPlayer(urlWithToken, teamsInfo); |
|
|
|
|
const castPlayer = new CastPlayer(baseUrl, teamsInfo); |
|
|
|
|
(window as any).__onGCastApiAvailable = (isAvailable: boolean) => { |
|
|
|
|
if (isAvailable) { |
|
|
|
|
castPlayer.initializeCastPlayer() |
|
|
|
|
@ -71,11 +65,11 @@ export const ChromeCast = memo(({ src } : Props) => { |
|
|
|
|
document.body.removeChild(script) |
|
|
|
|
setIsCastAvailable(false) |
|
|
|
|
} |
|
|
|
|
}, [teamsInfo, urlWithToken]) |
|
|
|
|
}, [teamsInfo, baseUrl]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Fragment> |
|
|
|
|
{isCastAvailable && <Container ref={containerRef} />} |
|
|
|
|
</Fragment> |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|