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

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