You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Conference.js 11KB

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