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

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