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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. isNarrowAspectRatio,
  12. makeAspectRatioAware
  13. } from '../../base/responsive-ui';
  14. import { TestConnectionInfo } from '../../base/testing';
  15. import { createDesiredLocalTracks } from '../../base/tracks';
  16. import { ConferenceNotification } from '../../calendar-sync';
  17. import { FILMSTRIP_SIZE, Filmstrip, isFilmstripVisible } from '../../filmstrip';
  18. import { LargeVideo } from '../../large-video';
  19. import { CalleeInfoContainer } from '../../invite';
  20. import { NotificationsContainer } from '../../notifications';
  21. import { Captions } from '../../subtitles';
  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. * Notifications are rendered on the very top of other
  251. * components like subtitles, toolbox and filmstrip.
  252. */
  253. this._renderNotificationsContainer()
  254. }
  255. <Captions onPress = { this._onClick } />
  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. <NotificationsContainer />
  275. </Container>
  276. );
  277. }
  278. _onClick: () => void;
  279. /**
  280. * Changes the value of the toolboxVisible state, thus allowing us to switch
  281. * between Toolbox and Filmstrip and change their visibility.
  282. *
  283. * @private
  284. * @returns {void}
  285. */
  286. _onClick() {
  287. if (this.props._toolboxAlwaysVisible) {
  288. return;
  289. }
  290. const toolboxVisible = !this.props._toolboxVisible;
  291. this.props._setToolboxVisible(toolboxVisible);
  292. }
  293. _onHardwareBackPress: () => boolean;
  294. /**
  295. * Handles a hardware button press for back navigation.
  296. *
  297. * @returns {boolean} If the hardware button press for back navigation was
  298. * handled by this {@code Conference}, then {@code true}; otherwise,
  299. * {@code false}.
  300. */
  301. _onHardwareBackPress() {
  302. return this._backHandler && this.props._onHardwareBackPress();
  303. }
  304. /**
  305. * Renders the conference notification badge if the feature is enabled.
  306. *
  307. * @private
  308. * @returns {React$Node}
  309. */
  310. _renderConferenceNotification() {
  311. // XXX If the calendar feature is disabled on a platform, then we don't
  312. // have its components exported so an undefined check is necessary.
  313. return (
  314. !this.props._reducedUI && ConferenceNotification
  315. ? <ConferenceNotification />
  316. : undefined);
  317. }
  318. /**
  319. * Renders a container for notifications to be displayed by the
  320. * base/notifications feature.
  321. *
  322. * @private
  323. * @returns {React$Element}
  324. */
  325. _renderNotificationsContainer() {
  326. const notificationsStyle = {};
  327. // In the landscape mode (wide) there's problem with notifications being
  328. // shadowed by the filmstrip rendered on the right. This makes the "x"
  329. // button not clickable. In order to avoid that a margin of the
  330. // filmstrip's size is added to the right.
  331. //
  332. // Pawel: after many attempts I failed to make notifications adjust to
  333. // their contents width because of column and rows being used in the
  334. // flex layout. The only option that seemed to limit the notification's
  335. // size was explicit 'width' value which is not better than the margin
  336. // added here.
  337. if (this.props._filmstripVisible && !isNarrowAspectRatio(this)) {
  338. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  339. }
  340. return <NotificationsContainer style = { notificationsStyle } />;
  341. }
  342. }
  343. /**
  344. * Maps dispatching of some action to React component props.
  345. *
  346. * @param {Function} dispatch - Redux action dispatcher.
  347. * @private
  348. * @returns {{
  349. * _onConnect: Function,
  350. * _onDisconnect: Function,
  351. * _onHardwareBackPress: Function,
  352. * _setToolboxVisible: Function
  353. * }}
  354. */
  355. function _mapDispatchToProps(dispatch) {
  356. return {
  357. /**
  358. * Dispatches actions to create the desired local tracks and for
  359. * connecting to the conference.
  360. *
  361. * @private
  362. * @returns {void}
  363. */
  364. _onConnect() {
  365. dispatch(createDesiredLocalTracks());
  366. dispatch(connect());
  367. },
  368. /**
  369. * Dispatches an action disconnecting from the conference.
  370. *
  371. * @private
  372. * @returns {void}
  373. */
  374. _onDisconnect() {
  375. dispatch(disconnect());
  376. },
  377. /**
  378. * Handles a hardware button press for back navigation. Leaves the
  379. * associated {@code Conference}.
  380. *
  381. * @returns {boolean} As the associated conference is unconditionally
  382. * left and exiting the app while it renders a {@code Conference} is
  383. * undesired, {@code true} is always returned.
  384. */
  385. _onHardwareBackPress() {
  386. dispatch(appNavigate(undefined));
  387. return true;
  388. },
  389. /**
  390. * Dispatches an action changing the visibility of the {@link Toolbox}.
  391. *
  392. * @param {boolean} visible - {@code true} to show the {@code Toolbox}
  393. * or {@code false} to hide it.
  394. * @private
  395. * @returns {void}
  396. */
  397. _setToolboxVisible(visible) {
  398. dispatch(setToolboxVisible(visible));
  399. }
  400. };
  401. }
  402. /**
  403. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  404. *
  405. * @param {Object} state - The redux state.
  406. * @private
  407. * @returns {{
  408. * _connecting: boolean,
  409. * _filmstripVisible: boolean,
  410. * _locationURL: URL,
  411. * _participantCount: number,
  412. * _reducedUI: boolean,
  413. * _room: string,
  414. * _toolboxVisible: boolean,
  415. * _toolboxAlwaysVisible: boolean
  416. * }}
  417. */
  418. function _mapStateToProps(state) {
  419. const { connecting, connection, locationURL }
  420. = state['features/base/connection'];
  421. const {
  422. conference,
  423. joining,
  424. leaving,
  425. room
  426. } = state['features/base/conference'];
  427. const { reducedUI } = state['features/base/responsive-ui'];
  428. const { alwaysVisible, visible } = state['features/toolbox'];
  429. // XXX There is a window of time between the successful establishment of the
  430. // XMPP connection and the subsequent commencement of joining the MUC during
  431. // which the app does not appear to be doing anything according to the redux
  432. // state. In order to not toggle the _connecting props during the window of
  433. // time in question, define _connecting as follows:
  434. // - the XMPP connection is connecting, or
  435. // - the XMPP connection is connected and the conference is joining, or
  436. // - the XMPP connection is connected and we have no conference yet, nor we
  437. // are leaving one.
  438. const connecting_
  439. = connecting || (connection && (joining || (!conference && !leaving)));
  440. return {
  441. /**
  442. * The indicator which determines that we are still connecting to the
  443. * conference which includes establishing the XMPP connection and then
  444. * joining the room. If truthy, then an activity/loading indicator will
  445. * be rendered.
  446. *
  447. * @private
  448. * @type {boolean}
  449. */
  450. _connecting: Boolean(connecting_),
  451. /**
  452. * Is {@code true} when the filmstrip is currently visible.
  453. */
  454. _filmstripVisible: isFilmstripVisible(state),
  455. /**
  456. * Current conference's full URL.
  457. *
  458. * @private
  459. * @type {URL}
  460. */
  461. _locationURL: locationURL,
  462. /**
  463. * The number of participants in the conference.
  464. *
  465. * @private
  466. * @type {number}
  467. */
  468. _participantCount: getParticipantCount(state),
  469. /**
  470. * The indicator which determines whether the UI is reduced (to
  471. * accommodate smaller display areas).
  472. *
  473. * @private
  474. * @type {boolean}
  475. */
  476. _reducedUI: reducedUI,
  477. /**
  478. * The current conference room name.
  479. *
  480. * @private
  481. * @type {string}
  482. */
  483. _room: room,
  484. /**
  485. * The indicator which determines whether the Toolbox is visible.
  486. *
  487. * @private
  488. * @type {boolean}
  489. */
  490. _toolboxVisible: visible,
  491. /**
  492. * The indicator which determines whether the Toolbox is always visible.
  493. *
  494. * @private
  495. * @type {boolean}
  496. */
  497. _toolboxAlwaysVisible: alwaysVisible
  498. };
  499. }
  500. // $FlowFixMe
  501. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  502. makeAspectRatioAware(Conference));