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 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 { getParticipantCount } from '../../base/participants';
  11. import { Container, LoadingIndicator, TintedView } from '../../base/react';
  12. import { TestConnectionInfo } from '../../base/testing';
  13. import { createDesiredLocalTracks } from '../../base/tracks';
  14. import { ConferenceNotification } from '../../calendar-sync';
  15. import { Filmstrip } from '../../filmstrip';
  16. import { LargeVideo } from '../../large-video';
  17. import { setToolboxVisible, Toolbox } from '../../toolbox';
  18. import styles from './styles';
  19. /**
  20. * The type of the React {@code Component} props of {@link Conference}.
  21. */
  22. type Props = {
  23. /**
  24. * The indicator which determines that we are still connecting to the
  25. * conference which includes establishing the XMPP connection and then
  26. * joining the room. If truthy, then an activity/loading indicator will
  27. * be rendered.
  28. *
  29. * @private
  30. */
  31. _connecting: boolean,
  32. /**
  33. * The handler which dispatches the (redux) action connect.
  34. *
  35. * @private
  36. */
  37. _onConnect: Function,
  38. /**
  39. * The handler which dispatches the (redux) action disconnect.
  40. *
  41. * @private
  42. */
  43. _onDisconnect: Function,
  44. /**
  45. * Handles a hardware button press for back navigation. Leaves the
  46. * associated {@code Conference}.
  47. *
  48. * @private
  49. * @returns {boolean} As the associated conference is unconditionally
  50. * left and exiting the app while it renders a {@code Conference} is
  51. * undesired, {@code true} is always returned.
  52. */
  53. _onHardwareBackPress: Function,
  54. /**
  55. * The number of participants in the conference.
  56. *
  57. * @private
  58. */
  59. _participantCount: number,
  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. /**
  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. // 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. // Show the toolbox if we are the only participant; otherwise, the whole
  115. // UI looks too unpopulated the LargeVideo visible.
  116. const { _participantCount, _setToolboxVisible } = this.props;
  117. _participantCount === 1 && _setToolboxVisible(true);
  118. }
  119. /**
  120. * Implements {@link Component#componentWillMount()}. Invoked immediately
  121. * before mounting occurs. Connects the conference described by the redux
  122. * store/state.
  123. *
  124. * @inheritdoc
  125. * @returns {void}
  126. */
  127. componentWillMount() {
  128. this.props._onConnect();
  129. }
  130. /**
  131. * Notifies this mounted React {@code Component} that it will receive new
  132. * props. Check if we need to show / hide the toolbox based on the
  133. * participant count.
  134. *
  135. * @inheritdoc
  136. * @param {Object} nextProps - The read-only React {@code Component} props
  137. * that this instance will receive.
  138. * @returns {void}
  139. */
  140. componentWillReceiveProps({ _participantCount: newParticipantCount }) {
  141. const {
  142. _participantCount: oldParticipantCount,
  143. _setToolboxVisible
  144. } = this.props;
  145. if (oldParticipantCount === 1) {
  146. newParticipantCount > 1 && _setToolboxVisible(false);
  147. } else if (oldParticipantCount > 1) {
  148. newParticipantCount === 1 && _setToolboxVisible(true);
  149. }
  150. }
  151. /**
  152. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  153. * before this component is unmounted and destroyed. Disconnects the
  154. * conference described by the redux store/state.
  155. *
  156. * @inheritdoc
  157. * @returns {void}
  158. */
  159. componentWillUnmount() {
  160. // Tear handling any hardware button presses for back navigation down.
  161. const backHandler = this._backHandler;
  162. if (backHandler) {
  163. this._backHandler = undefined;
  164. backHandler.removeEventListener(
  165. 'hardwareBackPress',
  166. this._onHardwareBackPress);
  167. }
  168. this.props._onDisconnect();
  169. }
  170. /**
  171. * Implements React's {@link Component#render()}.
  172. *
  173. * @inheritdoc
  174. * @returns {ReactElement}
  175. */
  176. render() {
  177. return (
  178. <Container style = { styles.conference }>
  179. <StatusBar
  180. barStyle = 'light-content'
  181. hidden = { true }
  182. translucent = { true } />
  183. {/*
  184. * The LargeVideo is the lowermost stacking layer.
  185. */}
  186. <LargeVideo onPress = { this._onClick } />
  187. {/*
  188. * If there is a ringing call, show the callee's info.
  189. */
  190. this.props._reducedUI || <CalleeInfoContainer />
  191. }
  192. {/*
  193. * The activity/loading indicator goes above everything, except
  194. * the toolbox/toolbars and the dialogs.
  195. */
  196. this.props._connecting
  197. && <TintedView>
  198. <LoadingIndicator />
  199. </TintedView>
  200. }
  201. <View
  202. pointerEvents = 'box-none'
  203. style = { styles.toolboxAndFilmstripContainer }>
  204. {/*
  205. * The Toolbox is in a stacking layer bellow the Filmstrip.
  206. */}
  207. <Toolbox />
  208. {/*
  209. * The Filmstrip is in a stacking layer above the
  210. * LargeVideo. The LargeVideo and the Filmstrip form what
  211. * the Web/React app calls "videospace". Presumably, the
  212. * name and grouping stem from the fact that these two
  213. * React Components depict the videos of the conference's
  214. * participants.
  215. */}
  216. <Filmstrip />
  217. </View>
  218. <TestConnectionInfo />
  219. {
  220. this._renderConferenceNotification()
  221. }
  222. {/*
  223. * The dialogs are in the topmost stacking layers.
  224. */
  225. this.props._reducedUI || <DialogContainer />
  226. }
  227. </Container>
  228. );
  229. }
  230. _onClick: () => void;
  231. /**
  232. * Changes the value of the toolboxVisible state, thus allowing us to switch
  233. * between Toolbox and Filmstrip and change their visibility.
  234. *
  235. * @private
  236. * @returns {void}
  237. */
  238. _onClick() {
  239. const toolboxVisible = !this.props._toolboxVisible;
  240. this.props._setToolboxVisible(toolboxVisible);
  241. }
  242. _onHardwareBackPress: () => boolean;
  243. /**
  244. * Handles a hardware button press for back navigation.
  245. *
  246. * @returns {boolean} If the hardware button press for back navigation was
  247. * handled by this {@code Conference}, then {@code true}; otherwise,
  248. * {@code false}.
  249. */
  250. _onHardwareBackPress() {
  251. return this._backHandler && this.props._onHardwareBackPress();
  252. }
  253. /**
  254. * Renders the conference notification badge if the feature is enabled.
  255. *
  256. * Note: If the calendar feature is disabled on a platform, then we don't
  257. * have its components exported so an undefined check is necessary.
  258. *
  259. * @private
  260. * @returns {React$Node}
  261. */
  262. _renderConferenceNotification() {
  263. return ConferenceNotification
  264. ? <ConferenceNotification />
  265. : undefined;
  266. }
  267. }
  268. /**
  269. * Maps dispatching of some action to React component props.
  270. *
  271. * @param {Function} dispatch - Redux action dispatcher.
  272. * @private
  273. * @returns {{
  274. * _onConnect: Function,
  275. * _onDisconnect: Function,
  276. * _setToolboxVisible: Function
  277. * }}
  278. */
  279. function _mapDispatchToProps(dispatch) {
  280. return {
  281. /**
  282. * Dispatches actions to create the desired local tracks and for
  283. * connecting to the conference.
  284. *
  285. * @returns {void}
  286. * @private
  287. */
  288. _onConnect() {
  289. dispatch(createDesiredLocalTracks());
  290. dispatch(connect());
  291. },
  292. /**
  293. * Dispatches an action disconnecting from the conference.
  294. *
  295. * @returns {void}
  296. * @private
  297. */
  298. _onDisconnect() {
  299. dispatch(disconnect());
  300. },
  301. /**
  302. * Handles a hardware button press for back navigation. Leaves the
  303. * associated {@code Conference}.
  304. *
  305. * @returns {boolean} As the associated conference is unconditionally
  306. * left and exiting the app while it renders a {@code Conference} is
  307. * undesired, {@code true} is always returned.
  308. */
  309. _onHardwareBackPress() {
  310. dispatch(appNavigate(undefined));
  311. return true;
  312. },
  313. /**
  314. * Dispatches an action changing the visibility of the Toolbox.
  315. *
  316. * @param {boolean} visible - True to show the Toolbox or false to hide
  317. * it.
  318. * @returns {void}
  319. * @private
  320. */
  321. _setToolboxVisible(visible) {
  322. dispatch(setToolboxVisible(visible));
  323. }
  324. };
  325. }
  326. /**
  327. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  328. *
  329. * @param {Object} state - The redux state.
  330. * @private
  331. * @returns {{
  332. * _connecting: boolean,
  333. * _participantCount: number,
  334. * _reducedUI: boolean,
  335. * _toolboxVisible: boolean
  336. * }}
  337. */
  338. function _mapStateToProps(state) {
  339. const { connecting, connection } = state['features/base/connection'];
  340. const { conference, joining, leaving } = state['features/base/conference'];
  341. const { reducedUI } = state['features/base/responsive-ui'];
  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: getParticipantCount(state),
  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);