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.

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