Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Conference.native.js 13KB

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