您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.native.js 12KB

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