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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 ConferenceInfo from './ConferenceInfo';
  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. * Returns true if the 'lobby screen' is visible.
  63. */
  64. _isLobbyScreenVisible: boolean,
  65. /**
  66. * The CSS class to apply to the root of {@link Conference} to modify the
  67. * application layout.
  68. */
  69. _layoutClassName: string,
  70. /**
  71. * Name for this conference room.
  72. */
  73. _roomName: string,
  74. /**
  75. * If prejoin page is visible or not.
  76. */
  77. _showPrejoin: boolean,
  78. dispatch: Function,
  79. t: Function
  80. }
  81. /**
  82. * The conference page of the Web application.
  83. */
  84. class Conference extends AbstractConference<Props, *> {
  85. _onFullScreenChange: Function;
  86. _onShowToolbar: Function;
  87. _originalOnShowToolbar: Function;
  88. _setBackground: Function;
  89. /**
  90. * Initializes a new Conference instance.
  91. *
  92. * @param {Object} props - The read-only properties with which the new
  93. * instance is to be initialized.
  94. */
  95. constructor(props) {
  96. super(props);
  97. // Throttle and bind this component's mousemove handler to prevent it
  98. // from firing too often.
  99. this._originalOnShowToolbar = this._onShowToolbar;
  100. this._onShowToolbar = _.throttle(
  101. () => this._originalOnShowToolbar(),
  102. 100,
  103. {
  104. leading: true,
  105. trailing: false
  106. });
  107. // Bind event handler so it is only bound once for every instance.
  108. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  109. this._setBackground = this._setBackground.bind(this);
  110. }
  111. /**
  112. * Start the connection and get the UI ready for the conference.
  113. *
  114. * @inheritdoc
  115. */
  116. componentDidMount() {
  117. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  118. this._start();
  119. }
  120. /**
  121. * Calls into legacy UI to update the application layout, if necessary.
  122. *
  123. * @inheritdoc
  124. * returns {void}
  125. */
  126. componentDidUpdate(prevProps) {
  127. if (this.props._shouldDisplayTileView
  128. === prevProps._shouldDisplayTileView) {
  129. return;
  130. }
  131. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  132. // sizing logic is still handled outside of React. Once all components
  133. // are in react they should calculate size on their own as much as
  134. // possible and pass down sizings.
  135. VideoLayout.refreshLayout();
  136. }
  137. /**
  138. * Disconnect from the conference when component will be
  139. * unmounted.
  140. *
  141. * @inheritdoc
  142. */
  143. componentWillUnmount() {
  144. APP.UI.unbindEvents();
  145. FULL_SCREEN_EVENTS.forEach(name =>
  146. document.removeEventListener(name, this._onFullScreenChange));
  147. APP.conference.isJoined() && this.props.dispatch(disconnect());
  148. }
  149. /**
  150. * Implements React's {@link Component#render()}.
  151. *
  152. * @inheritdoc
  153. * @returns {ReactElement}
  154. */
  155. render() {
  156. const {
  157. _isLobbyScreenVisible,
  158. _layoutClassName,
  159. _showPrejoin
  160. } = this.props;
  161. return (
  162. <div
  163. className = { _layoutClassName }
  164. id = 'videoconference_page'
  165. onMouseMove = { this._onShowToolbar }
  166. ref = { this._setBackground }>
  167. <ConferenceInfo />
  168. <Notice />
  169. <div id = 'videospace'>
  170. <LargeVideo />
  171. <KnockingParticipantList />
  172. <Filmstrip />
  173. </div>
  174. { _showPrejoin || _isLobbyScreenVisible || <Toolbox /> }
  175. <Chat />
  176. { this.renderNotificationsContainer() }
  177. <CalleeInfoContainer />
  178. { _showPrejoin && <Prejoin />}
  179. </div>
  180. );
  181. }
  182. /**
  183. * Sets custom background opacity based on config. It also applies the
  184. * opacity on parent element, as the parent element is not accessible directly,
  185. * only though it's child.
  186. *
  187. * @param {Object} element - The DOM element for which to apply opacity.
  188. *
  189. * @private
  190. * @returns {void}
  191. */
  192. _setBackground(element) {
  193. if (!element) {
  194. return;
  195. }
  196. if (this.props._backgroundAlpha !== undefined) {
  197. const elemColor = element.style.background;
  198. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  199. element.style.background = alphaElemColor;
  200. if (element.parentElement) {
  201. const parentColor = element.parentElement.style.background;
  202. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  203. element.parentElement.style.background = alphaParentColor;
  204. }
  205. }
  206. }
  207. /**
  208. * Updates the Redux state when full screen mode has been enabled or
  209. * disabled.
  210. *
  211. * @private
  212. * @returns {void}
  213. */
  214. _onFullScreenChange() {
  215. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  216. }
  217. /**
  218. * Displays the toolbar.
  219. *
  220. * @private
  221. * @returns {void}
  222. */
  223. _onShowToolbar() {
  224. this.props.dispatch(showToolbox());
  225. }
  226. /**
  227. * Until we don't rewrite UI using react components
  228. * we use UI.start from old app. Also method translates
  229. * component right after it has been mounted.
  230. *
  231. * @inheritdoc
  232. */
  233. _start() {
  234. APP.UI.start();
  235. APP.UI.registerListeners();
  236. APP.UI.bindEvents();
  237. FULL_SCREEN_EVENTS.forEach(name =>
  238. document.addEventListener(name, this._onFullScreenChange));
  239. const { dispatch, t } = this.props;
  240. dispatch(connect());
  241. maybeShowSuboptimalExperienceNotification(dispatch, t);
  242. }
  243. }
  244. /**
  245. * Maps (parts of) the Redux state to the associated props for the
  246. * {@code Conference} component.
  247. *
  248. * @param {Object} state - The Redux state.
  249. * @private
  250. * @returns {Props}
  251. */
  252. function _mapStateToProps(state) {
  253. return {
  254. ...abstractMapStateToProps(state),
  255. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  256. _isLobbyScreenVisible: state['features/base/dialog']?.component === LobbyScreen,
  257. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state)],
  258. _roomName: getConferenceNameForTitle(state),
  259. _showPrejoin: isPrejoinPageVisible(state)
  260. };
  261. }
  262. export default reactReduxConnect(_mapStateToProps)(translate(Conference));