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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import PropTypes from 'prop-types';
  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 conference page of the mobile (i.e. React Native) application.
  25. */
  26. class Conference extends Component {
  27. /**
  28. * Conference component's property types.
  29. *
  30. * @static
  31. */
  32. static propTypes = {
  33. /**
  34. * The indicator which determines that we are still connecting to the
  35. * conference which includes establishing the XMPP connection and then
  36. * joining the room. If truthy, then an activity/loading indicator will
  37. * be rendered.
  38. *
  39. * @private
  40. */
  41. _connecting: PropTypes.bool,
  42. /**
  43. * The handler which dispatches the (redux) action connect.
  44. *
  45. * @private
  46. */
  47. _onConnect: PropTypes.func,
  48. /**
  49. * The handler which dispatches the (redux) action disconnect.
  50. *
  51. * @private
  52. */
  53. _onDisconnect: PropTypes.func,
  54. /**
  55. * Handles a hardware button press for back navigation. Leaves the
  56. * associated {@code Conference}.
  57. *
  58. * @private
  59. * @returns {boolean} As the associated conference is unconditionally
  60. * left and exiting the app while it renders a {@code Conference} is
  61. * undesired, {@code true} is always returned.
  62. */
  63. _onHardwareBackPress: PropTypes.func,
  64. /**
  65. * The handler which dispatches the (redux) action setToolboxVisible to
  66. * show/hide the Toolbox.
  67. *
  68. * @private
  69. */
  70. _setToolboxVisible: PropTypes.func,
  71. /**
  72. * The indicator which determines whether the Toolbox is visible.
  73. *
  74. * @private
  75. */
  76. _toolboxVisible: PropTypes.bool
  77. };
  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. onClick = { this._onClick }
  157. style = { styles.conference }
  158. touchFeedback = { false }>
  159. {/*
  160. * The LargeVideo is the lowermost stacking layer.
  161. */}
  162. <LargeVideo />
  163. {/*
  164. * The Filmstrip is in a stacking layer above the LargeVideo.
  165. * The LargeVideo and the Filmstrip form what the Web/React app
  166. * calls "videospace". Presumably, the name and grouping stem
  167. * from the fact that these two React Components depict the
  168. * videos of the conference's participants.
  169. */}
  170. <Filmstrip />
  171. {/*
  172. * The overlays need to be bellow the Toolbox so that the user
  173. * may tap the ToolbarButtons.
  174. */}
  175. <OverlayContainer />
  176. {/*
  177. * The activity/loading indicator goes above everything, except
  178. * the toolbox/toolbars and the dialogs.
  179. */
  180. this.props._connecting
  181. && <View style = { styles.connectingIndicator }>
  182. <LoadingIndicator />
  183. </View>
  184. }
  185. {/*
  186. * The Toolbox is in a stacking layer above the Filmstrip.
  187. */}
  188. <Toolbox />
  189. {/*
  190. * The dialogs are in the topmost stacking layers.
  191. */}
  192. <DialogContainer />
  193. </Container>
  194. );
  195. }
  196. /**
  197. * Clears {@link #_toolboxTimeout} if any.
  198. *
  199. * @private
  200. * @returns {void}
  201. */
  202. _clearToolboxTimeout() {
  203. if (this._toolboxTimeout) {
  204. clearTimeout(this._toolboxTimeout);
  205. this._toolboxTimeout = undefined;
  206. }
  207. }
  208. /**
  209. * Changes the value of the toolboxVisible state, thus allowing us to switch
  210. * between Toolbox and Filmstrip and change their visibility.
  211. *
  212. * @private
  213. * @returns {void}
  214. */
  215. _onClick() {
  216. const toolboxVisible = !this.props._toolboxVisible;
  217. this.props._setToolboxVisible(toolboxVisible);
  218. this._setToolboxTimeout(toolboxVisible);
  219. }
  220. /**
  221. * Handles a hardware button press for back navigation.
  222. *
  223. * @returns {boolean} If the hardware button press for back navigation was
  224. * handled by this {@code Conference}, then {@code true}; otherwise,
  225. * {@code false}.
  226. */
  227. _onHardwareBackPress() {
  228. return this._backHandler && this.props._onHardwareBackPress();
  229. }
  230. /**
  231. * Triggers the default Toolbox timeout.
  232. *
  233. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  234. * currently visible.
  235. * @private
  236. * @returns {void}
  237. */
  238. _setToolboxTimeout(toolboxVisible) {
  239. this._clearToolboxTimeout();
  240. if (toolboxVisible) {
  241. this._toolboxTimeout
  242. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  243. }
  244. }
  245. }
  246. /**
  247. * Maps dispatching of some action to React component props.
  248. *
  249. * @param {Function} dispatch - Redux action dispatcher.
  250. * @private
  251. * @returns {{
  252. * _onConnect: Function,
  253. * _onDisconnect: Function,
  254. * _setToolboxVisible: Function
  255. * }}
  256. */
  257. function _mapDispatchToProps(dispatch) {
  258. return {
  259. /**
  260. * Dispatches actions to create the desired local tracks and for
  261. * connecting to the conference.
  262. *
  263. * @returns {void}
  264. * @private
  265. */
  266. _onConnect() {
  267. dispatch(createDesiredLocalTracks());
  268. dispatch(connect());
  269. },
  270. /**
  271. * Dispatches an action disconnecting from the conference.
  272. *
  273. * @returns {void}
  274. * @private
  275. */
  276. _onDisconnect() {
  277. dispatch(disconnect());
  278. },
  279. /**
  280. * Handles a hardware button press for back navigation. Leaves the
  281. * associated {@code Conference}.
  282. *
  283. * @returns {boolean} As the associated conference is unconditionally
  284. * left and exiting the app while it renders a {@code Conference} is
  285. * undesired, {@code true} is always returned.
  286. */
  287. _onHardwareBackPress() {
  288. dispatch(appNavigate(undefined));
  289. return true;
  290. },
  291. /**
  292. * Dispatches an action changing the visibility of the Toolbox.
  293. *
  294. * @param {boolean} visible - True to show the Toolbox or false to hide
  295. * it.
  296. * @returns {void}
  297. * @private
  298. */
  299. _setToolboxVisible(visible: boolean) {
  300. dispatch(setToolboxVisible(visible));
  301. }
  302. };
  303. }
  304. /**
  305. * Maps (parts of) the Redux state to the associated Conference's props.
  306. *
  307. * @param {Object} state - The Redux state.
  308. * @private
  309. * @returns {{
  310. * _connecting: boolean,
  311. * _toolboxVisible: boolean
  312. * }}
  313. */
  314. function _mapStateToProps(state) {
  315. const { connecting, connection } = state['features/base/connection'];
  316. const { conference, joining, leaving } = state['features/base/conference'];
  317. // XXX There is a window of time between the successful establishment of the
  318. // XMPP connection and the subsequent commencement of joining the MUC during
  319. // which the app does not appear to be doing anything according to the redux
  320. // state. In order to not toggle the _connecting props during the window of
  321. // time in question, define _connecting as follows:
  322. // - the XMPP connection is connecting, or
  323. // - the XMPP connection is connected and the conference is joining, or
  324. // - the XMPP connection is connected and we have no conference yet, nor we
  325. // are leaving one.
  326. const connecting_
  327. = connecting || (connection && (joining || (!conference && !leaving)));
  328. return {
  329. /**
  330. * The indicator which determines that we are still connecting to the
  331. * conference which includes establishing the XMPP connection and then
  332. * joining the room. If truthy, then an activity/loading indicator will
  333. * be rendered.
  334. *
  335. * @private
  336. * @type {boolean}
  337. */
  338. _connecting: Boolean(connecting_),
  339. /**
  340. * The indicator which determines whether the Toolbox is visible.
  341. *
  342. * @private
  343. * @type {boolean}
  344. */
  345. _toolboxVisible: state['features/toolbox'].visible
  346. };
  347. }
  348. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  349. Conference);