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.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  15. import {
  16. Toolbox,
  17. fullScreenChanged,
  18. setToolboxAlwaysVisible,
  19. showToolbox
  20. } from '../../../toolbox';
  21. import { maybeShowSuboptimalExperienceNotification } from '../../functions';
  22. import Labels from './Labels';
  23. import { default as Notice } from './Notice';
  24. import { default as Subject } from './Subject';
  25. import { abstractMapStateToProps } from '../AbstractConference';
  26. import type { AbstractProps } from '../AbstractConference';
  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 = AbstractProps & {
  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. dispatch: Function,
  69. t: Function
  70. }
  71. /**
  72. * The conference page of the Web application.
  73. */
  74. class Conference extends Component<Props> {
  75. _onFullScreenChange: Function;
  76. _onShowToolbar: Function;
  77. _originalOnShowToolbar: Function;
  78. /**
  79. * Initializes a new Conference instance.
  80. *
  81. * @param {Object} props - The read-only properties with which the new
  82. * instance is to be initialized.
  83. */
  84. constructor(props) {
  85. super(props);
  86. // Throttle and bind this component's mousemove handler to prevent it
  87. // from firing too often.
  88. this._originalOnShowToolbar = this._onShowToolbar;
  89. this._onShowToolbar = _.throttle(
  90. () => this._originalOnShowToolbar(),
  91. 100,
  92. {
  93. leading: true,
  94. trailing: false
  95. });
  96. // Bind event handler so it is only bound once for every instance.
  97. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  98. }
  99. /**
  100. * Start the connection and get the UI ready for the conference.
  101. *
  102. * @inheritdoc
  103. */
  104. componentDidMount() {
  105. const { configLocation } = config;
  106. if (configLocation) {
  107. obtainConfig(configLocation, this.props._room)
  108. .then(() => {
  109. const now = window.performance.now();
  110. APP.connectionTimes['configuration.fetched'] = now;
  111. logger.log('(TIME) configuration fetched:\t', now);
  112. this._start();
  113. })
  114. .catch(err => {
  115. logger.log(err);
  116. // Show obtain config error.
  117. APP.UI.messageHandler.showError({
  118. descriptionKey: 'dialog.connectError',
  119. titleKey: 'connection.CONNFAIL'
  120. });
  121. });
  122. } else {
  123. this._start();
  124. }
  125. }
  126. /**
  127. * Calls into legacy UI to update the application layout, if necessary.
  128. *
  129. * @inheritdoc
  130. * returns {void}
  131. */
  132. componentDidUpdate(prevProps) {
  133. if (this.props._shouldDisplayTileView
  134. === prevProps._shouldDisplayTileView) {
  135. return;
  136. }
  137. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  138. // sizing logic is still handled outside of React. Once all components
  139. // are in react they should calculate size on their own as much as
  140. // possible and pass down sizings.
  141. VideoLayout.refreshLayout();
  142. }
  143. /**
  144. * Disconnect from the conference when component will be
  145. * unmounted.
  146. *
  147. * @inheritdoc
  148. */
  149. componentWillUnmount() {
  150. APP.UI.unbindEvents();
  151. FULL_SCREEN_EVENTS.forEach(name =>
  152. document.removeEventListener(name, this._onFullScreenChange));
  153. APP.conference.isJoined() && this.props.dispatch(disconnect());
  154. }
  155. /**
  156. * Implements React's {@link Component#render()}.
  157. *
  158. * @inheritdoc
  159. * @returns {ReactElement}
  160. */
  161. render() {
  162. const {
  163. VIDEO_QUALITY_LABEL_DISABLED,
  164. // XXX The character casing of the name filmStripOnly utilized by
  165. // interfaceConfig is obsolete but legacy support is required.
  166. filmStripOnly: filmstripOnly
  167. } = interfaceConfig;
  168. const hideVideoQualityLabel
  169. = filmstripOnly
  170. || VIDEO_QUALITY_LABEL_DISABLED
  171. || this.props._iAmRecorder;
  172. return (
  173. <div
  174. className = { this.props._layoutClassName }
  175. id = 'videoconference_page'
  176. onMouseMove = { this._onShowToolbar }>
  177. <Notice />
  178. <Subject />
  179. <div id = 'videospace'>
  180. <LargeVideo />
  181. { hideVideoQualityLabel
  182. || <Labels /> }
  183. <Filmstrip filmstripOnly = { filmstripOnly } />
  184. </div>
  185. { filmstripOnly || <Toolbox /> }
  186. { filmstripOnly || <Chat /> }
  187. <NotificationsContainer />
  188. <CalleeInfoContainer />
  189. </div>
  190. );
  191. }
  192. /**
  193. * Updates the Redux state when full screen mode has been enabled or
  194. * disabled.
  195. *
  196. * @private
  197. * @returns {void}
  198. */
  199. _onFullScreenChange() {
  200. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  201. }
  202. /**
  203. * Displays the toolbar.
  204. *
  205. * @private
  206. * @returns {void}
  207. */
  208. _onShowToolbar() {
  209. this.props.dispatch(showToolbox());
  210. }
  211. /**
  212. * Until we don't rewrite UI using react components
  213. * we use UI.start from old app. Also method translates
  214. * component right after it has been mounted.
  215. *
  216. * @inheritdoc
  217. */
  218. _start() {
  219. APP.UI.start();
  220. APP.UI.registerListeners();
  221. APP.UI.bindEvents();
  222. FULL_SCREEN_EVENTS.forEach(name =>
  223. document.addEventListener(name, this._onFullScreenChange));
  224. const { dispatch, t } = this.props;
  225. dispatch(connect());
  226. maybeShowSuboptimalExperienceNotification(dispatch, t);
  227. interfaceConfig.filmStripOnly
  228. && dispatch(setToolboxAlwaysVisible(true));
  229. }
  230. }
  231. /**
  232. * Maps (parts of) the Redux state to the associated props for the
  233. * {@code Conference} component.
  234. *
  235. * @param {Object} state - The Redux state.
  236. * @private
  237. * @returns {Props}
  238. */
  239. function _mapStateToProps(state) {
  240. const currentLayout = getCurrentLayout(state);
  241. return {
  242. ...abstractMapStateToProps(state),
  243. _iAmRecorder: state['features/base/config'].iAmRecorder,
  244. _layoutClassName: LAYOUT_CLASSNAMES[currentLayout]
  245. };
  246. }
  247. // $FlowExpectedError
  248. export default reactReduxConnect(_mapStateToProps)(translate(Conference));