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.native.js 16KB

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