Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

Conference.native.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 { TestConnectionInfo } from '../../base/testing';
  12. import { createDesiredLocalTracks } from '../../base/tracks';
  13. import { ConferenceNotification } from '../../calendar-sync';
  14. import { Filmstrip } from '../../filmstrip';
  15. import { LargeVideo } from '../../large-video';
  16. import { setToolboxVisible, Toolbox } from '../../toolbox';
  17. import styles from './styles';
  18. /**
  19. * The type of the React {@code Component} props of {@link Conference}.
  20. */
  21. type Props = {
  22. /**
  23. * The indicator which determines that we are still connecting to the
  24. * conference which includes establishing the XMPP connection and then
  25. * joining the room. If truthy, then an activity/loading indicator will
  26. * be rendered.
  27. *
  28. * @private
  29. */
  30. _connecting: boolean,
  31. /**
  32. * The handler which dispatches the (redux) action connect.
  33. *
  34. * @private
  35. */
  36. _onConnect: Function,
  37. /**
  38. * The handler which dispatches the (redux) action disconnect.
  39. *
  40. * @private
  41. */
  42. _onDisconnect: Function,
  43. /**
  44. * Handles a hardware button press for back navigation. Leaves the
  45. * associated {@code Conference}.
  46. *
  47. * @private
  48. * @returns {boolean} As the associated conference is unconditionally
  49. * left and exiting the app while it renders a {@code Conference} is
  50. * undesired, {@code true} is always returned.
  51. */
  52. _onHardwareBackPress: Function,
  53. /**
  54. * The number of participants in the conference.
  55. *
  56. * @private
  57. */
  58. _participantCount: number,
  59. /**
  60. * The indicator which determines whether the UI is reduced (to accommodate
  61. * smaller display areas).
  62. *
  63. * @private
  64. */
  65. _reducedUI: boolean,
  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. /**
  86. * Initializes a new Conference instance.
  87. *
  88. * @param {Object} props - The read-only properties with which the new
  89. * instance is to be initialized.
  90. */
  91. constructor(props) {
  92. super(props);
  93. // Bind event handlers so they are only bound once per instance.
  94. this._onClick = this._onClick.bind(this);
  95. this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
  96. }
  97. /**
  98. * Implements {@link Component#componentDidMount()}. Invoked immediately
  99. * after this component is mounted.
  100. *
  101. * @inheritdoc
  102. * @returns {void}
  103. */
  104. componentDidMount() {
  105. // Set handling any hardware button presses for back navigation up.
  106. const backHandler = BackHandler || BackAndroid;
  107. if (backHandler) {
  108. this._backHandler = backHandler;
  109. backHandler.addEventListener(
  110. 'hardwareBackPress',
  111. this._onHardwareBackPress);
  112. }
  113. // Show the toolbox if we are the only participant; otherwise, the whole
  114. // UI looks too unpopulated the LargeVideo visible.
  115. const { _participantCount, _setToolboxVisible } = this.props;
  116. _participantCount === 1 && _setToolboxVisible(true);
  117. }
  118. /**
  119. * Implements {@link Component#componentWillMount()}. Invoked immediately
  120. * before mounting occurs. Connects the conference described by the redux
  121. * store/state.
  122. *
  123. * @inheritdoc
  124. * @returns {void}
  125. */
  126. componentWillMount() {
  127. this.props._onConnect();
  128. }
  129. /**
  130. * Notifies this mounted React {@code Component} that it will receive new
  131. * props. Check if we need to show / hide the toolbox based on the
  132. * participant count.
  133. *
  134. * @inheritdoc
  135. * @param {Object} nextProps - The read-only React {@code Component} props
  136. * that this instance will receive.
  137. * @returns {void}
  138. */
  139. componentWillReceiveProps({ _participantCount: newParticipantCount }) {
  140. const {
  141. _participantCount: oldParticipantCount,
  142. _setToolboxVisible
  143. } = this.props;
  144. if (oldParticipantCount === 1) {
  145. newParticipantCount > 1 && _setToolboxVisible(false);
  146. } else if (oldParticipantCount > 1) {
  147. newParticipantCount === 1 && _setToolboxVisible(true);
  148. }
  149. }
  150. /**
  151. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  152. * before this component is unmounted and destroyed. Disconnects the
  153. * conference described by the redux store/state.
  154. *
  155. * @inheritdoc
  156. * @returns {void}
  157. */
  158. componentWillUnmount() {
  159. // Tear handling any hardware button presses for back navigation down.
  160. const backHandler = this._backHandler;
  161. if (backHandler) {
  162. this._backHandler = undefined;
  163. backHandler.removeEventListener(
  164. 'hardwareBackPress',
  165. this._onHardwareBackPress);
  166. }
  167. this.props._onDisconnect();
  168. }
  169. /**
  170. * Implements React's {@link Component#render()}.
  171. *
  172. * @inheritdoc
  173. * @returns {ReactElement}
  174. */
  175. render() {
  176. return (
  177. <Container style = { styles.conference }>
  178. <StatusBar
  179. barStyle = 'light-content'
  180. hidden = { true }
  181. translucent = { true } />
  182. {/*
  183. * The LargeVideo is the lowermost stacking layer.
  184. */}
  185. <LargeVideo onPress = { this._onClick } />
  186. {/*
  187. * If there is a ringing call, show the callee's info.
  188. */
  189. this.props._reducedUI || <CalleeInfoContainer />
  190. }
  191. {/*
  192. * The activity/loading indicator goes above everything, except
  193. * the toolbox/toolbars and the dialogs.
  194. */
  195. this.props._connecting
  196. && <TintedView>
  197. <LoadingIndicator />
  198. </TintedView>
  199. }
  200. <View
  201. pointerEvents = 'box-none'
  202. style = { styles.toolboxAndFilmstripContainer }>
  203. {/*
  204. * The Toolbox is in a stacking layer bellow the Filmstrip.
  205. */}
  206. <Toolbox />
  207. {/*
  208. * The Filmstrip is in a stacking layer above the
  209. * LargeVideo. The LargeVideo and the Filmstrip form what
  210. * the Web/React app calls "videospace". Presumably, the
  211. * name and grouping stem from the fact that these two
  212. * React Components depict the videos of the conference's
  213. * participants.
  214. */}
  215. <Filmstrip />
  216. </View>
  217. <TestConnectionInfo />
  218. {
  219. this._renderConferenceNotification()
  220. }
  221. {/*
  222. * The dialogs are in the topmost stacking layers.
  223. */
  224. this.props._reducedUI || <DialogContainer />
  225. }
  226. </Container>
  227. );
  228. }
  229. _onClick: () => void;
  230. /**
  231. * Changes the value of the toolboxVisible state, thus allowing us to switch
  232. * between Toolbox and Filmstrip and change their visibility.
  233. *
  234. * @private
  235. * @returns {void}
  236. */
  237. _onClick() {
  238. const toolboxVisible = !this.props._toolboxVisible;
  239. this.props._setToolboxVisible(toolboxVisible);
  240. }
  241. _onHardwareBackPress: () => boolean;
  242. /**
  243. * Handles a hardware button press for back navigation.
  244. *
  245. * @returns {boolean} If the hardware button press for back navigation was
  246. * handled by this {@code Conference}, then {@code true}; otherwise,
  247. * {@code false}.
  248. */
  249. _onHardwareBackPress() {
  250. return this._backHandler && this.props._onHardwareBackPress();
  251. }
  252. /**
  253. * Renders the conference notification badge if the feature is enabled.
  254. *
  255. * Note: If the calendar feature is disabled on a platform, then we don't
  256. * have its components exported so an undefined check is necessary.
  257. *
  258. * @private
  259. * @returns {React$Node}
  260. */
  261. _renderConferenceNotification() {
  262. return ConferenceNotification
  263. ? <ConferenceNotification />
  264. : undefined;
  265. }
  266. }
  267. /**
  268. * Maps dispatching of some action to React component props.
  269. *
  270. * @param {Function} dispatch - Redux action dispatcher.
  271. * @private
  272. * @returns {{
  273. * _onConnect: Function,
  274. * _onDisconnect: Function,
  275. * _setToolboxVisible: Function
  276. * }}
  277. */
  278. function _mapDispatchToProps(dispatch) {
  279. return {
  280. /**
  281. * Dispatches actions to create the desired local tracks and for
  282. * connecting to the conference.
  283. *
  284. * @returns {void}
  285. * @private
  286. */
  287. _onConnect() {
  288. dispatch(createDesiredLocalTracks());
  289. dispatch(connect());
  290. },
  291. /**
  292. * Dispatches an action disconnecting from the conference.
  293. *
  294. * @returns {void}
  295. * @private
  296. */
  297. _onDisconnect() {
  298. dispatch(disconnect());
  299. },
  300. /**
  301. * Handles a hardware button press for back navigation. Leaves the
  302. * associated {@code Conference}.
  303. *
  304. * @returns {boolean} As the associated conference is unconditionally
  305. * left and exiting the app while it renders a {@code Conference} is
  306. * undesired, {@code true} is always returned.
  307. */
  308. _onHardwareBackPress() {
  309. dispatch(appNavigate(undefined));
  310. return true;
  311. },
  312. /**
  313. * Dispatches an action changing the visibility of the Toolbox.
  314. *
  315. * @param {boolean} visible - True to show the Toolbox or false to hide
  316. * it.
  317. * @returns {void}
  318. * @private
  319. */
  320. _setToolboxVisible(visible) {
  321. dispatch(setToolboxVisible(visible));
  322. }
  323. };
  324. }
  325. /**
  326. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  327. *
  328. * @param {Object} state - The redux state.
  329. * @private
  330. * @returns {{
  331. * _connecting: boolean,
  332. * _participantCount: number,
  333. * _reducedUI: boolean,
  334. * _toolboxVisible: boolean
  335. * }}
  336. */
  337. function _mapStateToProps(state) {
  338. const { connecting, connection } = state['features/base/connection'];
  339. const { conference, joining, leaving } = state['features/base/conference'];
  340. const { reducedUI } = state['features/base/responsive-ui'];
  341. const participants = state['features/base/participants'];
  342. // XXX There is a window of time between the successful establishment of the
  343. // XMPP connection and the subsequent commencement of joining the MUC during
  344. // which the app does not appear to be doing anything according to the redux
  345. // state. In order to not toggle the _connecting props during the window of
  346. // time in question, define _connecting as follows:
  347. // - the XMPP connection is connecting, or
  348. // - the XMPP connection is connected and the conference is joining, or
  349. // - the XMPP connection is connected and we have no conference yet, nor we
  350. // are leaving one.
  351. const connecting_
  352. = connecting || (connection && (joining || (!conference && !leaving)));
  353. return {
  354. /**
  355. * The indicator which determines that we are still connecting to the
  356. * conference which includes establishing the XMPP connection and then
  357. * joining the room. If truthy, then an activity/loading indicator will
  358. * be rendered.
  359. *
  360. * @private
  361. * @type {boolean}
  362. */
  363. _connecting: Boolean(connecting_),
  364. /**
  365. * The number of participants in the conference.
  366. *
  367. * @private
  368. * @type {number}
  369. */
  370. _participantCount: participants.length,
  371. /**
  372. * The indicator which determines whether the UI is reduced (to
  373. * accommodate smaller display areas).
  374. *
  375. * @private
  376. * @type {boolean}
  377. */
  378. _reducedUI: reducedUI,
  379. /**
  380. * The indicator which determines whether the Toolbox is visible.
  381. *
  382. * @private
  383. * @type {boolean}
  384. */
  385. _toolboxVisible: state['features/toolbox'].visible
  386. };
  387. }
  388. // $FlowFixMe
  389. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  390. Conference);