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

Conference.js 15KB

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