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.web.js 8.2KB

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