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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. * Promise wrapper on obtain config method. When HttpConfigFetch will be moved
  27. * to React app it's better to use load config instead.
  28. *
  29. * @param {string} location - URL of the domain from which the config is to be
  30. * obtained.
  31. * @param {string} room - Room name.
  32. * @private
  33. * @returns {Promise}
  34. */
  35. function _obtainConfig(location: string, room: string) {
  36. return new Promise((resolve, reject) =>
  37. obtainConfig(location, room, (success, error) => {
  38. success ? resolve() : reject(error);
  39. })
  40. );
  41. }
  42. /**
  43. * DOM events for when full screen mode has changed. Different browsers need
  44. * different vendor prefixes.
  45. *
  46. * @private
  47. * @type {Array<string>}
  48. */
  49. const FULL_SCREEN_EVENTS = [
  50. 'webkitfullscreenchange',
  51. 'mozfullscreenchange',
  52. 'fullscreenchange'
  53. ];
  54. /**
  55. * The type of the React {@code Component} props of {@link Conference}.
  56. */
  57. type Props = {
  58. /**
  59. * Whether the local participant is recording the conference.
  60. */
  61. _iAmRecorder: boolean,
  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. titleKey: 'connection.CONNFAIL',
  117. descriptionKey: 'dialog.connectError'
  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. id = 'videoconference_page'
  157. onMouseMove = { this._onShowToolbar }>
  158. <div id = 'videospace'>
  159. <LargeVideo
  160. hideVideoQualityLabel = { hideVideoQualityLabel } />
  161. <Filmstrip filmstripOnly = { filmstripOnly } />
  162. </div>
  163. { filmstripOnly || <Toolbox /> }
  164. { filmstripOnly || <SidePanel /> }
  165. <DialogContainer />
  166. <NotificationsContainer />
  167. <CalleeInfoContainer />
  168. </div>
  169. );
  170. }
  171. /**
  172. * Updates the Redux state when full screen mode has been enabled or
  173. * disabled.
  174. *
  175. * @private
  176. * @returns {void}
  177. */
  178. _onFullScreenChange() {
  179. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  180. }
  181. /**
  182. * Displays the toolbar.
  183. *
  184. * @private
  185. * @returns {void}
  186. */
  187. _onShowToolbar() {
  188. this.props.dispatch(showToolbox());
  189. }
  190. /**
  191. * Until we don't rewrite UI using react components
  192. * we use UI.start from old app. Also method translates
  193. * component right after it has been mounted.
  194. *
  195. * @inheritdoc
  196. */
  197. _start() {
  198. APP.UI.start();
  199. APP.UI.registerListeners();
  200. APP.UI.bindEvents();
  201. FULL_SCREEN_EVENTS.forEach(name =>
  202. document.addEventListener(name, this._onFullScreenChange));
  203. const { dispatch, t } = this.props;
  204. dispatch(connect());
  205. maybeShowSuboptimalExperienceNotification(dispatch, t);
  206. interfaceConfig.filmStripOnly
  207. && dispatch(setToolboxAlwaysVisible(true));
  208. }
  209. }
  210. /**
  211. * Maps (parts of) the Redux state to the associated props for the
  212. * {@code Conference} component.
  213. *
  214. * @param {Object} state - The Redux state.
  215. * @private
  216. * @returns {{
  217. * _iAmRecorder: boolean
  218. * }}
  219. */
  220. function _mapStateToProps(state) {
  221. const { room } = state['features/base/conference'];
  222. const { iAmRecorder } = state['features/base/config'];
  223. return {
  224. /**
  225. * Whether the local participant is recording the conference.
  226. *
  227. * @private
  228. */
  229. _iAmRecorder: iAmRecorder,
  230. /**
  231. * Conference room name.
  232. */
  233. _room: room
  234. };
  235. }
  236. export default reactReduxConnect(_mapStateToProps)(translate(Conference));