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.

LargeVideo.web.js 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. // @flow
  2. import React, { Component } from 'react';
  3. import VideoLayout from '../../../../modules/UI/videolayout/VideoLayout';
  4. import { Watermarks } from '../../base/react';
  5. import { connect } from '../../base/redux';
  6. import { setColorAlpha } from '../../base/util';
  7. import { DominantSpeakerName } from '../../display-name';
  8. import { FILMSTRIP_BREAKPOINT, isFilmstripResizable } from '../../filmstrip';
  9. import { getVerticalViewMaxWidth } from '../../filmstrip/functions.web';
  10. import { SharedVideo } from '../../shared-video/components/web';
  11. import { Captions } from '../../subtitles/';
  12. import { setTileView } from '../../video-layout/actions';
  13. declare var interfaceConfig: Object;
  14. type Props = {
  15. /**
  16. * The alpha(opacity) of the background.
  17. */
  18. _backgroundAlpha: number,
  19. /**
  20. * The user selected background color.
  21. */
  22. _customBackgroundColor: string,
  23. /**
  24. * The user selected background image url.
  25. */
  26. _customBackgroundImageUrl: string,
  27. /**
  28. * Prop that indicates whether the chat is open.
  29. */
  30. _isChatOpen: boolean,
  31. /**
  32. * Used to determine the value of the autoplay attribute of the underlying
  33. * video element.
  34. */
  35. _noAutoPlayVideo: boolean,
  36. /**
  37. * Whether or not the filmstrip is resizable.
  38. */
  39. _resizableFilmstrip: boolean,
  40. /**
  41. * Whether or not to show dominant speaker badge.
  42. */
  43. _showDominantSpeakerBadge: boolean,
  44. /**
  45. * The width of the vertical filmstrip (user resized).
  46. */
  47. _verticalFilmstripWidth: ?number,
  48. /**
  49. * The max width of the vertical filmstrip.
  50. */
  51. _verticalViewMaxWidth: number,
  52. /**
  53. * Whether or not the filmstrip is visible.
  54. */
  55. _visibleFilmstrip: boolean,
  56. /**
  57. * The Redux dispatch function.
  58. */
  59. dispatch: Function
  60. }
  61. /** .
  62. * Implements a React {@link Component} which represents the large video (a.k.a.
  63. * The conference participant who is on the local stage) on Web/React.
  64. *
  65. * @augments Component
  66. */
  67. class LargeVideo extends Component<Props> {
  68. _tappedTimeout: ?TimeoutID;
  69. _containerRef: Object;
  70. _wrapperRef: Object;
  71. /**
  72. * Constructor of the component.
  73. *
  74. * @inheritdoc
  75. */
  76. constructor(props) {
  77. super(props);
  78. this._containerRef = React.createRef();
  79. this._wrapperRef = React.createRef();
  80. this._clearTapTimeout = this._clearTapTimeout.bind(this);
  81. this._onDoubleTap = this._onDoubleTap.bind(this);
  82. this._updateLayout = this._updateLayout.bind(this);
  83. }
  84. /**
  85. * Implements {@code Component#componentDidUpdate}.
  86. *
  87. * @inheritdoc
  88. */
  89. componentDidUpdate(prevProps: Props) {
  90. const { _visibleFilmstrip } = this.props;
  91. if (prevProps._visibleFilmstrip !== _visibleFilmstrip) {
  92. this._updateLayout();
  93. }
  94. }
  95. /**
  96. * Implements React's {@link Component#render()}.
  97. *
  98. * @inheritdoc
  99. * @returns {React$Element}
  100. */
  101. render() {
  102. const {
  103. _isChatOpen,
  104. _noAutoPlayVideo,
  105. _showDominantSpeakerBadge
  106. } = this.props;
  107. const style = this._getCustomSyles();
  108. const className = `videocontainer${_isChatOpen ? ' shift-right' : ''}`;
  109. return (
  110. <div
  111. className = { className }
  112. id = 'largeVideoContainer'
  113. ref = { this._containerRef }
  114. style = { style }>
  115. <SharedVideo />
  116. <div id = 'etherpad' />
  117. <Watermarks />
  118. <div
  119. id = 'dominantSpeaker'
  120. onTouchEnd = { this._onDoubleTap }>
  121. <div className = 'dynamic-shadow' />
  122. <div id = 'dominantSpeakerAvatarContainer' />
  123. </div>
  124. <div id = 'remotePresenceMessage' />
  125. <span id = 'remoteConnectionMessage' />
  126. <div id = 'largeVideoElementsContainer'>
  127. <div id = 'largeVideoBackgroundContainer' />
  128. {/*
  129. * FIXME: the architecture of elements related to the large
  130. * video and the naming. The background is not part of
  131. * largeVideoWrapper because we are controlling the size of
  132. * the video through largeVideoWrapper. That's why we need
  133. * another container for the background and the
  134. * largeVideoWrapper in order to hide/show them.
  135. */}
  136. <div
  137. id = 'largeVideoWrapper'
  138. onTouchEnd = { this._onDoubleTap }
  139. ref = { this._wrapperRef }
  140. role = 'figure' >
  141. <video
  142. autoPlay = { !_noAutoPlayVideo }
  143. id = 'largeVideo'
  144. muted = { true }
  145. playsInline = { true } /* for Safari on iOS to work */ />
  146. </div>
  147. </div>
  148. { interfaceConfig.DISABLE_TRANSCRIPTION_SUBTITLES
  149. || <Captions /> }
  150. {_showDominantSpeakerBadge && <DominantSpeakerName />}
  151. </div>
  152. );
  153. }
  154. _updateLayout: () => void;
  155. /**
  156. * Refreshes the video layout to determine the dimensions of the stage view.
  157. * If the filmstrip is toggled it adds CSS transition classes and removes them
  158. * when the transition is done.
  159. *
  160. * @returns {void}
  161. */
  162. _updateLayout() {
  163. const { _verticalFilmstripWidth, _resizableFilmstrip } = this.props;
  164. if (_resizableFilmstrip && _verticalFilmstripWidth >= FILMSTRIP_BREAKPOINT) {
  165. this._containerRef.current.classList.add('transition');
  166. this._wrapperRef.current.classList.add('transition');
  167. VideoLayout.refreshLayout();
  168. setTimeout(() => {
  169. this._containerRef.current && this._containerRef.current.classList.remove('transition');
  170. this._wrapperRef.current && this._wrapperRef.current.classList.remove('transition');
  171. }, 1000);
  172. } else {
  173. VideoLayout.refreshLayout();
  174. }
  175. }
  176. _clearTapTimeout: () => void;
  177. /**
  178. * Clears the '_tappedTimout'.
  179. *
  180. * @private
  181. * @returns {void}
  182. */
  183. _clearTapTimeout() {
  184. clearTimeout(this._tappedTimeout);
  185. this._tappedTimeout = undefined;
  186. }
  187. /**
  188. * Creates the custom styles object.
  189. *
  190. * @private
  191. * @returns {Object}
  192. */
  193. _getCustomSyles() {
  194. const styles = {};
  195. const {
  196. _customBackgroundColor,
  197. _customBackgroundImageUrl,
  198. _verticalFilmstripWidth,
  199. _verticalViewMaxWidth,
  200. _visibleFilmstrip
  201. } = this.props;
  202. styles.backgroundColor = _customBackgroundColor || interfaceConfig.DEFAULT_BACKGROUND;
  203. if (this.props._backgroundAlpha !== undefined) {
  204. const alphaColor = setColorAlpha(styles.backgroundColor, this.props._backgroundAlpha);
  205. styles.backgroundColor = alphaColor;
  206. }
  207. if (_customBackgroundImageUrl) {
  208. styles.backgroundImage = `url(${_customBackgroundImageUrl})`;
  209. styles.backgroundSize = 'cover';
  210. }
  211. if (_visibleFilmstrip && _verticalFilmstripWidth >= FILMSTRIP_BREAKPOINT) {
  212. styles.width = `calc(100% - ${_verticalViewMaxWidth || 0}px)`;
  213. }
  214. return styles;
  215. }
  216. _onDoubleTap: () => void;
  217. /**
  218. * Sets view to tile view on double tap.
  219. *
  220. * @param {Object} e - The event.
  221. * @private
  222. * @returns {void}
  223. */
  224. _onDoubleTap(e) {
  225. e.stopPropagation();
  226. e.preventDefault();
  227. if (this._tappedTimeout) {
  228. this._clearTapTimeout();
  229. this.props.dispatch(setTileView(true));
  230. } else {
  231. this._tappedTimeout = setTimeout(this._clearTapTimeout, 300);
  232. }
  233. }
  234. }
  235. /**
  236. * Maps (parts of) the Redux state to the associated LargeVideo props.
  237. *
  238. * @param {Object} state - The Redux state.
  239. * @private
  240. * @returns {Props}
  241. */
  242. function _mapStateToProps(state) {
  243. const testingConfig = state['features/base/config'].testing;
  244. const { backgroundColor, backgroundImageUrl } = state['features/dynamic-branding'];
  245. const { isOpen: isChatOpen } = state['features/chat'];
  246. const { width: verticalFilmstripWidth, visible } = state['features/filmstrip'];
  247. const { hideDominantSpeakerBadge } = state['features/base/config'];
  248. return {
  249. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  250. _customBackgroundColor: backgroundColor,
  251. _customBackgroundImageUrl: backgroundImageUrl,
  252. _isChatOpen: isChatOpen,
  253. _noAutoPlayVideo: testingConfig?.noAutoPlayVideo,
  254. _resizableFilmstrip: isFilmstripResizable(state),
  255. _showDominantSpeakerBadge: !hideDominantSpeakerBadge,
  256. _verticalFilmstripWidth: verticalFilmstripWidth.current,
  257. _verticalViewMaxWidth: getVerticalViewMaxWidth(state),
  258. _visibleFilmstrip: visible
  259. };
  260. }
  261. export default connect(_mapStateToProps)(LargeVideo);