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

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