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

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