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

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