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 15KB

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