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

Conference.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. * The config specified interval for triggering mouseMoved iframe api events
  78. */
  79. _mouseMoveCallbackInterval: number,
  80. /**
  81. * Name for this conference room.
  82. */
  83. _roomName: string,
  84. /**
  85. * If prejoin page is visible or not.
  86. */
  87. _showPrejoin: boolean,
  88. dispatch: Function,
  89. t: Function
  90. }
  91. /**
  92. * The conference page of the Web application.
  93. */
  94. class Conference extends AbstractConference<Props, *> {
  95. _onFullScreenChange: Function;
  96. _onMouseEnter: Function;
  97. _onMouseLeave: Function;
  98. _onMouseMove: Function;
  99. _onShowToolbar: Function;
  100. _originalOnMouseMove: Function;
  101. _originalOnShowToolbar: Function;
  102. _setBackground: Function;
  103. /**
  104. * Initializes a new Conference instance.
  105. *
  106. * @param {Object} props - The read-only properties with which the new
  107. * instance is to be initialized.
  108. */
  109. constructor(props) {
  110. super(props);
  111. const { _mouseMoveCallbackInterval } = props;
  112. // Throttle and bind this component's mousemove handler to prevent it
  113. // from firing too often.
  114. this._originalOnShowToolbar = this._onShowToolbar;
  115. this._originalOnMouseMove = this._onMouseMove;
  116. this._onShowToolbar = _.throttle(
  117. () => this._originalOnShowToolbar(),
  118. 100,
  119. {
  120. leading: true,
  121. trailing: false
  122. });
  123. this._onMouseMove = _.throttle(
  124. event => this._originalOnMouseMove(event),
  125. _mouseMoveCallbackInterval,
  126. {
  127. leading: true,
  128. trailing: false
  129. });
  130. // Bind event handler so it is only bound once for every instance.
  131. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  132. this._setBackground = this._setBackground.bind(this);
  133. }
  134. /**
  135. * Start the connection and get the UI ready for the conference.
  136. *
  137. * @inheritdoc
  138. */
  139. componentDidMount() {
  140. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  141. this._start();
  142. }
  143. /**
  144. * Calls into legacy UI to update the application layout, if necessary.
  145. *
  146. * @inheritdoc
  147. * returns {void}
  148. */
  149. componentDidUpdate(prevProps) {
  150. if (this.props._shouldDisplayTileView
  151. === prevProps._shouldDisplayTileView) {
  152. return;
  153. }
  154. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  155. // sizing logic is still handled outside of React. Once all components
  156. // are in react they should calculate size on their own as much as
  157. // possible and pass down sizings.
  158. VideoLayout.refreshLayout();
  159. }
  160. /**
  161. * Disconnect from the conference when component will be
  162. * unmounted.
  163. *
  164. * @inheritdoc
  165. */
  166. componentWillUnmount() {
  167. APP.UI.unbindEvents();
  168. FULL_SCREEN_EVENTS.forEach(name =>
  169. document.removeEventListener(name, this._onFullScreenChange));
  170. APP.conference.isJoined() && this.props.dispatch(disconnect());
  171. }
  172. /**
  173. * Implements React's {@link Component#render()}.
  174. *
  175. * @inheritdoc
  176. * @returns {ReactElement}
  177. */
  178. render() {
  179. const {
  180. _isLobbyScreenVisible,
  181. _isParticipantsPaneVisible,
  182. _layoutClassName,
  183. _showPrejoin
  184. } = this.props;
  185. return (
  186. <div
  187. id = 'layout_wrapper'
  188. onMouseEnter = { this._onMouseEnter }
  189. onMouseLeave = { this._onMouseLeave }
  190. onMouseMove = { this._onMouseMove } >
  191. <div
  192. className = { _layoutClassName }
  193. id = 'videoconference_page'
  194. onMouseMove = { this._onShowToolbar }
  195. ref = { this._setBackground }>
  196. <ConferenceInfo />
  197. <Notice />
  198. <div id = 'videospace'>
  199. <LargeVideo />
  200. {!_isParticipantsPaneVisible && <KnockingParticipantList />}
  201. <Filmstrip />
  202. </div>
  203. { _showPrejoin || _isLobbyScreenVisible || <Toolbox /> }
  204. <Chat />
  205. { this.renderNotificationsContainer() }
  206. <CalleeInfoContainer />
  207. { _showPrejoin && <Prejoin />}
  208. </div>
  209. <ParticipantsPane />
  210. </div>
  211. );
  212. }
  213. /**
  214. * Sets custom background opacity based on config. It also applies the
  215. * opacity on parent element, as the parent element is not accessible directly,
  216. * only though it's child.
  217. *
  218. * @param {Object} element - The DOM element for which to apply opacity.
  219. *
  220. * @private
  221. * @returns {void}
  222. */
  223. _setBackground(element) {
  224. if (!element) {
  225. return;
  226. }
  227. if (this.props._backgroundAlpha !== undefined) {
  228. const elemColor = element.style.background;
  229. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  230. element.style.background = alphaElemColor;
  231. if (element.parentElement) {
  232. const parentColor = element.parentElement.style.background;
  233. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  234. element.parentElement.style.background = alphaParentColor;
  235. }
  236. }
  237. }
  238. /**
  239. * Updates the Redux state when full screen mode has been enabled or
  240. * disabled.
  241. *
  242. * @private
  243. * @returns {void}
  244. */
  245. _onFullScreenChange() {
  246. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  247. }
  248. /**
  249. * Triggers iframe API mouseEnter event.
  250. *
  251. * @param {MouseEvent} event - The mouse event.
  252. * @private
  253. * @returns {void}
  254. */
  255. _onMouseEnter(event) {
  256. APP.API.notifyMouseEnter(event);
  257. }
  258. /**
  259. * Triggers iframe API mouseLeave event.
  260. *
  261. * @param {MouseEvent} event - The mouse event.
  262. * @private
  263. * @returns {void}
  264. */
  265. _onMouseLeave(event) {
  266. APP.API.notifyMouseLeave(event);
  267. }
  268. /**
  269. * Triggers iframe API mouseMove event.
  270. *
  271. * @param {MouseEvent} event - The mouse event.
  272. * @private
  273. * @returns {void}
  274. */
  275. _onMouseMove(event) {
  276. APP.API.notifyMouseMove(event);
  277. }
  278. /**
  279. * Displays the toolbar.
  280. *
  281. * @private
  282. * @returns {void}
  283. */
  284. _onShowToolbar() {
  285. this.props.dispatch(showToolbox());
  286. }
  287. /**
  288. * Until we don't rewrite UI using react components
  289. * we use UI.start from old app. Also method translates
  290. * component right after it has been mounted.
  291. *
  292. * @inheritdoc
  293. */
  294. _start() {
  295. APP.UI.start();
  296. APP.UI.registerListeners();
  297. APP.UI.bindEvents();
  298. FULL_SCREEN_EVENTS.forEach(name =>
  299. document.addEventListener(name, this._onFullScreenChange));
  300. const { dispatch, t } = this.props;
  301. dispatch(connect());
  302. maybeShowSuboptimalExperienceNotification(dispatch, t);
  303. }
  304. }
  305. /**
  306. * Maps (parts of) the Redux state to the associated props for the
  307. * {@code Conference} component.
  308. *
  309. * @param {Object} state - The Redux state.
  310. * @private
  311. * @returns {Props}
  312. */
  313. function _mapStateToProps(state) {
  314. const { backgroundAlpha, mouseMoveCallbackInterval } = state['features/base/config'];
  315. return {
  316. ...abstractMapStateToProps(state),
  317. _backgroundAlpha: backgroundAlpha,
  318. _isLobbyScreenVisible: state['features/base/dialog']?.component === LobbyScreen,
  319. _isParticipantsPaneVisible: getParticipantsPaneOpen(state),
  320. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state)],
  321. _mouseMoveCallbackInterval: mouseMoveCallbackInterval,
  322. _roomName: getConferenceNameForTitle(state),
  323. _showPrejoin: isPrejoinPageVisible(state)
  324. };
  325. }
  326. export default reactReduxConnect(_mapStateToProps)(translate(Conference));