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

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