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

Conference.js 11KB

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