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.

Conference.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { BackHandler, StatusBar, View } from 'react-native';
  4. import { connect as reactReduxConnect } from 'react-redux';
  5. import { appNavigate } from '../../../app';
  6. import { connect, disconnect } from '../../../base/connection';
  7. import { getParticipantCount } from '../../../base/participants';
  8. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  9. import {
  10. makeAspectRatioAware
  11. } from '../../../base/responsive-ui';
  12. import { TestConnectionInfo } from '../../../base/testing';
  13. import { createDesiredLocalTracks } from '../../../base/tracks';
  14. import { ConferenceNotification } from '../../../calendar-sync';
  15. import { Chat } from '../../../chat';
  16. import {
  17. Filmstrip,
  18. isFilmstripVisible,
  19. TileView
  20. } from '../../../filmstrip';
  21. import { LargeVideo } from '../../../large-video';
  22. import { CalleeInfoContainer } from '../../../invite';
  23. import { Captions } from '../../../subtitles';
  24. import { setToolboxVisible, Toolbox } from '../../../toolbox';
  25. import { shouldDisplayTileView } from '../../../video-layout';
  26. import DisplayNameLabel from './DisplayNameLabel';
  27. import Labels from './Labels';
  28. import styles from './styles';
  29. /**
  30. * The type of the React {@code Component} props of {@link Conference}.
  31. */
  32. type Props = {
  33. /**
  34. * The indicator which determines that we are still connecting to the
  35. * conference which includes establishing the XMPP connection and then
  36. * joining the room. If truthy, then an activity/loading indicator will be
  37. * rendered.
  38. *
  39. * @private
  40. */
  41. _connecting: boolean,
  42. /**
  43. * Set to {@code true} when the filmstrip is currently visible.
  44. *
  45. * @private
  46. */
  47. _filmstripVisible: boolean,
  48. /**
  49. * Current conference's full URL.
  50. *
  51. * @private
  52. */
  53. _locationURL: URL,
  54. /**
  55. * The handler which dispatches the (redux) action connect.
  56. *
  57. * @private
  58. * @returns {void}
  59. */
  60. _onConnect: Function,
  61. /**
  62. * The handler which dispatches the (redux) action disconnect.
  63. *
  64. * @private
  65. * @returns {void}
  66. */
  67. _onDisconnect: Function,
  68. /**
  69. * Handles a hardware button press for back navigation. Leaves the
  70. * associated {@code Conference}.
  71. *
  72. * @private
  73. * @returns {boolean} As the associated conference is unconditionally left
  74. * and exiting the app while it renders a {@code Conference} is undesired,
  75. * {@code true} is always returned.
  76. */
  77. _onHardwareBackPress: Function,
  78. /**
  79. * The number of participants in the conference.
  80. *
  81. * @private
  82. */
  83. _participantCount: number,
  84. /**
  85. * The indicator which determines whether the UI is reduced (to accommodate
  86. * smaller display areas).
  87. *
  88. * @private
  89. */
  90. _reducedUI: boolean,
  91. /**
  92. * The current conference room name.
  93. *
  94. * @private
  95. */
  96. _room: string,
  97. /**
  98. * The handler which dispatches the (redux) action {@link setToolboxVisible}
  99. * to show/hide the {@link Toolbox}.
  100. *
  101. * @param {boolean} visible - {@code true} to show the {@code Toolbox} or
  102. * {@code false} to hide it.
  103. * @private
  104. * @returns {void}
  105. */
  106. _setToolboxVisible: Function,
  107. /**
  108. * Whether or not the layout should change to support tile view mode.
  109. *
  110. * @private
  111. */
  112. _shouldDisplayTileView: boolean,
  113. /**
  114. * The indicator which determines whether the Toolbox is visible.
  115. *
  116. * @private
  117. */
  118. _toolboxVisible: boolean,
  119. /**
  120. * The indicator which determines whether the Toolbox is always visible.
  121. *
  122. * @private
  123. */
  124. _toolboxAlwaysVisible: boolean
  125. };
  126. /**
  127. * The conference page of the mobile (i.e. React Native) application.
  128. */
  129. class Conference extends Component<Props> {
  130. /**
  131. * Initializes a new Conference instance.
  132. *
  133. * @param {Object} props - The read-only properties with which the new
  134. * instance is to be initialized.
  135. */
  136. constructor(props) {
  137. super(props);
  138. // Bind event handlers so they are only bound once per instance.
  139. this._onClick = this._onClick.bind(this);
  140. }
  141. /**
  142. * Implements {@link Component#componentDidMount()}. Invoked immediately
  143. * after this component is mounted.
  144. *
  145. * @inheritdoc
  146. * @returns {void}
  147. */
  148. componentDidMount() {
  149. this.props._onConnect();
  150. BackHandler.addEventListener(
  151. 'hardwareBackPress',
  152. this.props._onHardwareBackPress);
  153. // Show the toolbox if we are the only participant; otherwise, the whole
  154. // UI looks too unpopulated the LargeVideo visible.
  155. const { _participantCount, _setToolboxVisible } = this.props;
  156. _participantCount === 1 && _setToolboxVisible(true);
  157. }
  158. /**
  159. * Implements React's {@link Component#componentDidUpdate()}.
  160. *
  161. * @inheritdoc
  162. */
  163. componentDidUpdate(pevProps: Props) {
  164. const {
  165. _locationURL: oldLocationURL,
  166. _participantCount: oldParticipantCount,
  167. _room: oldRoom
  168. } = pevProps;
  169. const {
  170. _locationURL: newLocationURL,
  171. _participantCount: newParticipantCount,
  172. _room: newRoom,
  173. _setToolboxVisible,
  174. _toolboxVisible
  175. } = this.props;
  176. // If the location URL changes we need to reconnect.
  177. oldLocationURL !== newLocationURL && this.props._onDisconnect();
  178. // Start the connection process when there is a (valid) room.
  179. oldRoom !== newRoom && newRoom && this.props._onConnect();
  180. if (oldParticipantCount === 1
  181. && newParticipantCount > 1
  182. && _toolboxVisible) {
  183. _setToolboxVisible(false);
  184. } else if (oldParticipantCount > 1
  185. && newParticipantCount === 1
  186. && !_toolboxVisible) {
  187. _setToolboxVisible(true);
  188. }
  189. }
  190. /**
  191. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  192. * before this component is unmounted and destroyed. Disconnects the
  193. * conference described by the redux store/state.
  194. *
  195. * @inheritdoc
  196. * @returns {void}
  197. */
  198. componentWillUnmount() {
  199. // Tear handling any hardware button presses for back navigation down.
  200. BackHandler.removeEventListener(
  201. 'hardwareBackPress',
  202. this.props._onHardwareBackPress);
  203. this.props._onDisconnect();
  204. }
  205. /**
  206. * Implements React's {@link Component#render()}.
  207. *
  208. * @inheritdoc
  209. * @returns {ReactElement}
  210. */
  211. render() {
  212. const {
  213. _connecting,
  214. _reducedUI,
  215. _shouldDisplayTileView
  216. } = this.props;
  217. return (
  218. <Container style = { styles.conference }>
  219. <StatusBar
  220. barStyle = 'light-content'
  221. hidden = { true }
  222. translucent = { true } />
  223. <Chat />
  224. {/*
  225. * The LargeVideo is the lowermost stacking layer.
  226. */
  227. _shouldDisplayTileView
  228. ? <TileView onClick = { this._onClick } />
  229. : <LargeVideo onClick = { this._onClick } />
  230. }
  231. {/*
  232. * If there is a ringing call, show the callee's info.
  233. */
  234. _reducedUI || <CalleeInfoContainer />
  235. }
  236. {/*
  237. * The activity/loading indicator goes above everything, except
  238. * the toolbox/toolbars and the dialogs.
  239. */
  240. _connecting
  241. && <TintedView>
  242. <LoadingIndicator />
  243. </TintedView>
  244. }
  245. <View
  246. pointerEvents = 'box-none'
  247. style = { styles.toolboxAndFilmstripContainer }>
  248. <Labels />
  249. <Captions onPress = { this._onClick } />
  250. <DisplayNameLabel />
  251. {/*
  252. * The Toolbox is in a stacking layer bellow the Filmstrip.
  253. */}
  254. <Toolbox />
  255. {/*
  256. * The Filmstrip is in a stacking layer above the
  257. * LargeVideo. The LargeVideo and the Filmstrip form what
  258. * the Web/React app calls "videospace". Presumably, the
  259. * name and grouping stem from the fact that these two
  260. * React Components depict the videos of the conference's
  261. * participants.
  262. */
  263. _shouldDisplayTileView ? undefined : <Filmstrip />
  264. }
  265. </View>
  266. <TestConnectionInfo />
  267. {
  268. this._renderConferenceNotification()
  269. }
  270. </Container>
  271. );
  272. }
  273. _onClick: () => void;
  274. /**
  275. * Changes the value of the toolboxVisible state, thus allowing us to switch
  276. * between Toolbox and Filmstrip and change their visibility.
  277. *
  278. * @private
  279. * @returns {void}
  280. */
  281. _onClick() {
  282. if (this.props._toolboxAlwaysVisible) {
  283. return;
  284. }
  285. const toolboxVisible = !this.props._toolboxVisible;
  286. this.props._setToolboxVisible(toolboxVisible);
  287. }
  288. /**
  289. * Renders the conference notification badge if the feature is enabled.
  290. *
  291. * @private
  292. * @returns {React$Node}
  293. */
  294. _renderConferenceNotification() {
  295. // XXX If the calendar feature is disabled on a platform, then we don't
  296. // have its components exported so an undefined check is necessary.
  297. return (
  298. !this.props._reducedUI && ConferenceNotification
  299. ? <ConferenceNotification />
  300. : undefined);
  301. }
  302. }
  303. /**
  304. * Maps dispatching of some action to React component props.
  305. *
  306. * @param {Function} dispatch - Redux action dispatcher.
  307. * @private
  308. * @returns {{
  309. * _onConnect: Function,
  310. * _onDisconnect: Function,
  311. * _onHardwareBackPress: Function,
  312. * _setToolboxVisible: Function
  313. * }}
  314. */
  315. function _mapDispatchToProps(dispatch) {
  316. return {
  317. /**
  318. * Dispatches actions to create the desired local tracks and for
  319. * connecting to the conference.
  320. *
  321. * @private
  322. * @returns {void}
  323. */
  324. _onConnect() {
  325. dispatch(createDesiredLocalTracks());
  326. dispatch(connect());
  327. },
  328. /**
  329. * Dispatches an action disconnecting from the conference.
  330. *
  331. * @private
  332. * @returns {void}
  333. */
  334. _onDisconnect() {
  335. dispatch(disconnect());
  336. },
  337. /**
  338. * Handles a hardware button press for back navigation. Leaves the
  339. * associated {@code Conference}.
  340. *
  341. * @returns {boolean} As the associated conference is unconditionally
  342. * left and exiting the app while it renders a {@code Conference} is
  343. * undesired, {@code true} is always returned.
  344. */
  345. _onHardwareBackPress() {
  346. dispatch(appNavigate(undefined));
  347. return true;
  348. },
  349. /**
  350. * Dispatches an action changing the visibility of the {@link Toolbox}.
  351. *
  352. * @private
  353. * @param {boolean} visible - Pass {@code true} to show the
  354. * {@code Toolbox} or {@code false} to hide it.
  355. * @returns {void}
  356. */
  357. _setToolboxVisible(visible) {
  358. dispatch(setToolboxVisible(visible));
  359. }
  360. };
  361. }
  362. /**
  363. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  364. *
  365. * @param {Object} state - The redux state.
  366. * @private
  367. * @returns {{
  368. * _connecting: boolean,
  369. * _filmstripVisible: boolean,
  370. * _locationURL: URL,
  371. * _participantCount: number,
  372. * _reducedUI: boolean,
  373. * _room: string,
  374. * _toolboxVisible: boolean,
  375. * _toolboxAlwaysVisible: boolean
  376. * }}
  377. */
  378. function _mapStateToProps(state) {
  379. const { connecting, connection, locationURL }
  380. = state['features/base/connection'];
  381. const {
  382. conference,
  383. joining,
  384. leaving,
  385. room
  386. } = state['features/base/conference'];
  387. const { reducedUI } = state['features/base/responsive-ui'];
  388. const { alwaysVisible, visible } = state['features/toolbox'];
  389. // XXX There is a window of time between the successful establishment of the
  390. // XMPP connection and the subsequent commencement of joining the MUC during
  391. // which the app does not appear to be doing anything according to the redux
  392. // state. In order to not toggle the _connecting props during the window of
  393. // time in question, define _connecting as follows:
  394. // - the XMPP connection is connecting, or
  395. // - the XMPP connection is connected and the conference is joining, or
  396. // - the XMPP connection is connected and we have no conference yet, nor we
  397. // are leaving one.
  398. const connecting_
  399. = connecting || (connection && (joining || (!conference && !leaving)));
  400. return {
  401. /**
  402. * The indicator which determines that we are still connecting to the
  403. * conference which includes establishing the XMPP connection and then
  404. * joining the room. If truthy, then an activity/loading indicator will
  405. * be rendered.
  406. *
  407. * @private
  408. * @type {boolean}
  409. */
  410. _connecting: Boolean(connecting_),
  411. /**
  412. * Is {@code true} when the filmstrip is currently visible.
  413. */
  414. _filmstripVisible: isFilmstripVisible(state),
  415. /**
  416. * Current conference's full URL.
  417. *
  418. * @private
  419. * @type {URL}
  420. */
  421. _locationURL: locationURL,
  422. /**
  423. * The number of participants in the conference.
  424. *
  425. * @private
  426. * @type {number}
  427. */
  428. _participantCount: getParticipantCount(state),
  429. /**
  430. * The indicator which determines whether the UI is reduced (to
  431. * accommodate smaller display areas).
  432. *
  433. * @private
  434. * @type {boolean}
  435. */
  436. _reducedUI: reducedUI,
  437. /**
  438. * The current conference room name.
  439. *
  440. * @private
  441. * @type {string}
  442. */
  443. _room: room,
  444. /**
  445. * Whether or not the layout should change to support tile view mode.
  446. *
  447. * @private
  448. * @type {boolean}
  449. */
  450. _shouldDisplayTileView: shouldDisplayTileView(state),
  451. /**
  452. * The indicator which determines whether the Toolbox is visible.
  453. *
  454. * @private
  455. * @type {boolean}
  456. */
  457. _toolboxVisible: visible,
  458. /**
  459. * The indicator which determines whether the Toolbox is always visible.
  460. *
  461. * @private
  462. * @type {boolean}
  463. */
  464. _toolboxAlwaysVisible: alwaysVisible
  465. };
  466. }
  467. // $FlowFixMe
  468. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  469. makeAspectRatioAware(Conference));