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

Conference.js 11KB

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