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

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