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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.unbindEvents();
  159. FULL_SCREEN_EVENTS.forEach(name =>
  160. document.removeEventListener(name, this._onFullScreenChange));
  161. APP.conference.isJoined() && this.props.dispatch(disconnect());
  162. }
  163. /**
  164. * Implements React's {@link Component#render()}.
  165. *
  166. * @inheritdoc
  167. * @returns {ReactElement}
  168. */
  169. render() {
  170. const {
  171. VIDEO_QUALITY_LABEL_DISABLED,
  172. // XXX The character casing of the name filmStripOnly utilized by
  173. // interfaceConfig is obsolete but legacy support is required.
  174. filmStripOnly: filmstripOnly
  175. } = interfaceConfig;
  176. const hideVideoQualityLabel
  177. = filmstripOnly
  178. || VIDEO_QUALITY_LABEL_DISABLED
  179. || this.props._iAmRecorder;
  180. return (
  181. <div
  182. className = { this.props._layoutClassName }
  183. id = 'videoconference_page'
  184. onMouseMove = { this._onShowToolbar }>
  185. <Notice />
  186. <div id = 'videospace'>
  187. <LargeVideo
  188. hideVideoQualityLabel = { hideVideoQualityLabel } />
  189. <Filmstrip filmstripOnly = { filmstripOnly } />
  190. </div>
  191. { filmstripOnly || <Toolbox /> }
  192. { filmstripOnly || <Chat /> }
  193. <NotificationsContainer />
  194. <CalleeInfoContainer />
  195. </div>
  196. );
  197. }
  198. /**
  199. * Updates the Redux state when full screen mode has been enabled or
  200. * disabled.
  201. *
  202. * @private
  203. * @returns {void}
  204. */
  205. _onFullScreenChange() {
  206. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  207. }
  208. /**
  209. * Displays the toolbar.
  210. *
  211. * @private
  212. * @returns {void}
  213. */
  214. _onShowToolbar() {
  215. this.props.dispatch(showToolbox());
  216. }
  217. /**
  218. * Until we don't rewrite UI using react components
  219. * we use UI.start from old app. Also method translates
  220. * component right after it has been mounted.
  221. *
  222. * @inheritdoc
  223. */
  224. _start() {
  225. APP.UI.start();
  226. APP.UI.registerListeners();
  227. APP.UI.bindEvents();
  228. FULL_SCREEN_EVENTS.forEach(name =>
  229. document.addEventListener(name, this._onFullScreenChange));
  230. const { dispatch, t } = this.props;
  231. dispatch(connect());
  232. maybeShowSuboptimalExperienceNotification(dispatch, t);
  233. interfaceConfig.filmStripOnly
  234. && dispatch(setToolboxAlwaysVisible(true));
  235. }
  236. }
  237. /**
  238. * Maps (parts of) the Redux state to the associated props for the
  239. * {@code Conference} component.
  240. *
  241. * @param {Object} state - The Redux state.
  242. * @private
  243. * @returns {{
  244. * _iAmRecorder: boolean,
  245. * _layoutClassName: string,
  246. * _room: ?string,
  247. * _shouldDisplayTileView: boolean
  248. * }}
  249. */
  250. function _mapStateToProps(state) {
  251. const currentLayout = getCurrentLayout(state);
  252. return {
  253. _iAmRecorder: state['features/base/config'].iAmRecorder,
  254. _layoutClassName: LAYOUT_CLASSNAMES[currentLayout],
  255. _room: state['features/base/conference'].room,
  256. _shouldDisplayTileView: shouldDisplayTileView(state)
  257. };
  258. }
  259. export default reactReduxConnect(_mapStateToProps)(translate(Conference));