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.tsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. // @ts-expect-error
  4. import VideoLayout from '../../../../modules/UI/videolayout/VideoLayout';
  5. import { IReduxState, IStore } from '../../app/types';
  6. import { VIDEO_TYPE } from '../../base/media/constants';
  7. import { getLocalParticipant } from '../../base/participants/functions';
  8. import Watermarks from '../../base/react/components/web/Watermarks';
  9. import { getHideSelfView } from '../../base/settings/functions.any';
  10. import { getVideoTrackByParticipant } from '../../base/tracks/functions.web';
  11. import { setColorAlpha } from '../../base/util/helpers';
  12. import StageParticipantNameLabel from '../../display-name/components/web/StageParticipantNameLabel';
  13. import { FILMSTRIP_BREAKPOINT } from '../../filmstrip/constants';
  14. import { getVerticalViewMaxWidth, isFilmstripResizable } from '../../filmstrip/functions.web';
  15. import SharedVideo from '../../shared-video/components/web/SharedVideo';
  16. import Captions from '../../subtitles/components/web/Captions';
  17. import { setTileView } from '../../video-layout/actions.web';
  18. import Whiteboard from '../../whiteboard/components/web/Whiteboard';
  19. import { isWhiteboardEnabled } from '../../whiteboard/functions';
  20. import { setSeeWhatIsBeingShared } from '../actions.web';
  21. import { getLargeVideoParticipant } from '../functions';
  22. import ScreenSharePlaceholder from './ScreenSharePlaceholder.web';
  23. // Hack to detect Spot.
  24. const SPOT_DISPLAY_NAME = 'Meeting Room';
  25. interface IProps {
  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. * Whether or not the hideSelfView is enabled.
  44. */
  45. _hideSelfView: boolean;
  46. /**
  47. * Prop that indicates whether the chat is open.
  48. */
  49. _isChatOpen: boolean;
  50. /**
  51. * Whether or not the local screen share is on large-video.
  52. */
  53. _isScreenSharing: boolean;
  54. /**
  55. * The large video participant id.
  56. */
  57. _largeVideoParticipantId: string;
  58. /**
  59. * Local Participant id.
  60. */
  61. _localParticipantId: string;
  62. /**
  63. * Used to determine the value of the autoplay attribute of the underlying
  64. * video element.
  65. */
  66. _noAutoPlayVideo: boolean;
  67. /**
  68. * Whether or not the filmstrip is resizable.
  69. */
  70. _resizableFilmstrip: boolean;
  71. /**
  72. * Whether or not the screen sharing is visible.
  73. */
  74. _seeWhatIsBeingShared: boolean;
  75. /**
  76. * Whether or not to show dominant speaker badge.
  77. */
  78. _showDominantSpeakerBadge: boolean;
  79. /**
  80. * The width of the vertical filmstrip (user resized).
  81. */
  82. _verticalFilmstripWidth?: number | null;
  83. /**
  84. * The max width of the vertical filmstrip.
  85. */
  86. _verticalViewMaxWidth: number;
  87. /**
  88. * Whether or not the filmstrip is visible.
  89. */
  90. _visibleFilmstrip: boolean;
  91. /**
  92. * Whether or not the whiteboard is enabled.
  93. */
  94. _whiteboardEnabled: boolean;
  95. /**
  96. * The Redux dispatch function.
  97. */
  98. dispatch: IStore['dispatch'];
  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<IProps> {
  107. _tappedTimeout: number | undefined;
  108. _containerRef: React.RefObject<HTMLDivElement>;
  109. _wrapperRef: React.RefObject<HTMLDivElement>;
  110. /**
  111. * Constructor of the component.
  112. *
  113. * @inheritdoc
  114. */
  115. constructor(props: IProps) {
  116. super(props);
  117. this._containerRef = React.createRef<HTMLDivElement>();
  118. this._wrapperRef = React.createRef<HTMLDivElement>();
  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: IProps) {
  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. /**
  213. * Refreshes the video layout to determine the dimensions of the stage view.
  214. * If the filmstrip is toggled it adds CSS transition classes and removes them
  215. * when the transition is done.
  216. *
  217. * @returns {void}
  218. */
  219. _updateLayout() {
  220. const { _verticalFilmstripWidth, _resizableFilmstrip } = this.props;
  221. if (_resizableFilmstrip && Number(_verticalFilmstripWidth) >= FILMSTRIP_BREAKPOINT) {
  222. this._containerRef.current?.classList.add('transition');
  223. this._wrapperRef.current?.classList.add('transition');
  224. VideoLayout.refreshLayout();
  225. setTimeout(() => {
  226. this._containerRef?.current && this._containerRef.current.classList.remove('transition');
  227. this._wrapperRef?.current && this._wrapperRef.current.classList.remove('transition');
  228. }, 1000);
  229. } else {
  230. VideoLayout.refreshLayout();
  231. }
  232. }
  233. /**
  234. * Clears the '_tappedTimout'.
  235. *
  236. * @private
  237. * @returns {void}
  238. */
  239. _clearTapTimeout() {
  240. clearTimeout(this._tappedTimeout);
  241. this._tappedTimeout = undefined;
  242. }
  243. /**
  244. * Creates the custom styles object.
  245. *
  246. * @private
  247. * @returns {Object}
  248. */
  249. _getCustomStyles() {
  250. const styles: any = {};
  251. const {
  252. _customBackgroundColor,
  253. _customBackgroundImageUrl,
  254. _verticalFilmstripWidth,
  255. _verticalViewMaxWidth,
  256. _visibleFilmstrip
  257. } = this.props;
  258. styles.backgroundColor = _customBackgroundColor || interfaceConfig.DEFAULT_BACKGROUND;
  259. if (this.props._backgroundAlpha !== undefined) {
  260. const alphaColor = setColorAlpha(styles.backgroundColor, this.props._backgroundAlpha);
  261. styles.backgroundColor = alphaColor;
  262. }
  263. if (_customBackgroundImageUrl) {
  264. styles.backgroundImage = `url(${_customBackgroundImageUrl})`;
  265. styles.backgroundSize = 'cover';
  266. }
  267. if (_visibleFilmstrip && Number(_verticalFilmstripWidth) >= FILMSTRIP_BREAKPOINT) {
  268. styles.width = `calc(100% - ${_verticalViewMaxWidth || 0}px)`;
  269. }
  270. return styles;
  271. }
  272. /**
  273. * Sets view to tile view on double tap.
  274. *
  275. * @param {Object} e - The event.
  276. * @private
  277. * @returns {void}
  278. */
  279. _onDoubleTap(e: React.TouchEvent) {
  280. e.stopPropagation();
  281. e.preventDefault();
  282. if (this._tappedTimeout) {
  283. this._clearTapTimeout();
  284. this.props.dispatch(setTileView(true));
  285. } else {
  286. this._tappedTimeout = window.setTimeout(this._clearTapTimeout, 300);
  287. }
  288. }
  289. }
  290. /**
  291. * Maps (parts of) the Redux state to the associated LargeVideo props.
  292. *
  293. * @param {Object} state - The Redux state.
  294. * @private
  295. * @returns {IProps}
  296. */
  297. function _mapStateToProps(state: IReduxState) {
  298. const testingConfig = state['features/base/config'].testing;
  299. const { backgroundColor, backgroundImageUrl } = state['features/dynamic-branding'];
  300. const { isOpen: isChatOpen } = state['features/chat'];
  301. const { width: verticalFilmstripWidth, visible } = state['features/filmstrip'];
  302. const { defaultLocalDisplayName, hideDominantSpeakerBadge } = state['features/base/config'];
  303. const { seeWhatIsBeingShared } = state['features/large-video'];
  304. const localParticipantId = getLocalParticipant(state)?.id;
  305. const largeVideoParticipant = getLargeVideoParticipant(state);
  306. const videoTrack = getVideoTrackByParticipant(state, largeVideoParticipant);
  307. const isLocalScreenshareOnLargeVideo = largeVideoParticipant?.id?.includes(localParticipantId ?? '')
  308. && videoTrack?.videoType === VIDEO_TYPE.DESKTOP;
  309. const isOnSpot = defaultLocalDisplayName === SPOT_DISPLAY_NAME;
  310. return {
  311. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  312. _customBackgroundColor: backgroundColor,
  313. _customBackgroundImageUrl: backgroundImageUrl,
  314. _displayScreenSharingPlaceholder: Boolean(isLocalScreenshareOnLargeVideo && !seeWhatIsBeingShared && !isOnSpot),
  315. _hideSelfView: getHideSelfView(state),
  316. _isChatOpen: isChatOpen,
  317. _isScreenSharing: Boolean(isLocalScreenshareOnLargeVideo),
  318. _largeVideoParticipantId: largeVideoParticipant?.id ?? '',
  319. _localParticipantId: localParticipantId ?? '',
  320. _noAutoPlayVideo: Boolean(testingConfig?.noAutoPlayVideo),
  321. _resizableFilmstrip: isFilmstripResizable(state),
  322. _seeWhatIsBeingShared: Boolean(seeWhatIsBeingShared),
  323. _showDominantSpeakerBadge: !hideDominantSpeakerBadge,
  324. _verticalFilmstripWidth: verticalFilmstripWidth.current,
  325. _verticalViewMaxWidth: getVerticalViewMaxWidth(state),
  326. _visibleFilmstrip: visible,
  327. _whiteboardEnabled: isWhiteboardEnabled(state)
  328. };
  329. }
  330. export default connect(_mapStateToProps)(LargeVideo);