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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 from '../../../prejoin/components/web/Prejoin';
  19. import { isPrejoinPageVisible } from '../../../prejoin/functions';
  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 { LAYOUT_CLASSNAMES, 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 type of the React {@code Component} props of {@link Conference}.
  48. */
  49. type Props = AbstractProps & {
  50. /**
  51. * The alpha(opacity) of the background.
  52. */
  53. _backgroundAlpha: number,
  54. /**
  55. * The CSS class to apply to the root of {@link Conference} to modify the
  56. * application layout.
  57. */
  58. _layoutClassName: string,
  59. /**
  60. * The config specified interval for triggering mouseMoved iframe api events.
  61. */
  62. _mouseMoveCallbackInterval: number,
  63. /**
  64. *Whether or not the notifications should be displayed in the overflow drawer.
  65. */
  66. _overflowDrawer: boolean,
  67. /**
  68. * Name for this conference room.
  69. */
  70. _roomName: string,
  71. /**
  72. * If lobby page is visible or not.
  73. */
  74. _showLobby: boolean,
  75. /**
  76. * If prejoin page is visible or not.
  77. */
  78. _showPrejoin: boolean,
  79. dispatch: Function,
  80. t: Function
  81. }
  82. /**
  83. * The conference page of the Web application.
  84. */
  85. class Conference extends AbstractConference<Props, *> {
  86. _onFullScreenChange: Function;
  87. _onMouseEnter: Function;
  88. _onMouseLeave: Function;
  89. _onMouseMove: Function;
  90. _onShowToolbar: Function;
  91. _onVidespaceTouchStart: Function;
  92. _originalOnMouseMove: Function;
  93. _originalOnShowToolbar: Function;
  94. _setBackground: Function;
  95. /**
  96. * Initializes a new Conference instance.
  97. *
  98. * @param {Object} props - The read-only properties with which the new
  99. * instance is to be initialized.
  100. */
  101. constructor(props) {
  102. super(props);
  103. const { _mouseMoveCallbackInterval } = props;
  104. // Throttle and bind this component's mousemove handler to prevent it
  105. // from firing too often.
  106. this._originalOnShowToolbar = this._onShowToolbar;
  107. this._originalOnMouseMove = this._onMouseMove;
  108. this._onShowToolbar = _.throttle(
  109. () => this._originalOnShowToolbar(),
  110. 100,
  111. {
  112. leading: true,
  113. trailing: false
  114. });
  115. this._onMouseMove = _.throttle(
  116. event => this._originalOnMouseMove(event),
  117. _mouseMoveCallbackInterval,
  118. {
  119. leading: true,
  120. trailing: false
  121. });
  122. // Bind event handler so it is only bound once for every instance.
  123. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  124. this._onVidespaceTouchStart = this._onVidespaceTouchStart.bind(this);
  125. this._setBackground = this._setBackground.bind(this);
  126. }
  127. /**
  128. * Start the connection and get the UI ready for the conference.
  129. *
  130. * @inheritdoc
  131. */
  132. componentDidMount() {
  133. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  134. this._start();
  135. }
  136. /**
  137. * Calls into legacy UI to update the application layout, if necessary.
  138. *
  139. * @inheritdoc
  140. * returns {void}
  141. */
  142. componentDidUpdate(prevProps) {
  143. if (this.props._shouldDisplayTileView
  144. === prevProps._shouldDisplayTileView) {
  145. return;
  146. }
  147. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  148. // sizing logic is still handled outside of React. Once all components
  149. // are in react they should calculate size on their own as much as
  150. // possible and pass down sizings.
  151. VideoLayout.refreshLayout();
  152. }
  153. /**
  154. * Disconnect from the conference when component will be
  155. * unmounted.
  156. *
  157. * @inheritdoc
  158. */
  159. componentWillUnmount() {
  160. APP.UI.unbindEvents();
  161. FULL_SCREEN_EVENTS.forEach(name =>
  162. document.removeEventListener(name, this._onFullScreenChange));
  163. APP.conference.isJoined() && this.props.dispatch(disconnect());
  164. }
  165. /**
  166. * Implements React's {@link Component#render()}.
  167. *
  168. * @inheritdoc
  169. * @returns {ReactElement}
  170. */
  171. render() {
  172. const {
  173. _layoutClassName,
  174. _notificationsVisible,
  175. _overflowDrawer,
  176. _showLobby,
  177. _showPrejoin
  178. } = this.props;
  179. return (
  180. <div
  181. id = 'layout_wrapper'
  182. onMouseEnter = { this._onMouseEnter }
  183. onMouseLeave = { this._onMouseLeave }
  184. onMouseMove = { this._onMouseMove }
  185. ref = { this._setBackground }>
  186. <Chat />
  187. <div
  188. className = { _layoutClassName }
  189. id = 'videoconference_page'
  190. onMouseMove = { isMobileBrowser() ? undefined : this._onShowToolbar }>
  191. <ConferenceInfo />
  192. <Notice />
  193. <div
  194. id = 'videospace'
  195. onTouchStart = { this._onVidespaceTouchStart }>
  196. <LargeVideo />
  197. {
  198. _showPrejoin || _showLobby || (<>
  199. <StageFilmstrip />
  200. <ScreenshareFilmstrip />
  201. <MainFilmstrip />
  202. </>)
  203. }
  204. </div>
  205. { _showPrejoin || _showLobby || <Toolbox /> }
  206. {_notificationsVisible && (_overflowDrawer
  207. ? <JitsiPortal className = 'notification-portal'>
  208. {this.renderNotificationsContainer({ portal: true })}
  209. </JitsiPortal>
  210. : this.renderNotificationsContainer())
  211. }
  212. <CalleeInfoContainer />
  213. { _showPrejoin && <Prejoin />}
  214. { _showLobby && <LobbyScreen />}
  215. </div>
  216. <ParticipantsPane />
  217. </div>
  218. );
  219. }
  220. /**
  221. * Sets custom background opacity based on config. It also applies the
  222. * opacity on parent element, as the parent element is not accessible directly,
  223. * only though it's child.
  224. *
  225. * @param {Object} element - The DOM element for which to apply opacity.
  226. *
  227. * @private
  228. * @returns {void}
  229. */
  230. _setBackground(element) {
  231. if (!element) {
  232. return;
  233. }
  234. if (this.props._backgroundAlpha !== undefined) {
  235. const elemColor = element.style.background;
  236. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  237. element.style.background = alphaElemColor;
  238. if (element.parentElement) {
  239. const parentColor = element.parentElement.style.background;
  240. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  241. element.parentElement.style.background = alphaParentColor;
  242. }
  243. }
  244. }
  245. /**
  246. * Handler used for touch start on Video container.
  247. *
  248. * @private
  249. * @returns {void}
  250. */
  251. _onVidespaceTouchStart() {
  252. this.props.dispatch(toggleToolboxVisible());
  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. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state)],
  336. _mouseMoveCallbackInterval: mouseMoveCallbackInterval,
  337. _overflowDrawer: overflowDrawer,
  338. _roomName: getConferenceNameForTitle(state),
  339. _showLobby: getIsLobbyVisible(state),
  340. _showPrejoin: isPrejoinPageVisible(state)
  341. };
  342. }
  343. export default reactReduxConnect(_mapStateToProps)(translate(Conference));