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.

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