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 11KB

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