Ott 1531 ios fullscreen (#460)

* fix: console nested li error

* fix(1531): full screen mode on ios

* fix: removed redundant tab index
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 4 years ago committed by GitHub
parent 47d202d4b8
commit e0d83a0eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/config/userAgent.tsx
  2. 10
      src/features/MatchCard/CardFrontside/index.tsx
  3. 7
      src/features/MatchCard/styled.tsx
  4. 10
      src/features/MultiSourcePlayer/hooks/index.tsx
  5. 8
      src/features/MultiSourcePlayer/index.tsx
  6. 41
      src/features/StreamPlayer/hooks/useFullscreen.tsx
  7. 1
      src/features/VideoPlayer/hooks/index.tsx
  8. 2
      src/features/VideoPlayer/index.tsx

@ -1,5 +1,7 @@
import { includes } from 'lodash' import { includes } from 'lodash'
export const isMobileDevice = includes(window.navigator.userAgent, 'Android') || includes(window.navigator.userAgent, 'iPhone') export const isIphone = includes(window.navigator.userAgent, 'iPhone')
export const isMobileDevice = includes(window.navigator.userAgent, 'Android') || isIphone
// удалю когда закончу с адаптивом. // удалю когда закончу с адаптивом.
// || includes(window.navigator.userAgent, 'Linux') // || includes(window.navigator.userAgent, 'Linux')

@ -83,11 +83,11 @@ export const CardFrontside = ({
const team2InFavorites = isInFavorites(ProfileTypes.TEAMS, team2.id) const team2InFavorites = isInFavorites(ProfileTypes.TEAMS, team2.id)
return ( return (
<CardWrapperOuter> <CardWrapperOuter
<CardWrapper onClick={onClick}
onClick={onClick} onKeyPress={onKeyPress}
onKeyPress={onKeyPress} >
> <CardWrapper>
<HoverFrame /> <HoverFrame />
<PreviewWrapper> <PreviewWrapper>
{ {

@ -17,7 +17,7 @@ export const CardWrapperOuter = styled.li.attrs({
padding-top: 0; padding-top: 0;
height: 90px; height: 90px;
margin-bottom: 10px; margin-bottom: 10px;
@media screen and (orientation: landscape){ @media screen and (orientation: landscape){
width: 49%; width: 49%;
:nth-child(odd){ :nth-child(odd){
@ -28,9 +28,7 @@ export const CardWrapperOuter = styled.li.attrs({
: ''}; : ''};
` `
export const CardWrapper = styled.li.attrs({ export const CardWrapper = styled.div`
tabIndex: 0,
})`
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
@ -150,7 +148,6 @@ export const Info = styled.div`
padding: 13px 12px 13px 10px; padding: 13px 12px 13px 10px;
` `
: ''}; : ''};
` `
export const SecondaryInfo = styled.div` export const SecondaryInfo = styled.div`

@ -167,6 +167,14 @@ export const useMultiSourcePlayer = ({
setPlayerState({ playedProgress: value }) setPlayerState({ playedProgress: value })
} }
const onEnded = () => {
playNextChapter()
}
const onPause = () => {
setPlayerState({ playing: false })
}
useEffect(() => { useEffect(() => {
onPlayingChange(playing) onPlayingChange(playing)
}, [playing, onPlayingChange]) }, [playing, onPlayingChange])
@ -204,8 +212,10 @@ export const useMultiSourcePlayer = ({
loadedProgress, loadedProgress,
nextSrc: getChapterUrl((activeChapterIndex + 1) % numberOfChapters), nextSrc: getChapterUrl((activeChapterIndex + 1) % numberOfChapters),
numberOfChapters, numberOfChapters,
onEnded,
onError: handleError, onError: handleError,
onLoadedProgress, onLoadedProgress,
onPause,
onPlayedProgress, onPlayedProgress,
onPlayerClick, onPlayerClick,
onProgressChange, onProgressChange,

@ -47,9 +47,11 @@ export const MultiSourcePlayer = (props: Props) => {
muted, muted,
nextSrc, nextSrc,
numberOfChapters, numberOfChapters,
onEnded,
onError, onError,
onFullscreenClick, onFullscreenClick,
onLoadedProgress, onLoadedProgress,
onPause,
onPlayedProgress, onPlayedProgress,
onPlayerClick, onPlayerClick,
onProgressChange, onProgressChange,
@ -101,7 +103,8 @@ export const MultiSourcePlayer = (props: Props) => {
isFullscreen={isFullscreen} isFullscreen={isFullscreen}
onLoadedProgress={firstPlayerActive ? onLoadedProgress : undefined} onLoadedProgress={firstPlayerActive ? onLoadedProgress : undefined}
onPlayedProgress={firstPlayerActive ? onPlayedProgress : undefined} onPlayedProgress={firstPlayerActive ? onPlayedProgress : undefined}
onEnded={() => playNextChapter()} onEnded={onEnded}
onPause={onPause}
onError={onError} onError={onError}
onReady={onReady} onReady={onReady}
/> />
@ -116,7 +119,8 @@ export const MultiSourcePlayer = (props: Props) => {
isFullscreen={isFullscreen} isFullscreen={isFullscreen}
onLoadedProgress={!firstPlayerActive ? onLoadedProgress : undefined} onLoadedProgress={!firstPlayerActive ? onLoadedProgress : undefined}
onPlayedProgress={!firstPlayerActive ? onPlayedProgress : undefined} onPlayedProgress={!firstPlayerActive ? onPlayedProgress : undefined}
onEnded={() => playNextChapter()} onEnded={onEnded}
onPause={onPause}
onError={onError} onError={onError}
onReady={onReady} onReady={onReady}
/> />

@ -1,8 +1,21 @@
import { useEffect, useRef } from 'react' import { useEffect, useRef } from 'react'
import screenfull from 'screenfull' import screenfull from 'screenfull'
import { isIphone } from 'config/userAgent'
import { useToggle } from 'hooks' import { useToggle } from 'hooks'
type IOSVideo = HTMLVideoElement & {
webkitEnterFullscreen: () => void,
webkitExitFullscreen: () => void,
}
const supportsFullscreen = (video: HTMLVideoElement | null): video is IOSVideo => Boolean(
video
&& 'webkitEnterFullscreen' in video
&& 'webkitExitFullscreen' in video,
)
export const useFullscreen = () => { export const useFullscreen = () => {
const wrapperRef = useRef<HTMLDivElement>(null) const wrapperRef = useRef<HTMLDivElement>(null)
const { const {
@ -24,12 +37,38 @@ export const useFullscreen = () => {
} }
}, [setFullscreen]) }, [setFullscreen])
const onFullscreenClick = () => { const toggleFullscreen = () => {
if (screenfull.isEnabled && wrapperRef.current) { if (screenfull.isEnabled && wrapperRef.current) {
screenfull.toggle(wrapperRef.current) screenfull.toggle(wrapperRef.current)
} }
} }
/**
* В обертке могут быть 2 плеера, находим тот который играет сейчас, т.е. не скрыт
*/
const getPlayingVideoElement = () => (
wrapperRef.current?.querySelector('video:not([hidden])') as HTMLVideoElement | null
)
const toggleIOSFullscreen = () => {
const video = getPlayingVideoElement()
if (!video || !supportsFullscreen(video)) return
if (isFullscreen) {
video.webkitExitFullscreen()
} else {
video.webkitEnterFullscreen()
}
}
const onFullscreenClick = () => {
if (isIphone) {
toggleIOSFullscreen()
} else {
toggleFullscreen()
}
}
return { return {
isFullscreen, isFullscreen,
onFullscreenClick, onFullscreenClick,

@ -23,6 +23,7 @@ export type Props = {
onEnded?: (e: SyntheticEvent<HTMLVideoElement>) => void, onEnded?: (e: SyntheticEvent<HTMLVideoElement>) => void,
onError?: (e?: SyntheticEvent<HTMLVideoElement>) => void, onError?: (e?: SyntheticEvent<HTMLVideoElement>) => void,
onLoadedProgress?: (loadedMs: number) => void, onLoadedProgress?: (loadedMs: number) => void,
onPause?: (e: SyntheticEvent<HTMLVideoElement>) => void,
onPlayedProgress?: (playedMs: number) => void, onPlayedProgress?: (playedMs: number) => void,
onReady?: () => void, onReady?: () => void,
playing?: boolean, playing?: boolean,

@ -13,6 +13,7 @@ export const VideoPlayer = forwardRef<HTMLVideoElement, Props>((props: Props, re
muted, muted,
onEnded, onEnded,
onError, onError,
onPause,
src, src,
width, width,
} = props } = props
@ -38,6 +39,7 @@ export const VideoPlayer = forwardRef<HTMLVideoElement, Props>((props: Props, re
onProgress={handleLoadedChange} onProgress={handleLoadedChange}
onEnded={onEnded} onEnded={onEnded}
onDurationChange={handleDurationChange} onDurationChange={handleDurationChange}
onPause={onPause}
onError={onError} onError={onError}
crossOrigin={crossOrigin} crossOrigin={crossOrigin}
/> />

Loading…
Cancel
Save