您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.js 8.0KB

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