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

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