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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. // @flow
  2. import React from 'react';
  3. import { NativeModules, SafeAreaView, StatusBar, View } from 'react-native';
  4. import { withSafeAreaInsets } from 'react-native-safe-area-context';
  5. import { appNavigate } from '../../../app/actions';
  6. import { PIP_ENABLED, FULLSCREEN_ENABLED, getFeatureFlag } from '../../../base/flags';
  7. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  8. import { connect } from '../../../base/redux';
  9. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  10. import { TestConnectionInfo } from '../../../base/testing';
  11. import { ConferenceNotification, isCalendarEnabled } from '../../../calendar-sync';
  12. import { DisplayNameLabel } from '../../../display-name';
  13. import {
  14. FILMSTRIP_SIZE,
  15. Filmstrip,
  16. isFilmstripVisible,
  17. TileView
  18. } from '../../../filmstrip';
  19. import { CalleeInfoContainer } from '../../../invite';
  20. import { LargeVideo } from '../../../large-video';
  21. import { KnockingParticipantList } from '../../../lobby/components/native';
  22. import { getIsLobbyVisible } from '../../../lobby/functions';
  23. import { BackButtonRegistry } from '../../../mobile/back-button';
  24. import { navigate }
  25. from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  26. import { screen } from '../../../mobile/navigation/routes';
  27. import { Captions } from '../../../subtitles';
  28. import { setToolboxVisible } from '../../../toolbox/actions';
  29. import { Toolbox } from '../../../toolbox/components/native';
  30. import { isToolboxVisible } from '../../../toolbox/functions';
  31. import {
  32. AbstractConference,
  33. abstractMapStateToProps
  34. } from '../AbstractConference';
  35. import type { AbstractProps } from '../AbstractConference';
  36. import AlwaysOnLabels from './AlwaysOnLabels';
  37. import ExpandedLabelPopup from './ExpandedLabelPopup';
  38. import LonelyMeetingExperience from './LonelyMeetingExperience';
  39. import TitleBar from './TitleBar';
  40. import { EXPANDED_LABEL_TIMEOUT } from './constants';
  41. import styles from './styles';
  42. /**
  43. * The type of the React {@code Component} props of {@link Conference}.
  44. */
  45. type Props = AbstractProps & {
  46. /**
  47. * Application's aspect ratio.
  48. */
  49. _aspectRatio: Symbol,
  50. /**
  51. * Wherther the calendar feature is enabled or not.
  52. */
  53. _calendarEnabled: boolean,
  54. /**
  55. * The indicator which determines that we are still connecting to the
  56. * conference which includes establishing the XMPP connection and then
  57. * joining the room. If truthy, then an activity/loading indicator will be
  58. * rendered.
  59. */
  60. _connecting: boolean,
  61. /**
  62. * Set to {@code true} when the filmstrip is currently visible.
  63. */
  64. _filmstripVisible: boolean,
  65. /**
  66. * The indicator which determines whether fullscreen (immersive) mode is enabled.
  67. */
  68. _fullscreenEnabled: boolean,
  69. /**
  70. * The indicator which determines if the participants pane is open.
  71. */
  72. _isParticipantsPaneOpen: boolean,
  73. /**
  74. * The ID of the participant currently on stage (if any).
  75. */
  76. _largeVideoParticipantId: string,
  77. /**
  78. * Whether Picture-in-Picture is enabled.
  79. */
  80. _pictureInPictureEnabled: boolean,
  81. /**
  82. * The indicator which determines whether the UI is reduced (to accommodate
  83. * smaller display areas).
  84. */
  85. _reducedUI: boolean,
  86. /**
  87. * The indicator which determines whether the Toolbox is visible.
  88. */
  89. _toolboxVisible: boolean,
  90. /**
  91. * Indicates whether the lobby screen should be visible.
  92. */
  93. _showLobby: boolean,
  94. /**
  95. * The redux {@code dispatch} function.
  96. */
  97. dispatch: Function,
  98. /**
  99. * Object containing the safe area insets.
  100. */
  101. insets: Object
  102. };
  103. type State = {
  104. /**
  105. * The label that is currently expanded.
  106. */
  107. visibleExpandedLabel: ?string
  108. }
  109. /**
  110. * The conference page of the mobile (i.e. React Native) application.
  111. */
  112. class Conference extends AbstractConference<Props, State> {
  113. /**
  114. * Timeout ref.
  115. */
  116. _expandedLabelTimeout: Object;
  117. /**
  118. * Initializes a new Conference instance.
  119. *
  120. * @param {Object} props - The read-only properties with which the new
  121. * instance is to be initialized.
  122. */
  123. constructor(props) {
  124. super(props);
  125. this.state = {
  126. visibleExpandedLabel: undefined
  127. };
  128. this._expandedLabelTimeout = React.createRef();
  129. // Bind event handlers so they are only bound once per instance.
  130. this._onClick = this._onClick.bind(this);
  131. this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
  132. this._setToolboxVisible = this._setToolboxVisible.bind(this);
  133. this._createOnPress = this._createOnPress.bind(this);
  134. }
  135. /**
  136. * Implements {@link Component#componentDidMount()}. Invoked immediately
  137. * after this component is mounted.
  138. *
  139. * @inheritdoc
  140. * @returns {void}
  141. */
  142. componentDidMount() {
  143. BackButtonRegistry.addListener(this._onHardwareBackPress);
  144. }
  145. /**
  146. * Implements {@code Component#componentDidUpdate}.
  147. *
  148. * @inheritdoc
  149. */
  150. componentDidUpdate(prevProps) {
  151. const { _showLobby } = this.props;
  152. if (!prevProps._showLobby && _showLobby) {
  153. navigate(screen.lobby);
  154. }
  155. if (prevProps._showLobby && !_showLobby) {
  156. navigate(screen.conference.main);
  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. clearTimeout(this._expandedLabelTimeout.current);
  171. }
  172. /**
  173. * Implements React's {@link Component#render()}.
  174. *
  175. * @inheritdoc
  176. * @returns {ReactElement}
  177. */
  178. render() {
  179. const { _fullscreenEnabled } = this.props;
  180. return (
  181. <Container style = { styles.conference }>
  182. <StatusBar
  183. barStyle = 'light-content'
  184. hidden = { _fullscreenEnabled }
  185. translucent = { _fullscreenEnabled } />
  186. { this._renderContent() }
  187. </Container>
  188. );
  189. }
  190. _onClick: () => void;
  191. /**
  192. * Changes the value of the toolboxVisible state, thus allowing us to switch
  193. * between Toolbox and Filmstrip and change their visibility.
  194. *
  195. * @private
  196. * @returns {void}
  197. */
  198. _onClick() {
  199. this._setToolboxVisible(!this.props._toolboxVisible);
  200. }
  201. _onHardwareBackPress: () => boolean;
  202. /**
  203. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  204. * (if supported) or leaves the associated {@code Conference} otherwise.
  205. *
  206. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  207. */
  208. _onHardwareBackPress() {
  209. let p;
  210. if (this.props._pictureInPictureEnabled) {
  211. const { PictureInPicture } = NativeModules;
  212. p = PictureInPicture.enterPictureInPicture();
  213. } else {
  214. p = Promise.reject(new Error('PiP not enabled'));
  215. }
  216. p.catch(() => {
  217. this.props.dispatch(appNavigate(undefined));
  218. });
  219. return true;
  220. }
  221. /**
  222. * Renders the conference notification badge if the feature is enabled.
  223. *
  224. * @private
  225. * @returns {React$Node}
  226. */
  227. _renderConferenceNotification() {
  228. const { _calendarEnabled, _reducedUI } = this.props;
  229. return (
  230. _calendarEnabled && !_reducedUI
  231. ? <ConferenceNotification />
  232. : undefined);
  233. }
  234. _createOnPress: (string) => void;
  235. /**
  236. * Creates a function to be invoked when the onPress of the touchables are
  237. * triggered.
  238. *
  239. * @param {string} label - The identifier of the label that's onLayout is
  240. * triggered.
  241. * @returns {Function}
  242. */
  243. _createOnPress(label) {
  244. return () => {
  245. const { visibleExpandedLabel } = this.state;
  246. const newVisibleExpandedLabel
  247. = visibleExpandedLabel === label ? undefined : label;
  248. clearTimeout(this._expandedLabelTimeout.current);
  249. this.setState({
  250. visibleExpandedLabel: newVisibleExpandedLabel
  251. });
  252. if (newVisibleExpandedLabel) {
  253. this._expandedLabelTimeout.current = setTimeout(() => {
  254. this.setState({
  255. visibleExpandedLabel: undefined
  256. });
  257. }, EXPANDED_LABEL_TIMEOUT);
  258. }
  259. };
  260. }
  261. /**
  262. * Renders the content for the Conference container.
  263. *
  264. * @private
  265. * @returns {React$Element}
  266. */
  267. _renderContent() {
  268. const {
  269. _connecting,
  270. _largeVideoParticipantId,
  271. _reducedUI,
  272. _shouldDisplayTileView,
  273. _toolboxVisible
  274. } = this.props;
  275. if (_reducedUI) {
  276. return this._renderContentForReducedUi();
  277. }
  278. return (
  279. <>
  280. {/*
  281. * The LargeVideo is the lowermost stacking layer.
  282. */
  283. _shouldDisplayTileView
  284. ? <TileView onClick = { this._onClick } />
  285. : <LargeVideo onClick = { this._onClick } />
  286. }
  287. {/*
  288. * If there is a ringing call, show the callee's info.
  289. */
  290. <CalleeInfoContainer />
  291. }
  292. {/*
  293. * The activity/loading indicator goes above everything, except
  294. * the toolbox/toolbars and the dialogs.
  295. */
  296. _connecting
  297. && <TintedView>
  298. <LoadingIndicator />
  299. </TintedView>
  300. }
  301. <View
  302. pointerEvents = 'box-none'
  303. style = { styles.toolboxAndFilmstripContainer }>
  304. <Captions onPress = { this._onClick } />
  305. { _shouldDisplayTileView || <Container style = { styles.displayNameContainer }>
  306. <DisplayNameLabel participantId = { _largeVideoParticipantId } />
  307. </Container> }
  308. <LonelyMeetingExperience />
  309. { _shouldDisplayTileView || <><Filmstrip /><Toolbox /></> }
  310. </View>
  311. <SafeAreaView
  312. pointerEvents = 'box-none'
  313. style = {
  314. _toolboxVisible
  315. ? styles.titleBarSafeViewColor
  316. : styles.titleBarSafeViewTransparent }>
  317. <TitleBar _createOnPress = { this._createOnPress } />
  318. </SafeAreaView>
  319. <SafeAreaView
  320. pointerEvents = 'box-none'
  321. style = {
  322. _toolboxVisible
  323. ? [ styles.titleBarSafeViewTransparent, { top: this.props.insets.top + 50 } ]
  324. : styles.titleBarSafeViewTransparent
  325. }>
  326. <View
  327. pointerEvents = 'box-none'
  328. style = { styles.expandedLabelWrapper }>
  329. <ExpandedLabelPopup visibleExpandedLabel = { this.state.visibleExpandedLabel } />
  330. </View>
  331. <View
  332. pointerEvents = 'box-none'
  333. style = { styles.alwaysOnTitleBar }>
  334. {/* eslint-disable-next-line react/jsx-no-bind */}
  335. <AlwaysOnLabels createOnPress = { this._createOnPress } />
  336. </View>
  337. {this._renderNotificationsContainer()}
  338. <KnockingParticipantList />
  339. </SafeAreaView>
  340. <TestConnectionInfo />
  341. { this._renderConferenceNotification() }
  342. {_shouldDisplayTileView && <Toolbox />}
  343. </>
  344. );
  345. }
  346. /**
  347. * Renders the content for the Conference container when in "reduced UI" mode.
  348. *
  349. * @private
  350. * @returns {React$Element}
  351. */
  352. _renderContentForReducedUi() {
  353. const { _connecting } = this.props;
  354. return (
  355. <>
  356. <LargeVideo onClick = { this._onClick } />
  357. {
  358. _connecting
  359. && <TintedView>
  360. <LoadingIndicator />
  361. </TintedView>
  362. }
  363. </>
  364. );
  365. }
  366. /**
  367. * Renders a container for notifications to be displayed by the
  368. * base/notifications feature.
  369. *
  370. * @private
  371. * @returns {React$Element}
  372. */
  373. _renderNotificationsContainer() {
  374. const notificationsStyle = {};
  375. // In the landscape mode (wide) there's problem with notifications being
  376. // shadowed by the filmstrip rendered on the right. This makes the "x"
  377. // button not clickable. In order to avoid that a margin of the
  378. // filmstrip's size is added to the right.
  379. //
  380. // Pawel: after many attempts I failed to make notifications adjust to
  381. // their contents width because of column and rows being used in the
  382. // flex layout. The only option that seemed to limit the notification's
  383. // size was explicit 'width' value which is not better than the margin
  384. // added here.
  385. const { _aspectRatio, _filmstripVisible } = this.props;
  386. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  387. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  388. }
  389. return super.renderNotificationsContainer(
  390. {
  391. style: notificationsStyle
  392. }
  393. );
  394. }
  395. _setToolboxVisible: (boolean) => void;
  396. /**
  397. * Dispatches an action changing the visibility of the {@link Toolbox}.
  398. *
  399. * @private
  400. * @param {boolean} visible - Pass {@code true} to show the
  401. * {@code Toolbox} or {@code false} to hide it.
  402. * @returns {void}
  403. */
  404. _setToolboxVisible(visible) {
  405. this.props.dispatch(setToolboxVisible(visible));
  406. }
  407. }
  408. /**
  409. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  410. *
  411. * @param {Object} state - The redux state.
  412. * @private
  413. * @returns {Props}
  414. */
  415. function _mapStateToProps(state) {
  416. const { connecting, connection } = state['features/base/connection'];
  417. const {
  418. conference,
  419. joining,
  420. membersOnly,
  421. leaving
  422. } = state['features/base/conference'];
  423. const { isOpen } = state['features/participants-pane'];
  424. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  425. // XXX There is a window of time between the successful establishment of the
  426. // XMPP connection and the subsequent commencement of joining the MUC during
  427. // which the app does not appear to be doing anything according to the redux
  428. // state. In order to not toggle the _connecting props during the window of
  429. // time in question, define _connecting as follows:
  430. // - the XMPP connection is connecting, or
  431. // - the XMPP connection is connected and the conference is joining, or
  432. // - the XMPP connection is connected and we have no conference yet, nor we
  433. // are leaving one.
  434. const connecting_
  435. = connecting || (connection && (!membersOnly && (joining || (!conference && !leaving))));
  436. return {
  437. ...abstractMapStateToProps(state),
  438. _aspectRatio: aspectRatio,
  439. _calendarEnabled: isCalendarEnabled(state),
  440. _connecting: Boolean(connecting_),
  441. _filmstripVisible: isFilmstripVisible(state),
  442. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  443. _isParticipantsPaneOpen: isOpen,
  444. _largeVideoParticipantId: state['features/large-video'].participantId,
  445. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  446. _reducedUI: reducedUI,
  447. _showLobby: getIsLobbyVisible(state),
  448. _toolboxVisible: isToolboxVisible(state)
  449. };
  450. }
  451. export default withSafeAreaInsets(connect(_mapStateToProps)(Conference));