Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Conference.js 12KB

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