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

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