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

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