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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // @flow
  2. import React, { Component } from 'react';
  3. import VideoLayout from '../../../../modules/UI/videolayout/VideoLayout';
  4. import { getMultipleVideoSupportFeatureFlag } from '../../base/config';
  5. import { MEDIA_TYPE, VIDEO_TYPE } from '../../base/media';
  6. import { getLocalParticipant, isScreenShareParticipant } from '../../base/participants';
  7. import { Watermarks } from '../../base/react';
  8. import { connect } from '../../base/redux';
  9. import { getTrackByMediaTypeAndParticipant, getVirtualScreenshareParticipantTrack } 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. * The Redux dispatch function.
  89. */
  90. dispatch: Function
  91. }
  92. /** .
  93. * Implements a React {@link Component} which represents the large video (a.k.a.
  94. * The conference participant who is on the local stage) on Web/React.
  95. *
  96. * @augments Component
  97. */
  98. class LargeVideo extends Component<Props> {
  99. _tappedTimeout: ?TimeoutID;
  100. _containerRef: Object;
  101. _wrapperRef: Object;
  102. /**
  103. * Constructor of the component.
  104. *
  105. * @inheritdoc
  106. */
  107. constructor(props) {
  108. super(props);
  109. this._containerRef = React.createRef();
  110. this._wrapperRef = React.createRef();
  111. this._clearTapTimeout = this._clearTapTimeout.bind(this);
  112. this._onDoubleTap = this._onDoubleTap.bind(this);
  113. this._updateLayout = this._updateLayout.bind(this);
  114. }
  115. /**
  116. * Implements {@code Component#componentDidUpdate}.
  117. *
  118. * @inheritdoc
  119. */
  120. componentDidUpdate(prevProps: Props) {
  121. const { _visibleFilmstrip, _isScreenSharing, _seeWhatIsBeingShared, _largeVideoParticipantId } = this.props;
  122. if (prevProps._visibleFilmstrip !== _visibleFilmstrip) {
  123. this._updateLayout();
  124. }
  125. if (prevProps._isScreenSharing !== _isScreenSharing && !_isScreenSharing) {
  126. this.props.dispatch(setSeeWhatIsBeingShared(false));
  127. }
  128. if (_isScreenSharing && _seeWhatIsBeingShared) {
  129. VideoLayout.updateLargeVideo(_largeVideoParticipantId, true, true);
  130. }
  131. }
  132. /**
  133. * Implements React's {@link Component#render()}.
  134. *
  135. * @inheritdoc
  136. * @returns {React$Element}
  137. */
  138. render() {
  139. const {
  140. _displayScreenSharingPlaceholder,
  141. _isChatOpen,
  142. _noAutoPlayVideo,
  143. _showDominantSpeakerBadge,
  144. _whiteboardEnabled
  145. } = this.props;
  146. const style = this._getCustomStyles();
  147. const className = `videocontainer${_isChatOpen ? ' shift-right' : ''}`;
  148. return (
  149. <div
  150. className = { className }
  151. id = 'largeVideoContainer'
  152. ref = { this._containerRef }
  153. style = { style }>
  154. <SharedVideo />
  155. {_whiteboardEnabled && <Whiteboard />}
  156. <div id = 'etherpad' />
  157. <Watermarks />
  158. <div
  159. id = 'dominantSpeaker'
  160. onTouchEnd = { this._onDoubleTap }>
  161. <div className = 'dynamic-shadow' />
  162. <div id = 'dominantSpeakerAvatarContainer' />
  163. </div>
  164. <div id = 'remotePresenceMessage' />
  165. <span id = 'remoteConnectionMessage' />
  166. <div id = 'largeVideoElementsContainer'>
  167. <div id = 'largeVideoBackgroundContainer' />
  168. {/*
  169. * FIXME: the architecture of elements related to the large
  170. * video and the naming. The background is not part of
  171. * largeVideoWrapper because we are controlling the size of
  172. * the video through largeVideoWrapper. That's why we need
  173. * another container for the background and the
  174. * largeVideoWrapper in order to hide/show them.
  175. */}
  176. <div
  177. id = 'largeVideoWrapper'
  178. onTouchEnd = { this._onDoubleTap }
  179. ref = { this._wrapperRef }
  180. role = 'figure' >
  181. { _displayScreenSharingPlaceholder ? <ScreenSharePlaceholder /> : <video
  182. autoPlay = { !_noAutoPlayVideo }
  183. id = 'largeVideo'
  184. muted = { true }
  185. playsInline = { true } /* for Safari on iOS to work */ /> }
  186. </div>
  187. </div>
  188. { interfaceConfig.DISABLE_TRANSCRIPTION_SUBTITLES
  189. || <Captions /> }
  190. {_showDominantSpeakerBadge && <StageParticipantNameLabel />}
  191. </div>
  192. );
  193. }
  194. _updateLayout: () => void;
  195. /**
  196. * Refreshes the video layout to determine the dimensions of the stage view.
  197. * If the filmstrip is toggled it adds CSS transition classes and removes them
  198. * when the transition is done.
  199. *
  200. * @returns {void}
  201. */
  202. _updateLayout() {
  203. const { _verticalFilmstripWidth, _resizableFilmstrip } = this.props;
  204. if (_resizableFilmstrip && _verticalFilmstripWidth >= FILMSTRIP_BREAKPOINT) {
  205. this._containerRef.current.classList.add('transition');
  206. this._wrapperRef.current.classList.add('transition');
  207. VideoLayout.refreshLayout();
  208. setTimeout(() => {
  209. this._containerRef.current && this._containerRef.current.classList.remove('transition');
  210. this._wrapperRef.current && this._wrapperRef.current.classList.remove('transition');
  211. }, 1000);
  212. } else {
  213. VideoLayout.refreshLayout();
  214. }
  215. }
  216. _clearTapTimeout: () => void;
  217. /**
  218. * Clears the '_tappedTimout'.
  219. *
  220. * @private
  221. * @returns {void}
  222. */
  223. _clearTapTimeout() {
  224. clearTimeout(this._tappedTimeout);
  225. this._tappedTimeout = undefined;
  226. }
  227. /**
  228. * Creates the custom styles object.
  229. *
  230. * @private
  231. * @returns {Object}
  232. */
  233. _getCustomStyles() {
  234. const styles = {};
  235. const {
  236. _customBackgroundColor,
  237. _customBackgroundImageUrl,
  238. _verticalFilmstripWidth,
  239. _verticalViewMaxWidth,
  240. _visibleFilmstrip
  241. } = this.props;
  242. styles.backgroundColor = _customBackgroundColor || interfaceConfig.DEFAULT_BACKGROUND;
  243. if (this.props._backgroundAlpha !== undefined) {
  244. const alphaColor = setColorAlpha(styles.backgroundColor, this.props._backgroundAlpha);
  245. styles.backgroundColor = alphaColor;
  246. }
  247. if (_customBackgroundImageUrl) {
  248. styles.backgroundImage = `url(${_customBackgroundImageUrl})`;
  249. styles.backgroundSize = 'cover';
  250. }
  251. if (_visibleFilmstrip && _verticalFilmstripWidth >= FILMSTRIP_BREAKPOINT) {
  252. styles.width = `calc(100% - ${_verticalViewMaxWidth || 0}px)`;
  253. }
  254. return styles;
  255. }
  256. _onDoubleTap: () => void;
  257. /**
  258. * Sets view to tile view on double tap.
  259. *
  260. * @param {Object} e - The event.
  261. * @private
  262. * @returns {void}
  263. */
  264. _onDoubleTap(e) {
  265. e.stopPropagation();
  266. e.preventDefault();
  267. if (this._tappedTimeout) {
  268. this._clearTapTimeout();
  269. this.props.dispatch(setTileView(true));
  270. } else {
  271. this._tappedTimeout = setTimeout(this._clearTapTimeout, 300);
  272. }
  273. }
  274. }
  275. /**
  276. * Maps (parts of) the Redux state to the associated LargeVideo props.
  277. *
  278. * @param {Object} state - The Redux state.
  279. * @private
  280. * @returns {Props}
  281. */
  282. function _mapStateToProps(state) {
  283. const testingConfig = state['features/base/config'].testing;
  284. const { backgroundColor, backgroundImageUrl } = state['features/dynamic-branding'];
  285. const { isOpen: isChatOpen } = state['features/chat'];
  286. const { width: verticalFilmstripWidth, visible } = state['features/filmstrip'];
  287. const { defaultLocalDisplayName, hideDominantSpeakerBadge } = state['features/base/config'];
  288. const { seeWhatIsBeingShared } = state['features/large-video'];
  289. const tracks = state['features/base/tracks'];
  290. const localParticipantId = getLocalParticipant(state)?.id;
  291. const largeVideoParticipant = getLargeVideoParticipant(state);
  292. let videoTrack;
  293. if (getMultipleVideoSupportFeatureFlag(state) && isScreenShareParticipant(largeVideoParticipant)) {
  294. videoTrack = getVirtualScreenshareParticipantTrack(tracks, largeVideoParticipant?.id);
  295. } else {
  296. videoTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideoParticipant?.id);
  297. }
  298. const isLocalScreenshareOnLargeVideo = largeVideoParticipant?.id?.includes(localParticipantId)
  299. && videoTrack?.videoType === VIDEO_TYPE.DESKTOP;
  300. const isOnSpot = defaultLocalDisplayName === SPOT_DISPLAY_NAME;
  301. return {
  302. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  303. _customBackgroundColor: backgroundColor,
  304. _customBackgroundImageUrl: backgroundImageUrl,
  305. _displayScreenSharingPlaceholder: isLocalScreenshareOnLargeVideo && !seeWhatIsBeingShared && !isOnSpot,
  306. _isChatOpen: isChatOpen,
  307. _isScreenSharing: isLocalScreenshareOnLargeVideo,
  308. _largeVideoParticipantId: largeVideoParticipant?.id,
  309. _noAutoPlayVideo: testingConfig?.noAutoPlayVideo,
  310. _resizableFilmstrip: isFilmstripResizable(state),
  311. _seeWhatIsBeingShared: seeWhatIsBeingShared,
  312. _showDominantSpeakerBadge: !hideDominantSpeakerBadge,
  313. _verticalFilmstripWidth: verticalFilmstripWidth.current,
  314. _verticalViewMaxWidth: getVerticalViewMaxWidth(state),
  315. _visibleFilmstrip: visible,
  316. _whiteboardEnabled: isWhiteboardEnabled(state)
  317. };
  318. }
  319. export default connect(_mapStateToProps)(LargeVideo);