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

Conference.js 14KB

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