您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.js 15KB

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