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

Conference.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. const { configLocation } = config;
  108. if (configLocation) {
  109. obtainConfig(configLocation, this.props._room)
  110. .then(() => {
  111. const now = window.performance.now();
  112. APP.connectionTimes['configuration.fetched'] = now;
  113. logger.log('(TIME) configuration fetched:\t', now);
  114. this._start();
  115. })
  116. .catch(err => {
  117. logger.log(err);
  118. // Show obtain config error.
  119. APP.UI.messageHandler.showError({
  120. descriptionKey: 'dialog.connectError',
  121. titleKey: 'connection.CONNFAIL'
  122. });
  123. });
  124. } else {
  125. this._start();
  126. }
  127. }
  128. /**
  129. * Calls into legacy UI to update the application layout, if necessary.
  130. *
  131. * @inheritdoc
  132. * returns {void}
  133. */
  134. componentDidUpdate(prevProps) {
  135. if (this.props._shouldDisplayTileView
  136. === prevProps._shouldDisplayTileView) {
  137. return;
  138. }
  139. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  140. // sizing logic is still handled outside of React. Once all components
  141. // are in react they should calculate size on their own as much as
  142. // possible and pass down sizings.
  143. VideoLayout.refreshLayout();
  144. }
  145. /**
  146. * Disconnect from the conference when component will be
  147. * unmounted.
  148. *
  149. * @inheritdoc
  150. */
  151. componentWillUnmount() {
  152. APP.UI.unbindEvents();
  153. FULL_SCREEN_EVENTS.forEach(name =>
  154. document.removeEventListener(name, this._onFullScreenChange));
  155. APP.conference.isJoined() && this.props.dispatch(disconnect());
  156. }
  157. /**
  158. * Implements React's {@link Component#render()}.
  159. *
  160. * @inheritdoc
  161. * @returns {ReactElement}
  162. */
  163. render() {
  164. const {
  165. VIDEO_QUALITY_LABEL_DISABLED,
  166. // XXX The character casing of the name filmStripOnly utilized by
  167. // interfaceConfig is obsolete but legacy support is required.
  168. filmStripOnly: filmstripOnly
  169. } = interfaceConfig;
  170. const hideVideoQualityLabel
  171. = filmstripOnly
  172. || VIDEO_QUALITY_LABEL_DISABLED
  173. || this.props._iAmRecorder;
  174. return (
  175. <div
  176. className = { this.props._layoutClassName }
  177. id = 'videoconference_page'
  178. onMouseMove = { this._onShowToolbar }>
  179. <Notice />
  180. <Subject />
  181. <div id = 'videospace'>
  182. <LargeVideo />
  183. { hideVideoQualityLabel
  184. || <Labels /> }
  185. <Filmstrip filmstripOnly = { filmstripOnly } />
  186. </div>
  187. { filmstripOnly || <Toolbox /> }
  188. { filmstripOnly || <Chat /> }
  189. { this.renderNotificationsContainer() }
  190. <CalleeInfoContainer />
  191. </div>
  192. );
  193. }
  194. /**
  195. * Updates the Redux state when full screen mode has been enabled or
  196. * disabled.
  197. *
  198. * @private
  199. * @returns {void}
  200. */
  201. _onFullScreenChange() {
  202. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  203. }
  204. /**
  205. * Displays the toolbar.
  206. *
  207. * @private
  208. * @returns {void}
  209. */
  210. _onShowToolbar() {
  211. this.props.dispatch(showToolbox());
  212. }
  213. /**
  214. * Until we don't rewrite UI using react components
  215. * we use UI.start from old app. Also method translates
  216. * component right after it has been mounted.
  217. *
  218. * @inheritdoc
  219. */
  220. _start() {
  221. APP.UI.start();
  222. APP.UI.registerListeners();
  223. APP.UI.bindEvents();
  224. FULL_SCREEN_EVENTS.forEach(name =>
  225. document.addEventListener(name, this._onFullScreenChange));
  226. const { dispatch, t } = this.props;
  227. dispatch(connect());
  228. maybeShowSuboptimalExperienceNotification(dispatch, t);
  229. interfaceConfig.filmStripOnly
  230. && dispatch(setToolboxAlwaysVisible(true));
  231. }
  232. }
  233. /**
  234. * Maps (parts of) the Redux state to the associated props for the
  235. * {@code Conference} component.
  236. *
  237. * @param {Object} state - The Redux state.
  238. * @private
  239. * @returns {Props}
  240. */
  241. function _mapStateToProps(state) {
  242. const currentLayout = getCurrentLayout(state);
  243. return {
  244. ...abstractMapStateToProps(state),
  245. _iAmRecorder: state['features/base/config'].iAmRecorder,
  246. _layoutClassName: LAYOUT_CLASSNAMES[currentLayout]
  247. };
  248. }
  249. export default reactReduxConnect(_mapStateToProps)(translate(Conference));