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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 { 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 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. * If there is a ringing call, show the callee's info.
  167. */}
  168. <CalleeInfoContainer />
  169. {/*
  170. * The activity/loading indicator goes above everything, except
  171. * the toolbox/toolbars and the dialogs.
  172. */
  173. this.props._connecting
  174. && <TintedView>
  175. <LoadingIndicator />
  176. </TintedView>
  177. }
  178. <View style = { styles.toolboxAndFilmstripContainer } >
  179. {/*
  180. * The Toolbox is in a stacking layer bellow the Filmstrip.
  181. */}
  182. <Toolbox />
  183. {/*
  184. * The Filmstrip is in a stacking layer above the
  185. * LargeVideo. The LargeVideo and the Filmstrip form what
  186. * the Web/React app calls "videospace". Presumably, the
  187. * name and grouping stem from the fact that these two
  188. * React Components depict the videos of the conference's
  189. * participants.
  190. */}
  191. <Filmstrip />
  192. </View>
  193. {/*
  194. * The dialogs are in the topmost stacking layers.
  195. */}
  196. <DialogContainer />
  197. </Container>
  198. );
  199. }
  200. /**
  201. * Clears {@link #_toolboxTimeout} if any.
  202. *
  203. * @private
  204. * @returns {void}
  205. */
  206. _clearToolboxTimeout() {
  207. if (this._toolboxTimeout) {
  208. clearTimeout(this._toolboxTimeout);
  209. this._toolboxTimeout = undefined;
  210. }
  211. }
  212. _onClick: () => void;
  213. /**
  214. * Changes the value of the toolboxVisible state, thus allowing us to switch
  215. * between Toolbox and Filmstrip and change their visibility.
  216. *
  217. * @private
  218. * @returns {void}
  219. */
  220. _onClick() {
  221. const toolboxVisible = !this.props._toolboxVisible;
  222. this.props._setToolboxVisible(toolboxVisible);
  223. // XXX If the user taps to toggle the visibility of the Toolbox, then no
  224. // automatic toggling of the visibility should happen.
  225. this._clearToolboxTimeout();
  226. }
  227. _onHardwareBackPress: () => boolean;
  228. /**
  229. * Handles a hardware button press for back navigation.
  230. *
  231. * @returns {boolean} If the hardware button press for back navigation was
  232. * handled by this {@code Conference}, then {@code true}; otherwise,
  233. * {@code false}.
  234. */
  235. _onHardwareBackPress() {
  236. return this._backHandler && this.props._onHardwareBackPress();
  237. }
  238. /**
  239. * Triggers the default Toolbox timeout.
  240. *
  241. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  242. * currently visible.
  243. * @private
  244. * @returns {void}
  245. */
  246. _setToolboxTimeout(toolboxVisible) {
  247. this._clearToolboxTimeout();
  248. if (toolboxVisible) {
  249. this._toolboxTimeout
  250. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  251. }
  252. }
  253. }
  254. /**
  255. * Maps dispatching of some action to React component props.
  256. *
  257. * @param {Function} dispatch - Redux action dispatcher.
  258. * @private
  259. * @returns {{
  260. * _onConnect: Function,
  261. * _onDisconnect: Function,
  262. * _setToolboxVisible: Function
  263. * }}
  264. */
  265. function _mapDispatchToProps(dispatch) {
  266. return {
  267. /**
  268. * Dispatches actions to create the desired local tracks and for
  269. * connecting to the conference.
  270. *
  271. * @returns {void}
  272. * @private
  273. */
  274. _onConnect() {
  275. dispatch(createDesiredLocalTracks());
  276. dispatch(connect());
  277. },
  278. /**
  279. * Dispatches an action disconnecting from the conference.
  280. *
  281. * @returns {void}
  282. * @private
  283. */
  284. _onDisconnect() {
  285. dispatch(disconnect());
  286. },
  287. /**
  288. * Handles a hardware button press for back navigation. Leaves the
  289. * associated {@code Conference}.
  290. *
  291. * @returns {boolean} As the associated conference is unconditionally
  292. * left and exiting the app while it renders a {@code Conference} is
  293. * undesired, {@code true} is always returned.
  294. */
  295. _onHardwareBackPress() {
  296. dispatch(appNavigate(undefined));
  297. return true;
  298. },
  299. /**
  300. * Dispatches an action changing the visibility of the Toolbox.
  301. *
  302. * @param {boolean} visible - True to show the Toolbox or false to hide
  303. * it.
  304. * @returns {void}
  305. * @private
  306. */
  307. _setToolboxVisible(visible) {
  308. dispatch(setToolboxVisible(visible));
  309. }
  310. };
  311. }
  312. /**
  313. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  314. *
  315. * @param {Object} state - The redux state.
  316. * @private
  317. * @returns {{
  318. * _connecting: boolean,
  319. * _toolboxVisible: boolean
  320. * }}
  321. */
  322. function _mapStateToProps(state) {
  323. const { connecting, connection } = state['features/base/connection'];
  324. const { conference, joining, leaving } = state['features/base/conference'];
  325. // XXX There is a window of time between the successful establishment of the
  326. // XMPP connection and the subsequent commencement of joining the MUC during
  327. // which the app does not appear to be doing anything according to the redux
  328. // state. In order to not toggle the _connecting props during the window of
  329. // time in question, define _connecting as follows:
  330. // - the XMPP connection is connecting, or
  331. // - the XMPP connection is connected and the conference is joining, or
  332. // - the XMPP connection is connected and we have no conference yet, nor we
  333. // are leaving one.
  334. const connecting_
  335. = connecting || (connection && (joining || (!conference && !leaving)));
  336. return {
  337. /**
  338. * The indicator which determines that we are still connecting to the
  339. * conference which includes establishing the XMPP connection and then
  340. * joining the room. If truthy, then an activity/loading indicator will
  341. * be rendered.
  342. *
  343. * @private
  344. * @type {boolean}
  345. */
  346. _connecting: Boolean(connecting_),
  347. /**
  348. * The indicator which determines whether the Toolbox is visible.
  349. *
  350. * @private
  351. * @type {boolean}
  352. */
  353. _toolboxVisible: state['features/toolbox'].visible
  354. };
  355. }
  356. // $FlowFixMe
  357. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  358. Conference);