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

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