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

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