You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Conference.js 14KB

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