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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. _onConnect,
  163. _onDisconnect,
  164. _participantCount: oldParticipantCount,
  165. _room: oldRoom,
  166. _setToolboxVisible
  167. } = this.props;
  168. const {
  169. _locationURL: newLocationURL,
  170. _participantCount: newParticipantCount,
  171. _room: newRoom
  172. } = nextProps;
  173. // If the location URL changes we need to reconnect.
  174. oldLocationURL !== newLocationURL && _onDisconnect();
  175. // Start the connection process when there is a (valid) room.
  176. oldRoom !== newRoom && newRoom && _onConnect();
  177. if (oldParticipantCount === 1) {
  178. newParticipantCount > 1 && _setToolboxVisible(false);
  179. } else if (oldParticipantCount > 1) {
  180. newParticipantCount === 1 && _setToolboxVisible(true);
  181. }
  182. }
  183. /**
  184. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  185. * before this component is unmounted and destroyed. Disconnects the
  186. * conference described by the redux store/state.
  187. *
  188. * @inheritdoc
  189. * @returns {void}
  190. */
  191. componentWillUnmount() {
  192. // Tear handling any hardware button presses for back navigation down.
  193. const backHandler = this._backHandler;
  194. if (backHandler) {
  195. this._backHandler = undefined;
  196. backHandler.removeEventListener(
  197. 'hardwareBackPress',
  198. this._onHardwareBackPress);
  199. }
  200. this.props._onDisconnect();
  201. }
  202. /**
  203. * Implements React's {@link Component#render()}.
  204. *
  205. * @inheritdoc
  206. * @returns {ReactElement}
  207. */
  208. render() {
  209. return (
  210. <Container style = { styles.conference }>
  211. <StatusBar
  212. barStyle = 'light-content'
  213. hidden = { true }
  214. translucent = { true } />
  215. {/*
  216. * The LargeVideo is the lowermost stacking layer.
  217. */}
  218. <LargeVideo onPress = { this._onClick } />
  219. {/*
  220. * If there is a ringing call, show the callee's info.
  221. */
  222. this.props._reducedUI || <CalleeInfoContainer />
  223. }
  224. {/*
  225. * The activity/loading indicator goes above everything, except
  226. * the toolbox/toolbars and the dialogs.
  227. */
  228. this.props._connecting
  229. && <TintedView>
  230. <LoadingIndicator />
  231. </TintedView>
  232. }
  233. <View
  234. pointerEvents = 'box-none'
  235. style = { styles.toolboxAndFilmstripContainer }>
  236. {/*
  237. * The Toolbox is in a stacking layer bellow the Filmstrip.
  238. */}
  239. <Toolbox />
  240. {/*
  241. * The Filmstrip is in a stacking layer above the
  242. * LargeVideo. The LargeVideo and the Filmstrip form what
  243. * the Web/React app calls "videospace". Presumably, the
  244. * name and grouping stem from the fact that these two
  245. * React Components depict the videos of the conference's
  246. * participants.
  247. */}
  248. <Filmstrip />
  249. </View>
  250. <TestConnectionInfo />
  251. {
  252. this._renderConferenceNotification()
  253. }
  254. <NotificationsContainer />
  255. {/*
  256. * The dialogs are in the topmost stacking layers.
  257. */
  258. this.props._reducedUI || <DialogContainer />
  259. }
  260. </Container>
  261. );
  262. }
  263. _onClick: () => void;
  264. /**
  265. * Changes the value of the toolboxVisible state, thus allowing us to switch
  266. * between Toolbox and Filmstrip and change their visibility.
  267. *
  268. * @private
  269. * @returns {void}
  270. */
  271. _onClick() {
  272. if (this.props._toolboxAlwaysVisible) {
  273. return;
  274. }
  275. const toolboxVisible = !this.props._toolboxVisible;
  276. this.props._setToolboxVisible(toolboxVisible);
  277. }
  278. _onHardwareBackPress: () => boolean;
  279. /**
  280. * Handles a hardware button press for back navigation.
  281. *
  282. * @returns {boolean} If the hardware button press for back navigation was
  283. * handled by this {@code Conference}, then {@code true}; otherwise,
  284. * {@code false}.
  285. */
  286. _onHardwareBackPress() {
  287. return this._backHandler && this.props._onHardwareBackPress();
  288. }
  289. /**
  290. * Renders the conference notification badge if the feature is enabled.
  291. *
  292. * Note: If the calendar feature is disabled on a platform, then we don't
  293. * have its components exported so an undefined check is necessary.
  294. *
  295. * @private
  296. * @returns {React$Node}
  297. */
  298. _renderConferenceNotification() {
  299. return ConferenceNotification
  300. ? <ConferenceNotification />
  301. : undefined;
  302. }
  303. }
  304. /**
  305. * Maps dispatching of some action to React component props.
  306. *
  307. * @param {Function} dispatch - Redux action dispatcher.
  308. * @private
  309. * @returns {{
  310. * _onConnect: Function,
  311. * _onDisconnect: 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. * @returns {void}
  322. * @private
  323. */
  324. _onConnect() {
  325. dispatch(createDesiredLocalTracks());
  326. dispatch(connect());
  327. },
  328. /**
  329. * Dispatches an action disconnecting from the conference.
  330. *
  331. * @returns {void}
  332. * @private
  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 Toolbox.
  351. *
  352. * @param {boolean} visible - True to show the Toolbox or false to hide
  353. * it.
  354. * @returns {void}
  355. * @private
  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. * _locationURL: URL,
  370. * _participantCount: number,
  371. * _reducedUI: boolean,
  372. * _room: string,
  373. * _toolboxVisible: boolean,
  374. * _toolboxAlwaysVisible: boolean
  375. * }}
  376. */
  377. function _mapStateToProps(state) {
  378. const { connecting, connection, locationURL }
  379. = state['features/base/connection'];
  380. const {
  381. conference,
  382. joining,
  383. leaving,
  384. room
  385. } = state['features/base/conference'];
  386. const { reducedUI } = state['features/base/responsive-ui'];
  387. const { alwaysVisible, visible } = state['features/toolbox'];
  388. // XXX There is a window of time between the successful establishment of the
  389. // XMPP connection and the subsequent commencement of joining the MUC during
  390. // which the app does not appear to be doing anything according to the redux
  391. // state. In order to not toggle the _connecting props during the window of
  392. // time in question, define _connecting as follows:
  393. // - the XMPP connection is connecting, or
  394. // - the XMPP connection is connected and the conference is joining, or
  395. // - the XMPP connection is connected and we have no conference yet, nor we
  396. // are leaving one.
  397. const connecting_
  398. = connecting || (connection && (joining || (!conference && !leaving)));
  399. return {
  400. /**
  401. * The indicator which determines that we are still connecting to the
  402. * conference which includes establishing the XMPP connection and then
  403. * joining the room. If truthy, then an activity/loading indicator will
  404. * be rendered.
  405. *
  406. * @private
  407. * @type {boolean}
  408. */
  409. _connecting: Boolean(connecting_),
  410. /**
  411. * Current conference's full URL.
  412. *
  413. * @private
  414. * @type {URL}
  415. */
  416. _locationURL: locationURL,
  417. /**
  418. * The number of participants in the conference.
  419. *
  420. * @private
  421. * @type {number}
  422. */
  423. _participantCount: getParticipantCount(state),
  424. /**
  425. * The indicator which determines whether the UI is reduced (to
  426. * accommodate smaller display areas).
  427. *
  428. * @private
  429. * @type {boolean}
  430. */
  431. _reducedUI: reducedUI,
  432. /**
  433. * The current conference room name.
  434. *
  435. * @private
  436. * @type {string}
  437. */
  438. _room: room,
  439. /**
  440. * The indicator which determines whether the Toolbox is visible.
  441. *
  442. * @private
  443. * @type {boolean}
  444. */
  445. _toolboxVisible: visible,
  446. /**
  447. * The indicator which determines whether the Toolbox is always visible.
  448. *
  449. * @private
  450. * @type {boolean}
  451. */
  452. _toolboxAlwaysVisible: alwaysVisible
  453. };
  454. }
  455. // $FlowFixMe
  456. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  457. Conference);