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

Conference.js 8.3KB

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