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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 { isMobileBrowser } from '../../../base/environment/utils';
  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 { MainFilmstrip, StageFilmstrip, ScreenshareFilmstrip } from '../../../filmstrip';
  13. import { CalleeInfoContainer } from '../../../invite';
  14. import { LargeVideo } from '../../../large-video';
  15. import { LobbyScreen } from '../../../lobby';
  16. import { getIsLobbyVisible } from '../../../lobby/functions';
  17. import { ParticipantsPane } from '../../../participants-pane/components/web';
  18. import { Prejoin, isPrejoinPageVisible } from '../../../prejoin';
  19. import { toggleToolboxVisible } from '../../../toolbox/actions.any';
  20. import { fullScreenChanged, showToolbox } from '../../../toolbox/actions.web';
  21. import { JitsiPortal, 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. export const LAYOUT_CLASSNAMES = {
  53. [LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW]: 'horizontal-filmstrip',
  54. [LAYOUTS.TILE_VIEW]: 'tile-view',
  55. [LAYOUTS.VERTICAL_FILMSTRIP_VIEW]: 'vertical-filmstrip',
  56. [LAYOUTS.STAGE_FILMSTRIP_VIEW]: 'stage-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. dispatch: Function,
  92. t: Function
  93. }
  94. /**
  95. * The conference page of the Web application.
  96. */
  97. class Conference extends AbstractConference<Props, *> {
  98. _onFullScreenChange: Function;
  99. _onMouseEnter: Function;
  100. _onMouseLeave: Function;
  101. _onMouseMove: Function;
  102. _onShowToolbar: Function;
  103. _onVidespaceTouchStart: Function;
  104. _originalOnMouseMove: Function;
  105. _originalOnShowToolbar: Function;
  106. _setBackground: Function;
  107. /**
  108. * Initializes a new Conference instance.
  109. *
  110. * @param {Object} props - The read-only properties with which the new
  111. * instance is to be initialized.
  112. */
  113. constructor(props) {
  114. super(props);
  115. const { _mouseMoveCallbackInterval } = props;
  116. // Throttle and bind this component's mousemove handler to prevent it
  117. // from firing too often.
  118. this._originalOnShowToolbar = this._onShowToolbar;
  119. this._originalOnMouseMove = this._onMouseMove;
  120. this._onShowToolbar = _.throttle(
  121. () => this._originalOnShowToolbar(),
  122. 100,
  123. {
  124. leading: true,
  125. trailing: false
  126. });
  127. this._onMouseMove = _.throttle(
  128. event => this._originalOnMouseMove(event),
  129. _mouseMoveCallbackInterval,
  130. {
  131. leading: true,
  132. trailing: false
  133. });
  134. // Bind event handler so it is only bound once for every instance.
  135. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  136. this._onVidespaceTouchStart = this._onVidespaceTouchStart.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. _layoutClassName,
  186. _notificationsVisible,
  187. _overflowDrawer,
  188. _showLobby,
  189. _showPrejoin
  190. } = this.props;
  191. return (
  192. <div
  193. id = 'layout_wrapper'
  194. onMouseEnter = { this._onMouseEnter }
  195. onMouseLeave = { this._onMouseLeave }
  196. onMouseMove = { this._onMouseMove }
  197. ref = { this._setBackground }>
  198. <Chat />
  199. <div
  200. className = { _layoutClassName }
  201. id = 'videoconference_page'
  202. onMouseMove = { isMobileBrowser() ? undefined : this._onShowToolbar }>
  203. <ConferenceInfo />
  204. <Notice />
  205. <div
  206. id = 'videospace'
  207. onTouchStart = { this._onVidespaceTouchStart }>
  208. <LargeVideo />
  209. {
  210. _showPrejoin || _showLobby || (<>
  211. <StageFilmstrip />
  212. <ScreenshareFilmstrip />
  213. <MainFilmstrip />
  214. </>)
  215. }
  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. };
  354. }
  355. export default reactReduxConnect(_mapStateToProps)(translate(Conference));