Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Conference.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. * NOTE: This should be set to true once we received an error on connect. Before the first connect this will always
  95. * be false.
  96. */
  97. _showVisitorsQueue: boolean;
  98. dispatch: IStore['dispatch'];
  99. }
  100. /**
  101. * Returns true if the prejoin screen should be displayed and false otherwise.
  102. *
  103. * @param {IProps} props - The props object.
  104. * @returns {boolean} - True if the prejoin screen should be displayed and false otherwise.
  105. */
  106. function shouldShowPrejoin({ _showPrejoin, _showVisitorsQueue }: IProps) {
  107. return _showPrejoin && !_showVisitorsQueue;
  108. }
  109. /**
  110. * The conference page of the Web application.
  111. */
  112. class Conference extends AbstractConference<IProps, any> {
  113. _originalOnMouseMove: Function;
  114. _originalOnShowToolbar: Function;
  115. /**
  116. * Initializes a new Conference instance.
  117. *
  118. * @param {Object} props - The read-only properties with which the new
  119. * instance is to be initialized.
  120. */
  121. constructor(props: IProps) {
  122. super(props);
  123. const { _mouseMoveCallbackInterval } = props;
  124. // Throttle and bind this component's mousemove handler to prevent it
  125. // from firing too often.
  126. this._originalOnShowToolbar = this._onShowToolbar;
  127. this._originalOnMouseMove = this._onMouseMove;
  128. this._onShowToolbar = throttle(
  129. () => this._originalOnShowToolbar(),
  130. 100,
  131. {
  132. leading: true,
  133. trailing: false
  134. });
  135. this._onMouseMove = throttle(
  136. event => this._originalOnMouseMove(event),
  137. _mouseMoveCallbackInterval,
  138. {
  139. leading: true,
  140. trailing: false
  141. });
  142. // Bind event handler so it is only bound once for every instance.
  143. this._onFullScreenChange = this._onFullScreenChange.bind(this);
  144. this._onVidespaceTouchStart = this._onVidespaceTouchStart.bind(this);
  145. this._setBackground = this._setBackground.bind(this);
  146. }
  147. /**
  148. * Start the connection and get the UI ready for the conference.
  149. *
  150. * @inheritdoc
  151. */
  152. componentDidMount() {
  153. document.title = `${this.props._roomName} | ${interfaceConfig.APP_NAME}`;
  154. this._start();
  155. }
  156. /**
  157. * Calls into legacy UI to update the application layout, if necessary.
  158. *
  159. * @inheritdoc
  160. * returns {void}
  161. */
  162. componentDidUpdate(prevProps: IProps) {
  163. if (this.props._shouldDisplayTileView
  164. === prevProps._shouldDisplayTileView) {
  165. return;
  166. }
  167. // TODO: For now VideoLayout is being called as LargeVideo and Filmstrip
  168. // sizing logic is still handled outside of React. Once all components
  169. // are in react they should calculate size on their own as much as
  170. // possible and pass down sizings.
  171. VideoLayout.refreshLayout();
  172. }
  173. /**
  174. * Disconnect from the conference when component will be
  175. * unmounted.
  176. *
  177. * @inheritdoc
  178. */
  179. componentWillUnmount() {
  180. APP.UI.unbindEvents();
  181. FULL_SCREEN_EVENTS.forEach(name =>
  182. document.removeEventListener(name, this._onFullScreenChange));
  183. APP.conference.isJoined() && this.props.dispatch(hangup());
  184. }
  185. /**
  186. * Implements React's {@link Component#render()}.
  187. *
  188. * @inheritdoc
  189. * @returns {ReactElement}
  190. */
  191. render() {
  192. const {
  193. _isAnyOverlayVisible,
  194. _layoutClassName,
  195. _notificationsVisible,
  196. _overflowDrawer,
  197. _showLobby,
  198. _showPrejoin,
  199. _showVisitorsQueue,
  200. t
  201. } = this.props;
  202. return (
  203. <div
  204. id = 'layout_wrapper'
  205. onMouseEnter = { this._onMouseEnter }
  206. onMouseLeave = { this._onMouseLeave }
  207. onMouseMove = { this._onMouseMove }
  208. ref = { this._setBackground }>
  209. <Chat />
  210. <div
  211. className = { _layoutClassName }
  212. id = 'videoconference_page'
  213. onMouseMove = { isMobileBrowser() ? undefined : this._onShowToolbar }>
  214. <ConferenceInfo />
  215. <Notice />
  216. <div
  217. id = 'videospace'
  218. onTouchStart = { this._onVidespaceTouchStart }>
  219. <LargeVideo />
  220. {
  221. _showPrejoin || _showLobby || (<>
  222. <StageFilmstrip />
  223. <ScreenshareFilmstrip />
  224. <MainFilmstrip />
  225. </>)
  226. }
  227. </div>
  228. { _showPrejoin || _showLobby || (
  229. <>
  230. <span
  231. aria-level = { 1 }
  232. className = 'sr-only'
  233. role = 'heading'>
  234. { t('toolbar.accessibilityLabel.heading') }
  235. </span>
  236. <Toolbox />
  237. </>
  238. )}
  239. {_notificationsVisible && !_isAnyOverlayVisible && (_overflowDrawer
  240. ? <JitsiPortal className = 'notification-portal'>
  241. {this.renderNotificationsContainer({ portal: true })}
  242. </JitsiPortal>
  243. : this.renderNotificationsContainer())
  244. }
  245. <CalleeInfoContainer />
  246. { shouldShowPrejoin(this.props) && <Prejoin />}
  247. { (_showLobby && !_showVisitorsQueue) && <LobbyScreen />}
  248. { _showVisitorsQueue && <VisitorsQueue />}
  249. </div>
  250. <ParticipantsPane />
  251. <ReactionAnimations />
  252. </div>
  253. );
  254. }
  255. /**
  256. * Sets custom background opacity based on config. It also applies the
  257. * opacity on parent element, as the parent element is not accessible directly,
  258. * only though it's child.
  259. *
  260. * @param {Object} element - The DOM element for which to apply opacity.
  261. *
  262. * @private
  263. * @returns {void}
  264. */
  265. _setBackground(element: HTMLDivElement) {
  266. if (!element) {
  267. return;
  268. }
  269. if (this.props._backgroundAlpha !== undefined) {
  270. const elemColor = element.style.background;
  271. const alphaElemColor = setColorAlpha(elemColor, this.props._backgroundAlpha);
  272. element.style.background = alphaElemColor;
  273. if (element.parentElement) {
  274. const parentColor = element.parentElement.style.background;
  275. const alphaParentColor = setColorAlpha(parentColor, this.props._backgroundAlpha);
  276. element.parentElement.style.background = alphaParentColor;
  277. }
  278. }
  279. }
  280. /**
  281. * Handler used for touch start on Video container.
  282. *
  283. * @private
  284. * @returns {void}
  285. */
  286. _onVidespaceTouchStart() {
  287. this.props.dispatch(toggleToolboxVisible());
  288. }
  289. /**
  290. * Updates the Redux state when full screen mode has been enabled or
  291. * disabled.
  292. *
  293. * @private
  294. * @returns {void}
  295. */
  296. _onFullScreenChange() {
  297. this.props.dispatch(fullScreenChanged(APP.UI.isFullScreen()));
  298. }
  299. /**
  300. * Triggers iframe API mouseEnter event.
  301. *
  302. * @param {MouseEvent} event - The mouse event.
  303. * @private
  304. * @returns {void}
  305. */
  306. _onMouseEnter(event: React.MouseEvent) {
  307. APP.API.notifyMouseEnter(event);
  308. }
  309. /**
  310. * Triggers iframe API mouseLeave event.
  311. *
  312. * @param {MouseEvent} event - The mouse event.
  313. * @private
  314. * @returns {void}
  315. */
  316. _onMouseLeave(event: React.MouseEvent) {
  317. APP.API.notifyMouseLeave(event);
  318. }
  319. /**
  320. * Triggers iframe API mouseMove event.
  321. *
  322. * @param {MouseEvent} event - The mouse event.
  323. * @private
  324. * @returns {void}
  325. */
  326. _onMouseMove(event: React.MouseEvent) {
  327. APP.API.notifyMouseMove(event);
  328. }
  329. /**
  330. * Displays the toolbar.
  331. *
  332. * @private
  333. * @returns {void}
  334. */
  335. _onShowToolbar() {
  336. this.props.dispatch(showToolbox());
  337. }
  338. /**
  339. * Until we don't rewrite UI using react components
  340. * we use UI.start from old app. Also method translates
  341. * component right after it has been mounted.
  342. *
  343. * @inheritdoc
  344. */
  345. _start() {
  346. APP.UI.start();
  347. APP.UI.bindEvents();
  348. FULL_SCREEN_EVENTS.forEach(name =>
  349. document.addEventListener(name, this._onFullScreenChange));
  350. const { dispatch, t } = this.props;
  351. // if we will be showing prejoin we don't want to call connect from init.
  352. // Connect will be dispatched from prejoin screen.
  353. dispatch(init(!shouldShowPrejoin(this.props)));
  354. maybeShowSuboptimalExperienceNotification(dispatch, t);
  355. }
  356. }
  357. /**
  358. * Maps (parts of) the Redux state to the associated props for the
  359. * {@code Conference} component.
  360. *
  361. * @param {Object} state - The Redux state.
  362. * @private
  363. * @returns {IProps}
  364. */
  365. function _mapStateToProps(state: IReduxState) {
  366. const { backgroundAlpha, mouseMoveCallbackInterval } = state['features/base/config'];
  367. const { overflowDrawer } = state['features/toolbox'];
  368. return {
  369. ...abstractMapStateToProps(state),
  370. _backgroundAlpha: backgroundAlpha,
  371. _isAnyOverlayVisible: Boolean(getOverlayToRender(state)),
  372. _layoutClassName: LAYOUT_CLASSNAMES[getCurrentLayout(state) ?? ''],
  373. _mouseMoveCallbackInterval: mouseMoveCallbackInterval,
  374. _overflowDrawer: overflowDrawer,
  375. _roomName: getConferenceNameForTitle(state),
  376. _showLobby: getIsLobbyVisible(state),
  377. _showPrejoin: isPrejoinPageVisible(state),
  378. _showVisitorsQueue: showVisitorsQueue(state)
  379. };
  380. }
  381. export default reactReduxConnect(_mapStateToProps)(translate(Conference));