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.js 14KB

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