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

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