Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Conference.js 15KB

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