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

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