Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Conference.js 11KB

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