You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoTrack.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* @flow */
  2. import React from 'react';
  3. import { connect } from '../../../redux';
  4. import AbstractVideoTrack from '../AbstractVideoTrack';
  5. import type { Props as AbstractVideoTrackProps } from '../AbstractVideoTrack';
  6. import Video from './Video';
  7. /**
  8. * The type of the React {@code Component} props of {@link VideoTrack}.
  9. */
  10. type Props = AbstractVideoTrackProps & {
  11. /**
  12. * CSS classes to add to the video element.
  13. */
  14. className: string,
  15. /**
  16. * The value of the id attribute of the video. Used by the torture tests
  17. * to locate video elements.
  18. */
  19. id: string,
  20. /**
  21. *
  22. * Used to determine the value of the autoplay attribute of the underlying
  23. * video element.
  24. */
  25. _noAutoPlayVideo: boolean,
  26. /**
  27. * A map of the event handlers for the video HTML element.
  28. */
  29. eventHandlers?: {|
  30. /**
  31. * onAbort event handler.
  32. */
  33. onAbort?: ?Function,
  34. /**
  35. * onCanPlay event handler.
  36. */
  37. onCanPlay?: ?Function,
  38. /**
  39. * onCanPlayThrough event handler.
  40. */
  41. onCanPlayThrough?: ?Function,
  42. /**
  43. * onEmptied event handler.
  44. */
  45. onEmptied?: ?Function,
  46. /**
  47. * onEnded event handler.
  48. */
  49. onEnded?: ?Function,
  50. /**
  51. * onError event handler.
  52. */
  53. onError?: ?Function,
  54. /**
  55. * onLoadedData event handler.
  56. */
  57. onLoadedData?: ?Function,
  58. /**
  59. * onLoadedMetadata event handler.
  60. */
  61. onLoadedMetadata?: ?Function,
  62. /**
  63. * onLoadStart event handler.
  64. */
  65. onLoadStart?: ?Function,
  66. /**
  67. * onPause event handler.
  68. */
  69. onPause?: ?Function,
  70. /**
  71. * onPlay event handler.
  72. */
  73. onPlay?: ?Function,
  74. /**
  75. * onPlaying event handler.
  76. */
  77. onPlaying?: ?Function,
  78. /**
  79. * onRateChange event handler.
  80. */
  81. onRateChange?: ?Function,
  82. /**
  83. * onStalled event handler.
  84. */
  85. onStalled?: ?Function,
  86. /**
  87. * onSuspend event handler.
  88. */
  89. onSuspend?: ?Function,
  90. /**
  91. * onWaiting event handler.
  92. */
  93. onWaiting?: ?Function,
  94. |},
  95. /**
  96. * A styles that will be applied on the video element.
  97. */
  98. style: Object,
  99. /**
  100. * The value of the muted attribute for the underlying element.
  101. */
  102. muted?: boolean
  103. };
  104. /**
  105. * Component that renders a video element for a passed in video track and
  106. * notifies the store when the video has started playing.
  107. *
  108. * @extends AbstractVideoTrack
  109. */
  110. class VideoTrack extends AbstractVideoTrack<Props> {
  111. /**
  112. * Default values for {@code VideoTrack} component's properties.
  113. *
  114. * @static
  115. */
  116. static defaultProps = {
  117. className: '',
  118. id: ''
  119. };
  120. /**
  121. * Renders the video element.
  122. *
  123. * @override
  124. * @returns {ReactElement}
  125. */
  126. render() {
  127. const {
  128. _noAutoPlayVideo,
  129. className,
  130. id,
  131. muted,
  132. videoTrack,
  133. style,
  134. eventHandlers
  135. } = this.props;
  136. return (
  137. <Video
  138. autoPlay = { !_noAutoPlayVideo }
  139. className = { className }
  140. eventHandlers = { eventHandlers }
  141. id = { id }
  142. muted = { muted }
  143. onVideoPlaying = { this._onVideoPlaying }
  144. style = { style }
  145. videoTrack = { videoTrack } />
  146. );
  147. }
  148. _onVideoPlaying: () => void;
  149. }
  150. /**
  151. * Maps (parts of) the Redux state to the associated VideoTracks props.
  152. *
  153. * @param {Object} state - The Redux state.
  154. * @private
  155. * @returns {{
  156. * _noAutoPlayVideo: boolean
  157. * }}
  158. */
  159. function _mapStateToProps(state) {
  160. const testingConfig = state['features/base/config'].testing;
  161. return {
  162. _noAutoPlayVideo: testingConfig?.noAutoPlayVideo
  163. };
  164. }
  165. export default connect(_mapStateToProps)(VideoTrack);