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

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