11import React , { useEffect , useMemo , useRef } from 'react' ;
22
33import { MediaComponentVideoProps , MediaVideoType , PlayButtonProps } from '../../../models' ;
4+ import { block } from '../../../utils' ;
45import ReactPlayerBlock from '../../ReactPlayer/ReactPlayer' ;
6+
57import { getVideoTypesWithPriority } from './utils' ;
6- import { block } from '../../../utils' ;
78
89import './Video.scss' ;
910
@@ -21,7 +22,7 @@ interface InnerVideoProps {
2122 hasVideoFallback : boolean ;
2223}
2324
24- type VideoAllProps = VideoAdditionProps & MediaComponentVideoProps & InnerVideoProps ;
25+ export type VideoAllProps = VideoAdditionProps & MediaComponentVideoProps & InnerVideoProps ;
2526
2627const Video = ( props : VideoAllProps ) => {
2728 const {
@@ -47,15 +48,19 @@ const Video = (props: VideoAllProps) => {
4748 if ( loop && typeof loop !== 'boolean' ) {
4849 const { start = 0 , end} = loop ;
4950
50- ref . current . addEventListener ( 'timeupdate' , ( ) => {
51- const videoRef = ref . current ;
52- const endTime = end || ( videoRef && videoRef . duration ) ;
53-
54- if ( videoRef && videoRef . currentTime === endTime ) {
55- videoRef . currentTime = start ;
56- videoRef . play ( ) . catch ( ( ) => setHasVideoFallback ( true ) ) ;
57- }
58- } ) ;
51+ ref . current . addEventListener (
52+ 'timeupdate' ,
53+ ( ) => {
54+ const videoRef = ref . current ;
55+ const endTime = end || ( videoRef && videoRef . duration ) ;
56+
57+ if ( videoRef && videoRef . currentTime === endTime ) {
58+ videoRef . currentTime = start ;
59+ videoRef . play ( ) . catch ( ( ) => setHasVideoFallback ( true ) ) ;
60+ }
61+ } ,
62+ { passive : true } ,
63+ ) ;
5964 }
6065
6166 if ( playVideo ) {
@@ -65,7 +70,17 @@ const Video = (props: VideoAllProps) => {
6570 } , [ playVideo , video , setHasVideoFallback ] ) ;
6671
6772 const reactPlayerBlock = useMemo ( ( ) => {
68- const { src, loop, controls, muted, autoplay = true , elapsedTime, playButton} = video ;
73+ const {
74+ src,
75+ loop,
76+ controls,
77+ muted,
78+ autoplay = true ,
79+ elapsedTime,
80+ playButton,
81+ ariaLabel,
82+ customControlsOptions,
83+ } = video ;
6984
7085 return (
7186 < ReactPlayerBlock
@@ -82,6 +97,8 @@ const Video = (props: VideoAllProps) => {
8297 metrika = { metrika }
8398 analyticsEvents = { analyticsEvents }
8499 height = { height }
100+ ariaLabel = { ariaLabel }
101+ customControlsOptions = { customControlsOptions }
85102 />
86103 ) ;
87104 } , [
@@ -100,14 +117,16 @@ const Video = (props: VideoAllProps) => {
100117 return video . src . length && ! hasVideoFallback ? (
101118 < div className = { b ( 'wrap' , videoClassName ) } style = { { height} } >
102119 < video
103- disablePictureInPicture = { true }
104- playsInline = { true }
120+ disablePictureInPicture
121+ playsInline
105122 // @ts -ignore
123+ // eslint-disable-next-line react/no-unknown-property
106124 pip = "false"
107125 className = { b ( 'item' ) }
108126 ref = { ref }
109127 preload = "metadata"
110- muted = { true }
128+ muted
129+ aria-label = { video . ariaLabel }
111130 >
112131 { getVideoTypesWithPriority ( video . src ) . map ( ( { src, type} , index ) => (
113132 < source key = { index } src = { src } type = { type } />
0 commit comments