feat: 🎸 #2542
airplay test version ✅ Closes: #2542keep-around/b214ac7012ef42593bee62c207888a2593bc5a38
parent
d115fae7bf
commit
5b209af193
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,58 @@ |
||||
import { useEffect } from 'react' |
||||
|
||||
import { usePageParams } from 'hooks/usePageParams' |
||||
|
||||
import { AirplayButton, AirplayIcon } from './styled' |
||||
|
||||
type Props = { |
||||
videoRef: React.RefObject<HTMLVideoElement>, |
||||
} |
||||
|
||||
export const AirPlay = ({ videoRef }: Props) => { |
||||
const { profileId: matchId, sportType } = usePageParams() |
||||
|
||||
useEffect(() => { |
||||
// попытки подсунуть airplay кнопке урл отличающийся от урла основного плеера
|
||||
// const baseUrl = includes(videoRef?.current?.src, '.m3u8')
|
||||
// eslint-disable-next-line max-len
|
||||
// ? `${API_ROOT}/video/chromecast/stream/${sportType}/${matchId}.m3u8?access_token=${readToken()}`
|
||||
// : videoRef?.current?.src
|
||||
|
||||
const video = videoRef.current! |
||||
// const video = document.createElement('video')
|
||||
// video.src = baseUrl!
|
||||
|
||||
const airPlayBtn = document.getElementById('airPlay')! |
||||
|
||||
const changeAvailability = (event: any) => { |
||||
switch (event.availability) { |
||||
case 'available': |
||||
airPlayBtn.style.display = 'block' |
||||
break |
||||
case 'unavailable': |
||||
airPlayBtn.style.display = 'none' |
||||
break |
||||
} |
||||
} |
||||
|
||||
const onAirplayClick = () => { |
||||
(video as any).webkitShowPlaybackTargetPicker() |
||||
} |
||||
|
||||
if ((window as any).WebKitPlaybackTargetAvailabilityEvent && video) { |
||||
video.addEventListener('webkitplaybacktargetavailabilitychanged', changeAvailability) |
||||
airPlayBtn.addEventListener('click', onAirplayClick) |
||||
} |
||||
|
||||
return () => { |
||||
video.removeEventListener('webkitplaybacktargetavailabilitychanged', changeAvailability) |
||||
airPlayBtn.removeEventListener('click', onAirplayClick) |
||||
} |
||||
}, [matchId, sportType, videoRef]) |
||||
|
||||
return ( |
||||
<AirplayButton id='airPlay'> |
||||
<AirplayIcon src='/images/airplay.svg' /> |
||||
</AirplayButton> |
||||
) |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
import styled, { css } from 'styled-components' |
||||
|
||||
import { isMobileDevice } from 'config/userAgent' |
||||
|
||||
import { ButtonBase } from '../StreamPlayer/styled' |
||||
|
||||
export const AirplayButton = styled(ButtonBase)` |
||||
width: 24px; |
||||
height: 24px; |
||||
padding: 0; |
||||
display: none; |
||||
margin-left: 25px; |
||||
|
||||
${isMobileDevice |
||||
? css` |
||||
width: 22px; |
||||
height: 22px; |
||||
margin-left: 15px; |
||||
` |
||||
: ''}; |
||||
` |
||||
|
||||
export const AirplayIcon = styled.img` |
||||
width: 24px; |
||||
height: 24px; |
||||
` |
||||
Loading…
Reference in new issue