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 7.4KB

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