您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.tsx 13KB

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