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 15KB

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