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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. const {
  147. _connecting,
  148. _filmstripVisible,
  149. _largeVideoParticipantId,
  150. _reducedUI,
  151. _shouldDisplayTileView,
  152. _toolboxVisible
  153. } = this.props;
  154. const showGradient = _toolboxVisible;
  155. const applyGradientStretching = _filmstripVisible && isNarrowAspectRatio(this) && !_shouldDisplayTileView;
  156. return (
  157. <Container style = { styles.conference }>
  158. <StatusBar
  159. barStyle = 'light-content'
  160. hidden = { true }
  161. translucent = { true } />
  162. <AddPeopleDialog />
  163. <Chat />
  164. <SharedDocument />
  165. {/*
  166. * The LargeVideo is the lowermost stacking layer.
  167. */
  168. _shouldDisplayTileView
  169. ? <TileView onClick = { this._onClick } />
  170. : <LargeVideo onClick = { this._onClick } />
  171. }
  172. {/*
  173. * If there is a ringing call, show the callee's info.
  174. */
  175. _reducedUI || <CalleeInfoContainer />
  176. }
  177. {/*
  178. * The activity/loading indicator goes above everything, except
  179. * the toolbox/toolbars and the dialogs.
  180. */
  181. _connecting
  182. && <TintedView>
  183. <LoadingIndicator />
  184. </TintedView>
  185. }
  186. <View
  187. pointerEvents = 'box-none'
  188. style = { styles.toolboxAndFilmstripContainer }>
  189. { showGradient && <LinearGradient
  190. colors = { NAVBAR_GRADIENT_COLORS }
  191. end = {{
  192. x: 0.0,
  193. y: 0.0
  194. }}
  195. pointerEvents = 'none'
  196. start = {{
  197. x: 0.0,
  198. y: 1.0
  199. }}
  200. style = { [
  201. styles.bottomGradient,
  202. applyGradientStretching ? styles.gradientStretchBottom : undefined
  203. ] } />}
  204. <Labels />
  205. <Captions onPress = { this._onClick } />
  206. { _shouldDisplayTileView || <DisplayNameLabel participantId = { _largeVideoParticipantId } /> }
  207. {/*
  208. * The Toolbox is in a stacking layer below the Filmstrip.
  209. */}
  210. <Toolbox />
  211. {/*
  212. * The Filmstrip is in a stacking layer above the
  213. * LargeVideo. The LargeVideo and the Filmstrip form what
  214. * the Web/React app calls "videospace". Presumably, the
  215. * name and grouping stem from the fact that these two
  216. * React Components depict the videos of the conference's
  217. * participants.
  218. */
  219. _shouldDisplayTileView ? undefined : <Filmstrip />
  220. }
  221. </View>
  222. <SafeAreaView
  223. pointerEvents = 'box-none'
  224. style = { styles.navBarSafeView }>
  225. <NavigationBar />
  226. { this.renderNotificationsContainer() }
  227. </SafeAreaView>
  228. <TestConnectionInfo />
  229. {
  230. this._renderConferenceNotification()
  231. }
  232. </Container>
  233. );
  234. }
  235. _onClick: () => void;
  236. /**
  237. * Changes the value of the toolboxVisible state, thus allowing us to switch
  238. * between Toolbox and Filmstrip and change their visibility.
  239. *
  240. * @private
  241. * @returns {void}
  242. */
  243. _onClick() {
  244. this._setToolboxVisible(!this.props._toolboxVisible);
  245. }
  246. _onHardwareBackPress: () => boolean;
  247. /**
  248. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  249. * (if supported) or leaves the associated {@code Conference} otherwise.
  250. *
  251. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  252. */
  253. _onHardwareBackPress() {
  254. let p;
  255. if (this.props._pictureInPictureEnabled) {
  256. const { PictureInPicture } = NativeModules;
  257. p = PictureInPicture.enterPictureInPicture();
  258. } else {
  259. p = Promise.reject(new Error('PiP not enabled'));
  260. }
  261. p.catch(() => {
  262. this.props.dispatch(appNavigate(undefined));
  263. });
  264. return true;
  265. }
  266. /**
  267. * Renders the conference notification badge if the feature is enabled.
  268. *
  269. * @private
  270. * @returns {React$Node}
  271. */
  272. _renderConferenceNotification() {
  273. const { _calendarEnabled, _reducedUI } = this.props;
  274. return (
  275. _calendarEnabled && !_reducedUI
  276. ? <ConferenceNotification />
  277. : undefined);
  278. }
  279. /**
  280. * Renders a container for notifications to be displayed by the
  281. * base/notifications feature.
  282. *
  283. * @private
  284. * @returns {React$Element}
  285. */
  286. renderNotificationsContainer() {
  287. const notificationsStyle = {};
  288. // In the landscape mode (wide) there's problem with notifications being
  289. // shadowed by the filmstrip rendered on the right. This makes the "x"
  290. // button not clickable. In order to avoid that a margin of the
  291. // filmstrip's size is added to the right.
  292. //
  293. // Pawel: after many attempts I failed to make notifications adjust to
  294. // their contents width because of column and rows being used in the
  295. // flex layout. The only option that seemed to limit the notification's
  296. // size was explicit 'width' value which is not better than the margin
  297. // added here.
  298. if (this.props._filmstripVisible && !isNarrowAspectRatio(this)) {
  299. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  300. }
  301. return super.renderNotificationsContainer(
  302. {
  303. style: notificationsStyle
  304. }
  305. );
  306. }
  307. _setToolboxVisible: (boolean) => void;
  308. /**
  309. * Dispatches an action changing the visibility of the {@link Toolbox}.
  310. *
  311. * @private
  312. * @param {boolean} visible - Pass {@code true} to show the
  313. * {@code Toolbox} or {@code false} to hide it.
  314. * @returns {void}
  315. */
  316. _setToolboxVisible(visible) {
  317. this.props.dispatch(setToolboxVisible(visible));
  318. }
  319. }
  320. /**
  321. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  322. *
  323. * @param {Object} state - The redux state.
  324. * @private
  325. * @returns {Props}
  326. */
  327. function _mapStateToProps(state) {
  328. const { connecting, connection } = state['features/base/connection'];
  329. const {
  330. conference,
  331. joining,
  332. leaving
  333. } = state['features/base/conference'];
  334. const { reducedUI } = state['features/base/responsive-ui'];
  335. // XXX There is a window of time between the successful establishment of the
  336. // XMPP connection and the subsequent commencement of joining the MUC during
  337. // which the app does not appear to be doing anything according to the redux
  338. // state. In order to not toggle the _connecting props during the window of
  339. // time in question, define _connecting as follows:
  340. // - the XMPP connection is connecting, or
  341. // - the XMPP connection is connected and the conference is joining, or
  342. // - the XMPP connection is connected and we have no conference yet, nor we
  343. // are leaving one.
  344. const connecting_
  345. = connecting || (connection && (joining || (!conference && !leaving)));
  346. return {
  347. ...abstractMapStateToProps(state),
  348. /**
  349. * Wherther the calendar feature is enabled or not.
  350. *
  351. * @private
  352. * @type {boolean}
  353. */
  354. _calendarEnabled: isCalendarEnabled(state),
  355. /**
  356. * The indicator which determines that we are still connecting to the
  357. * conference which includes establishing the XMPP connection and then
  358. * joining the room. If truthy, then an activity/loading indicator will
  359. * be rendered.
  360. *
  361. * @private
  362. * @type {boolean}
  363. */
  364. _connecting: Boolean(connecting_),
  365. /**
  366. * Is {@code true} when the filmstrip is currently visible.
  367. */
  368. _filmstripVisible: isFilmstripVisible(state),
  369. /**
  370. * The ID of the participant currently on stage.
  371. */
  372. _largeVideoParticipantId: state['features/large-video'].participantId,
  373. /**
  374. * Whether Picture-in-Picture is enabled.
  375. *
  376. * @private
  377. * @type {boolean}
  378. */
  379. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  380. /**
  381. * The indicator which determines whether the UI is reduced (to
  382. * accommodate smaller display areas).
  383. *
  384. * @private
  385. * @type {boolean}
  386. */
  387. _reducedUI: reducedUI,
  388. /**
  389. * The indicator which determines whether the Toolbox is visible.
  390. *
  391. * @private
  392. * @type {boolean}
  393. */
  394. _toolboxVisible: isToolboxVisible(state)
  395. };
  396. }
  397. export default connect(_mapStateToProps)(makeAspectRatioAware(Conference));