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

Conference.js 15KB

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