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

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