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.

Conference.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. // @flow
  2. import _ from 'lodash';
  3. import React from 'react';
  4. import VideoLayout from '../../../../../modules/UI/videolayout/VideoLayout';
  5. import { getConferenceNameForTitle } from '../../../base/conference';
  6. import { connect, disconnect } from '../../../base/connection';
  7. import { translate } from '../../../base/i18n';
  8. import { connect as reactReduxConnect } from '../../../base/redux';
  9. import { setColorAlpha } from '../../../base/util';
  10. import { Chat } from '../../../chat';
  11. import { Filmstrip } from '../../../filmstrip';
  12. import { CalleeInfoContainer } from '../../../invite';
  13. import { LargeVideo } from '../../../large-video';
  14. import { KnockingParticipantList, LobbyScreen } from '../../../lobby';
  15. import { Prejoin, isPrejoinPageVisible } from '../../../prejoin';
  16. import { fullScreenChanged, showToolbox } from '../../../toolbox/actions.web';
  17. import { Toolbox } from '../../../toolbox/components/web';
  18. import { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  19. import { maybeShowSuboptimalExperienceNotification } from '../../functions';
  20. import {
  21. AbstractConference,
  22. abstractMapStateToProps
  23. } from '../AbstractConference';
  24. import type { AbstractProps } from '../AbstractConference';
  25. import Labels from './Labels';
  26. import { default as Notice } from './Notice';
  27. declare var APP: Object;
  28. declare var interfaceConfig: Object;
  29. /**
  30. * DOM events for when full screen mode has changed. Different browsers need
  31. * different vendor prefixes.
  32. *
  33. * @private
  34. * @type {Array<string>}
  35. */
  36. const FULL_SCREEN_EVENTS = [
  37. 'webkitfullscreenchange',
  38. 'mozfullscreenchange',
  39. 'fullscreenchange'
  40. ];
  41. /**
  42. * The CSS class to apply to the root element of the conference so CSS can
  43. * modify the app layout.
  44. *
  45. * @private
  46. * @type {Object}
  47. */
  48. const LAYOUT_CLASSNAMES = {
  49. [LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW]: 'horizontal-filmstrip',
  50. [LAYOUTS.TILE_VIEW]: 'tile-view',
  51. [LAYOUTS.VERTICAL_FILMSTRIP_VIEW]: 'vertical-filmstrip'
  52. };
  53. /**
  54. * The type of the React {@code Component} props of {@link Conference}.
  55. */
  56. type Props = AbstractProps & {
  57. /**
  58. * The alpha(opacity) of the background
  59. */
  60. _backgroundAlpha: number,
  61. /**
  62. * Whether the local participant is recording the conference.
  63. */
  64. _iAmRecorder: boolean,
  65. /**
  66. * Returns true if the 'lobby screen' is visible.
  67. */
  68. _isLobbyScreenVisible: boolean,
  69. /**
  70. * The CSS class to apply to the root of {@link Conference} to modify the
  71. * application layout.
  72. */
  73. _layoutClassName: string,
  74. /**
  75. * Name for this conference room.
  76. */
  77. _roomName: string,
  78. /**
  79. * If prejoin page is visible or not.
  80. */
  81. _showPrejoin: boolean,
  82. dispatch: Function,
  83. t: Function
  84. }
  85. /**
  86. * The conference page of the Web application.
  87. */
  88. class Conference extends AbstractConference<Props, *> {
  89. _onFullScreenChange: Function;
  90. _onShowToolbar: Function;
  91. _originalOnShowToolbar: Function;
  92. _setBackground: Function;
  93. /**
  94. * Initializes a new Conference instance.
  95. *
  96. * @param {Object} props - The read-only properties with which the new
  97. * instance is to be initialized.
  98. */
  99. constructor(props) {
  100. super(props);
  101. // Throttle and bind this component's mousemove handler to prevent it
  102. // from firing too often.
  103. this._originalOnShowToolbar = this._onShowToolbar;
  104. this._onShowToolbar = _.throttle(
  105. () => this._originalOnShowToolbar(),
  106. 100,
  107. {
  108. leading: true,
  109. trailing: false
  110. });
  111. // Bind event handler so it is only bound once for every instance.
  112. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  113. this._setBackground = this._setBackground.bind(this);
  114. }
  115. /**
  116. * Start the connection and get the UI ready for the conference.
  117. *
  118. * @inheritdoc
  119. */
  120. componentDidMount() {
  121. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  122. this._start();
  123. }
  124. /**
  125. * Calls into legacy UI to update the application layout, if necessary.
  126. *
  127. * @inheritdoc
  128. * returns {void}
  129. */
  130. componentDidUpdate(prevProps) {
  131. if (this.props._shouldDisplayTileView
  132. === prevProps._shouldDisplayTileView) {
  133. return;
  134. }
  135. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  136. // sizing logic is still handled outside of React. Once all components
  137. // are in react they should calculate size on their own as much as
  138. // possible and pass down sizings.
  139. VideoLayout.refreshLayout();
  140. }
  141. /**
  142. * Disconnect from the conference when component will be
  143. * unmounted.
  144. *
  145. * @inheritdoc
  146. */
  147. componentWillUnmount() {
  148. APP.UI.unbindEvents();
  149. FULL_SCREEN_EVENTS.forEach(name =>
  150. document.removeEventListener(name, this._onFullScreenChange));
  151. APP.conference.isJoined() && this.props.dispatch(disconnect());
  152. }
  153. /**
  154. * Implements React's {@link Component#render()}.
  155. *
  156. * @inheritdoc
  157. * @returns {ReactElement}
  158. */
  159. render() {
  160. const {
  161. _iAmRecorder,
  162. _isLobbyScreenVisible,
  163. _layoutClassName,
  164. _showPrejoin
  165. } = this.props;
  166. const hideLabels = _iAmRecorder;
  167. return (
  168. <div
  169. className = { _layoutClassName }
  170. id = 'videoconference_page'
  171. onMouseMove = { this._onShowToolbar }
  172. ref = { this._setBackground }>
  173. <Notice />
  174. <div id = 'videospace'>
  175. <LargeVideo />
  176. <KnockingParticipantList />
  177. <Filmstrip />
  178. { hideLabels || <Labels /> }
  179. </div>
  180. { _showPrejoin || _isLobbyScreenVisible || <Toolbox /> }
  181. <Chat />
  182. { this.renderNotificationsContainer() }
  183. <CalleeInfoContainer />
  184. { _showPrejoin && <Prejoin />}
  185. </div>
  186. );
  187. }
  188. /**
  189. * Sets custom background opacity based on config. It also applies the
  190. * opacity on parent element, as the parent element is not accessible directly,
  191. * only though it's child.
  192. *
  193. * @param {Object} element - The DOM element for which to apply opacity.
  194. *
  195. * @private
  196. * @returns {void}
  197. */
  198. _setBackground(element) {
  199. if (!element) {
  200. return;
  201. }
  202. if (this.props._backgroundAlpha !== undefined) {
  203. const elemColor = element.style.background;
  204. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  205. element.style.background = alphaElemColor;
  206. if (element.parentElement) {
  207. const parentColor = element.parentElement.style.background;
  208. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  209. element.parentElement.style.background = alphaParentColor;
  210. }
  211. }
  212. }
  213. /**
  214. * Updates the Redux state when full screen mode has been enabled or
  215. * disabled.
  216. *
  217. * @private
  218. * @returns {void}
  219. */
  220. _onFullScreenChange() {
  221. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  222. }
  223. /**
  224. * Displays the toolbar.
  225. *
  226. * @private
  227. * @returns {void}
  228. */
  229. _onShowToolbar() {
  230. this.props.dispatch(showToolbox());
  231. }
  232. /**
  233. * Until we don't rewrite UI using react components
  234. * we use UI.start from old app. Also method translates
  235. * component right after it has been mounted.
  236. *
  237. * @inheritdoc
  238. */
  239. _start() {
  240. APP.UI.start();
  241. APP.UI.registerListeners();
  242. APP.UI.bindEvents();
  243. FULL_SCREEN_EVENTS.forEach(name =>
  244. document.addEventListener(name, this._onFullScreenChange));
  245. const { dispatch, t } = this.props;
  246. dispatch(connect());
  247. maybeShowSuboptimalExperienceNotification(dispatch, t);
  248. }
  249. }
  250. /**
  251. * Maps (parts of) the Redux state to the associated props for the
  252. * {@code Conference} component.
  253. *
  254. * @param {Object} state - The Redux state.
  255. * @private
  256. * @returns {Props}
  257. */
  258. function _mapStateToProps(state) {
  259. return {
  260. ...abstractMapStateToProps(state),
  261. _iAmRecorder: state['features/base/config'].iAmRecorder,
  262. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  263. _isLobbyScreenVisible: state['features/base/dialog']?.component === LobbyScreen,
  264. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state)],
  265. _roomName: getConferenceNameForTitle(state),
  266. _showPrejoin: isPrejoinPageVisible(state)
  267. };
  268. }
  269. export default reactReduxConnect(_mapStateToProps)(translate(Conference));