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

Conference.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // @flow
  2. import _ from 'lodash';
  3. import React from 'react';
  4. import VideoLayout from '../../../../../modules/UI/videolayout/VideoLayout';
  5. import { getConferenceNameForTitle } from '../../../base/conference';
  6. import { connect, disconnect } from '../../../base/connection';
  7. import { translate } from '../../../base/i18n';
  8. import { connect as reactReduxConnect } from '../../../base/redux';
  9. import { setColorAlpha } from '../../../base/util';
  10. import { Chat } from '../../../chat';
  11. import { Filmstrip } from '../../../filmstrip';
  12. import { CalleeInfoContainer } from '../../../invite';
  13. import { LargeVideo } from '../../../large-video';
  14. import { KnockingParticipantList, LobbyScreen } from '../../../lobby';
  15. import { ParticipantsPane } from '../../../participants-pane/components';
  16. import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
  17. import { Prejoin, isPrejoinPageVisible } from '../../../prejoin';
  18. import { fullScreenChanged, showToolbox } from '../../../toolbox/actions.web';
  19. import { Toolbox } from '../../../toolbox/components/web';
  20. import { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  21. import { maybeShowSuboptimalExperienceNotification } from '../../functions';
  22. import {
  23. AbstractConference,
  24. abstractMapStateToProps
  25. } from '../AbstractConference';
  26. import type { AbstractProps } from '../AbstractConference';
  27. import ConferenceInfo from './ConferenceInfo';
  28. import { default as Notice } from './Notice';
  29. declare var APP: Object;
  30. declare var interfaceConfig: Object;
  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. * The alpha(opacity) of the background
  61. */
  62. _backgroundAlpha: number,
  63. /**
  64. * Returns true if the 'lobby screen' is visible.
  65. */
  66. _isLobbyScreenVisible: boolean,
  67. /**
  68. * If participants pane is visible or not.
  69. */
  70. _isParticipantsPaneVisible: boolean,
  71. /**
  72. * The CSS class to apply to the root of {@link Conference} to modify the
  73. * application layout.
  74. */
  75. _layoutClassName: string,
  76. /**
  77. * Name for this conference room.
  78. */
  79. _roomName: string,
  80. /**
  81. * If prejoin page is visible or not.
  82. */
  83. _showPrejoin: boolean,
  84. dispatch: Function,
  85. t: Function
  86. }
  87. /**
  88. * The conference page of the Web application.
  89. */
  90. class Conference extends AbstractConference<Props, *> {
  91. _onFullScreenChange: Function;
  92. _onShowToolbar: Function;
  93. _originalOnShowToolbar: Function;
  94. _setBackground: Function;
  95. /**
  96. * Initializes a new Conference instance.
  97. *
  98. * @param {Object} props - The read-only properties with which the new
  99. * instance is to be initialized.
  100. */
  101. constructor(props) {
  102. super(props);
  103. // Throttle and bind this component's mousemove handler to prevent it
  104. // from firing too often.
  105. this._originalOnShowToolbar = this._onShowToolbar;
  106. this._onShowToolbar = _.throttle(
  107. () => this._originalOnShowToolbar(),
  108. 100,
  109. {
  110. leading: true,
  111. trailing: false
  112. });
  113. // Bind event handler so it is only bound once for every instance.
  114. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  115. this._setBackground = this._setBackground.bind(this);
  116. }
  117. /**
  118. * Start the connection and get the UI ready for the conference.
  119. *
  120. * @inheritdoc
  121. */
  122. componentDidMount() {
  123. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  124. this._start();
  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. _isLobbyScreenVisible,
  164. _isParticipantsPaneVisible,
  165. _layoutClassName,
  166. _showPrejoin
  167. } = this.props;
  168. return (
  169. <div id = 'layout_wrapper'>
  170. <div
  171. className = { _layoutClassName }
  172. id = 'videoconference_page'
  173. onMouseMove = { this._onShowToolbar }
  174. ref = { this._setBackground }>
  175. <ConferenceInfo />
  176. <Notice />
  177. <div id = 'videospace'>
  178. <LargeVideo />
  179. {!_isParticipantsPaneVisible && <KnockingParticipantList />}
  180. <Filmstrip />
  181. </div>
  182. { _showPrejoin || _isLobbyScreenVisible || <Toolbox /> }
  183. <Chat />
  184. { this.renderNotificationsContainer() }
  185. <CalleeInfoContainer />
  186. { _showPrejoin && <Prejoin />}
  187. </div>
  188. <ParticipantsPane />
  189. </div>
  190. );
  191. }
  192. /**
  193. * Sets custom background opacity based on config. It also applies the
  194. * opacity on parent element, as the parent element is not accessible directly,
  195. * only though it's child.
  196. *
  197. * @param {Object} element - The DOM element for which to apply opacity.
  198. *
  199. * @private
  200. * @returns {void}
  201. */
  202. _setBackground(element) {
  203. if (!element) {
  204. return;
  205. }
  206. if (this.props._backgroundAlpha !== undefined) {
  207. const elemColor = element.style.background;
  208. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  209. element.style.background = alphaElemColor;
  210. if (element.parentElement) {
  211. const parentColor = element.parentElement.style.background;
  212. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  213. element.parentElement.style.background = alphaParentColor;
  214. }
  215. }
  216. }
  217. /**
  218. * Updates the Redux state when full screen mode has been enabled or
  219. * disabled.
  220. *
  221. * @private
  222. * @returns {void}
  223. */
  224. _onFullScreenChange() {
  225. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  226. }
  227. /**
  228. * Displays the toolbar.
  229. *
  230. * @private
  231. * @returns {void}
  232. */
  233. _onShowToolbar() {
  234. this.props.dispatch(showToolbox());
  235. }
  236. /**
  237. * Until we don't rewrite UI using react components
  238. * we use UI.start from old app. Also method translates
  239. * component right after it has been mounted.
  240. *
  241. * @inheritdoc
  242. */
  243. _start() {
  244. APP.UI.start();
  245. APP.UI.registerListeners();
  246. APP.UI.bindEvents();
  247. FULL_SCREEN_EVENTS.forEach(name =>
  248. document.addEventListener(name, this._onFullScreenChange));
  249. const { dispatch, t } = this.props;
  250. dispatch(connect());
  251. maybeShowSuboptimalExperienceNotification(dispatch, t);
  252. }
  253. }
  254. /**
  255. * Maps (parts of) the Redux state to the associated props for the
  256. * {@code Conference} component.
  257. *
  258. * @param {Object} state - The Redux state.
  259. * @private
  260. * @returns {Props}
  261. */
  262. function _mapStateToProps(state) {
  263. return {
  264. ...abstractMapStateToProps(state),
  265. _backgroundAlpha: state['features/base/config'].backgroundAlpha,
  266. _isLobbyScreenVisible: state['features/base/dialog']?.component === LobbyScreen,
  267. _isParticipantsPaneVisible: getParticipantsPaneOpen(state),
  268. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state)],
  269. _roomName: getConferenceNameForTitle(state),
  270. _showPrejoin: isPrejoinPageVisible(state)
  271. };
  272. }
  273. export default reactReduxConnect(_mapStateToProps)(translate(Conference));