Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Conference.js 14KB

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