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.tsx 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. import { useFocusEffect } from '@react-navigation/native';
  2. import React, { useCallback } from 'react';
  3. import {
  4. BackHandler,
  5. NativeModules,
  6. Platform,
  7. SafeAreaView,
  8. StatusBar,
  9. View,
  10. ViewStyle
  11. } from 'react-native';
  12. import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
  13. import { connect, useDispatch } from 'react-redux';
  14. import { appNavigate } from '../../../app/actions.native';
  15. import { IReduxState, IStore } from '../../../app/types';
  16. import { CONFERENCE_BLURRED, CONFERENCE_FOCUSED } from '../../../base/conference/actionTypes';
  17. import { FULLSCREEN_ENABLED } from '../../../base/flags/constants';
  18. import { getFeatureFlag } from '../../../base/flags/functions';
  19. import Container from '../../../base/react/components/native/Container';
  20. import LoadingIndicator from '../../../base/react/components/native/LoadingIndicator';
  21. import TintedView from '../../../base/react/components/native/TintedView';
  22. import {
  23. ASPECT_RATIO_NARROW,
  24. ASPECT_RATIO_WIDE
  25. } from '../../../base/responsive-ui/constants';
  26. import { StyleType } from '../../../base/styles/functions.any';
  27. import TestConnectionInfo from '../../../base/testing/components/TestConnectionInfo';
  28. import { isCalendarEnabled } from '../../../calendar-sync/functions.native';
  29. import DisplayNameLabel from '../../../display-name/components/native/DisplayNameLabel';
  30. import BrandingImageBackground from '../../../dynamic-branding/components/native/BrandingImageBackground';
  31. import Filmstrip from '../../../filmstrip/components/native/Filmstrip';
  32. import TileView from '../../../filmstrip/components/native/TileView';
  33. import { FILMSTRIP_SIZE } from '../../../filmstrip/constants';
  34. import { isFilmstripVisible } from '../../../filmstrip/functions.native';
  35. import CalleeInfoContainer from '../../../invite/components/callee-info/CalleeInfoContainer';
  36. import LargeVideo from '../../../large-video/components/LargeVideo.native';
  37. import { getIsLobbyVisible } from '../../../lobby/functions';
  38. import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  39. import { screen } from '../../../mobile/navigation/routes';
  40. import { isPipEnabled, setPictureInPictureEnabled } from '../../../mobile/picture-in-picture/functions';
  41. import Captions from '../../../subtitles/components/native/Captions';
  42. import { setToolboxVisible } from '../../../toolbox/actions.native';
  43. import Toolbox from '../../../toolbox/components/native/Toolbox';
  44. import { isToolboxVisible } from '../../../toolbox/functions.native';
  45. import {
  46. AbstractConference,
  47. abstractMapStateToProps
  48. } from '../AbstractConference';
  49. import type { AbstractProps } from '../AbstractConference';
  50. import { isConnecting } from '../functions.native';
  51. import AlwaysOnLabels from './AlwaysOnLabels';
  52. import ExpandedLabelPopup from './ExpandedLabelPopup';
  53. import LonelyMeetingExperience from './LonelyMeetingExperience';
  54. import TitleBar from './TitleBar';
  55. import { EXPANDED_LABEL_TIMEOUT } from './constants';
  56. import styles from './styles';
  57. /**
  58. * The type of the React {@code Component} props of {@link Conference}.
  59. */
  60. interface IProps extends AbstractProps {
  61. /**
  62. * Application's aspect ratio.
  63. */
  64. _aspectRatio: Symbol;
  65. /**
  66. * Whether the audio only is enabled or not.
  67. */
  68. _audioOnlyEnabled: boolean;
  69. /**
  70. * Branding styles for conference.
  71. */
  72. _brandingStyles: StyleType;
  73. /**
  74. * Whether the calendar feature is enabled or not.
  75. */
  76. _calendarEnabled: boolean;
  77. /**
  78. * The indicator which determines that we are still connecting to the
  79. * conference which includes establishing the XMPP connection and then
  80. * joining the room. If truthy, then an activity/loading indicator will be
  81. * rendered.
  82. */
  83. _connecting: boolean;
  84. /**
  85. * Set to {@code true} when the filmstrip is currently visible.
  86. */
  87. _filmstripVisible: boolean;
  88. /**
  89. * The indicator which determines whether fullscreen (immersive) mode is enabled.
  90. */
  91. _fullscreenEnabled: boolean;
  92. /**
  93. * The indicator which determines if the participants pane is open.
  94. */
  95. _isParticipantsPaneOpen: boolean;
  96. /**
  97. * The ID of the participant currently on stage (if any).
  98. */
  99. _largeVideoParticipantId: string;
  100. /**
  101. * Local participant's display name.
  102. */
  103. _localParticipantDisplayName: string;
  104. /**
  105. * Whether Picture-in-Picture is enabled.
  106. */
  107. _pictureInPictureEnabled: boolean;
  108. /**
  109. * The indicator which determines whether the UI is reduced (to accommodate
  110. * smaller display areas).
  111. */
  112. _reducedUI: boolean;
  113. /**
  114. * Indicates whether the lobby screen should be visible.
  115. */
  116. _showLobby: boolean;
  117. /**
  118. * Indicates whether the car mode is enabled.
  119. */
  120. _startCarMode: boolean;
  121. /**
  122. * The indicator which determines whether the Toolbox is visible.
  123. */
  124. _toolboxVisible: boolean;
  125. /**
  126. * The redux {@code dispatch} function.
  127. */
  128. dispatch: IStore['dispatch'];
  129. /**
  130. * Object containing the safe area insets.
  131. */
  132. insets: EdgeInsets;
  133. /**
  134. * Default prop for navigating between screen components(React Navigation).
  135. */
  136. navigation: any;
  137. }
  138. type State = {
  139. /**
  140. * The label that is currently expanded.
  141. */
  142. visibleExpandedLabel?: string;
  143. };
  144. /**
  145. * The conference page of the mobile (i.e. React Native) application.
  146. */
  147. class Conference extends AbstractConference<IProps, State> {
  148. /**
  149. * Timeout ref.
  150. */
  151. _expandedLabelTimeout: any;
  152. /**
  153. * Initializes a new Conference instance.
  154. *
  155. * @param {Object} props - The read-only properties with which the new
  156. * instance is to be initialized.
  157. */
  158. constructor(props: IProps) {
  159. super(props);
  160. this.state = {
  161. visibleExpandedLabel: undefined
  162. };
  163. this._expandedLabelTimeout = React.createRef<number>();
  164. // Bind event handlers so they are only bound once per instance.
  165. this._onClick = this._onClick.bind(this);
  166. this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
  167. this._setToolboxVisible = this._setToolboxVisible.bind(this);
  168. this._createOnPress = this._createOnPress.bind(this);
  169. }
  170. /**
  171. * Implements {@link Component#componentDidMount()}. Invoked immediately
  172. * after this component is mounted.
  173. *
  174. * @inheritdoc
  175. * @returns {void}
  176. */
  177. componentDidMount() {
  178. const {
  179. _audioOnlyEnabled,
  180. _startCarMode,
  181. navigation
  182. } = this.props;
  183. BackHandler.addEventListener('hardwareBackPress', this._onHardwareBackPress);
  184. if (_audioOnlyEnabled && _startCarMode) {
  185. navigation.navigate(screen.conference.carmode);
  186. }
  187. }
  188. /**
  189. * Implements {@code Component#componentDidUpdate}.
  190. *
  191. * @inheritdoc
  192. */
  193. componentDidUpdate(prevProps: IProps) {
  194. const {
  195. _audioOnlyEnabled,
  196. _showLobby,
  197. _startCarMode
  198. } = this.props;
  199. if (!prevProps._showLobby && _showLobby) {
  200. navigate(screen.lobby.root);
  201. }
  202. if (prevProps._showLobby && !_showLobby) {
  203. if (_audioOnlyEnabled && _startCarMode) {
  204. return;
  205. }
  206. navigate(screen.conference.main);
  207. }
  208. }
  209. /**
  210. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  211. * before this component is unmounted and destroyed. Disconnects the
  212. * conference described by the redux store/state.
  213. *
  214. * @inheritdoc
  215. * @returns {void}
  216. */
  217. componentWillUnmount() {
  218. // Tear handling any hardware button presses for back navigation down.
  219. BackHandler.removeEventListener('hardwareBackPress', this._onHardwareBackPress);
  220. clearTimeout(this._expandedLabelTimeout.current ?? 0);
  221. }
  222. /**
  223. * Implements React's {@link Component#render()}.
  224. *
  225. * @inheritdoc
  226. * @returns {ReactElement}
  227. */
  228. render() {
  229. const {
  230. _brandingStyles,
  231. _fullscreenEnabled
  232. } = this.props;
  233. return (
  234. <Container
  235. style = { [
  236. styles.conference,
  237. _brandingStyles
  238. ] }>
  239. <BrandingImageBackground />
  240. {
  241. Platform.OS === 'android'
  242. && <StatusBar
  243. barStyle = 'light-content'
  244. hidden = { _fullscreenEnabled }
  245. translucent = { _fullscreenEnabled } />
  246. }
  247. { this._renderContent() }
  248. </Container>
  249. );
  250. }
  251. /**
  252. * Changes the value of the toolboxVisible state, thus allowing us to switch
  253. * between Toolbox and Filmstrip and change their visibility.
  254. *
  255. * @private
  256. * @returns {void}
  257. */
  258. _onClick() {
  259. this._setToolboxVisible(!this.props._toolboxVisible);
  260. }
  261. /**
  262. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  263. * (if supported) or leaves the associated {@code Conference} otherwise.
  264. *
  265. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  266. */
  267. _onHardwareBackPress() {
  268. let p;
  269. if (this.props._pictureInPictureEnabled) {
  270. const { PictureInPicture } = NativeModules;
  271. p = PictureInPicture.enterPictureInPicture();
  272. } else {
  273. p = Promise.reject(new Error('PiP not enabled'));
  274. }
  275. p.catch(() => {
  276. this.props.dispatch(appNavigate(undefined));
  277. });
  278. return true;
  279. }
  280. /**
  281. * Creates a function to be invoked when the onPress of the touchables are
  282. * triggered.
  283. *
  284. * @param {string} label - The identifier of the label that's onLayout is
  285. * triggered.
  286. * @returns {Function}
  287. */
  288. _createOnPress(label: string) {
  289. return () => {
  290. const { visibleExpandedLabel } = this.state;
  291. const newVisibleExpandedLabel
  292. = visibleExpandedLabel === label ? undefined : label;
  293. clearTimeout(this._expandedLabelTimeout.current);
  294. this.setState({
  295. visibleExpandedLabel: newVisibleExpandedLabel
  296. });
  297. if (newVisibleExpandedLabel) {
  298. this._expandedLabelTimeout.current = setTimeout(() => {
  299. this.setState({
  300. visibleExpandedLabel: undefined
  301. });
  302. }, EXPANDED_LABEL_TIMEOUT);
  303. }
  304. };
  305. }
  306. /**
  307. * Renders the content for the Conference container.
  308. *
  309. * @private
  310. * @returns {React$Element}
  311. */
  312. _renderContent() {
  313. const {
  314. _aspectRatio,
  315. _connecting,
  316. _filmstripVisible,
  317. _largeVideoParticipantId,
  318. _reducedUI,
  319. _shouldDisplayTileView,
  320. _toolboxVisible
  321. } = this.props;
  322. let alwaysOnTitleBarStyles;
  323. if (_reducedUI) {
  324. return this._renderContentForReducedUi();
  325. }
  326. if (_aspectRatio === ASPECT_RATIO_WIDE) {
  327. alwaysOnTitleBarStyles
  328. = !_shouldDisplayTileView && _filmstripVisible
  329. ? styles.alwaysOnTitleBarWide
  330. : styles.alwaysOnTitleBar;
  331. } else {
  332. alwaysOnTitleBarStyles = styles.alwaysOnTitleBar;
  333. }
  334. return (
  335. <>
  336. {/*
  337. * The LargeVideo is the lowermost stacking layer.
  338. */
  339. _shouldDisplayTileView
  340. ? <TileView onClick = { this._onClick } />
  341. : <LargeVideo onClick = { this._onClick } />
  342. }
  343. {/*
  344. * If there is a ringing call, show the callee's info.
  345. */
  346. <CalleeInfoContainer />
  347. }
  348. {/*
  349. * The activity/loading indicator goes above everything, except
  350. * the toolbox/toolbars and the dialogs.
  351. */
  352. _connecting
  353. && <TintedView>
  354. <LoadingIndicator />
  355. </TintedView>
  356. }
  357. <View
  358. pointerEvents = 'box-none'
  359. style = { styles.toolboxAndFilmstripContainer as ViewStyle }>
  360. <Captions onPress = { this._onClick } />
  361. {
  362. _shouldDisplayTileView
  363. || <Container style = { styles.displayNameContainer }>
  364. <DisplayNameLabel
  365. participantId = { _largeVideoParticipantId } />
  366. </Container>
  367. }
  368. { !_shouldDisplayTileView && <LonelyMeetingExperience /> }
  369. {
  370. _shouldDisplayTileView
  371. || <>
  372. <Filmstrip />
  373. { this._renderNotificationsContainer() }
  374. <Toolbox />
  375. </>
  376. }
  377. </View>
  378. <SafeAreaView
  379. pointerEvents = 'box-none'
  380. style = {
  381. (_toolboxVisible
  382. ? styles.titleBarSafeViewColor
  383. : styles.titleBarSafeViewTransparent) as ViewStyle }>
  384. <TitleBar _createOnPress = { this._createOnPress } />
  385. </SafeAreaView>
  386. <SafeAreaView
  387. pointerEvents = 'box-none'
  388. style = {
  389. (_toolboxVisible
  390. ? [ styles.titleBarSafeViewTransparent, { top: this.props.insets.top + 50 } ]
  391. : styles.titleBarSafeViewTransparent) as ViewStyle
  392. }>
  393. <View
  394. pointerEvents = 'box-none'
  395. style = { styles.expandedLabelWrapper }>
  396. <ExpandedLabelPopup visibleExpandedLabel = { this.state.visibleExpandedLabel } />
  397. </View>
  398. <View
  399. pointerEvents = 'box-none'
  400. style = { alwaysOnTitleBarStyles as ViewStyle }>
  401. {/* eslint-disable-next-line react/jsx-no-bind */}
  402. <AlwaysOnLabels createOnPress = { this._createOnPress } />
  403. </View>
  404. </SafeAreaView>
  405. <TestConnectionInfo />
  406. {
  407. _shouldDisplayTileView
  408. && <>
  409. { this._renderNotificationsContainer() }
  410. <Toolbox />
  411. </>
  412. }
  413. </>
  414. );
  415. }
  416. /**
  417. * Renders the content for the Conference container when in "reduced UI" mode.
  418. *
  419. * @private
  420. * @returns {React$Element}
  421. */
  422. _renderContentForReducedUi() {
  423. const { _connecting } = this.props;
  424. return (
  425. <>
  426. <LargeVideo onClick = { this._onClick } />
  427. {
  428. _connecting
  429. && <TintedView>
  430. <LoadingIndicator />
  431. </TintedView>
  432. }
  433. </>
  434. );
  435. }
  436. /**
  437. * Renders a container for notifications to be displayed by the
  438. * base/notifications feature.
  439. *
  440. * @private
  441. * @returns {React$Element}
  442. */
  443. _renderNotificationsContainer() {
  444. const notificationsStyle: ViewStyle = {};
  445. // In the landscape mode (wide) there's problem with notifications being
  446. // shadowed by the filmstrip rendered on the right. This makes the "x"
  447. // button not clickable. In order to avoid that a margin of the
  448. // filmstrip's size is added to the right.
  449. //
  450. // Pawel: after many attempts I failed to make notifications adjust to
  451. // their contents width because of column and rows being used in the
  452. // flex layout. The only option that seemed to limit the notification's
  453. // size was explicit 'width' value which is not better than the margin
  454. // added here.
  455. const { _aspectRatio, _filmstripVisible } = this.props;
  456. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  457. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  458. }
  459. return super.renderNotificationsContainer(
  460. {
  461. shouldDisplayTileView: this.props._shouldDisplayTileView,
  462. style: notificationsStyle,
  463. toolboxVisible: this.props._toolboxVisible
  464. }
  465. );
  466. }
  467. /**
  468. * Dispatches an action changing the visibility of the {@link Toolbox}.
  469. *
  470. * @private
  471. * @param {boolean} visible - Pass {@code true} to show the
  472. * {@code Toolbox} or {@code false} to hide it.
  473. * @returns {void}
  474. */
  475. _setToolboxVisible(visible: boolean) {
  476. this.props.dispatch(setToolboxVisible(visible));
  477. }
  478. }
  479. /**
  480. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  481. *
  482. * @param {Object} state - The redux state.
  483. * @param {any} _ownProps - Component's own props.
  484. * @private
  485. * @returns {IProps}
  486. */
  487. function _mapStateToProps(state: IReduxState, _ownProps: any) {
  488. const { appState } = state['features/mobile/background'];
  489. const { isOpen } = state['features/participants-pane'];
  490. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  491. const { backgroundColor } = state['features/dynamic-branding'];
  492. const { startCarMode } = state['features/base/settings'];
  493. const { enabled: audioOnlyEnabled } = state['features/base/audio-only'];
  494. const brandingStyles = backgroundColor ? {
  495. backgroundColor
  496. } : undefined;
  497. return {
  498. ...abstractMapStateToProps(state),
  499. _aspectRatio: aspectRatio,
  500. _audioOnlyEnabled: Boolean(audioOnlyEnabled),
  501. _brandingStyles: brandingStyles,
  502. _calendarEnabled: isCalendarEnabled(state),
  503. _connecting: isConnecting(state),
  504. _filmstripVisible: isFilmstripVisible(state),
  505. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  506. _isParticipantsPaneOpen: isOpen,
  507. _largeVideoParticipantId: state['features/large-video'].participantId,
  508. _pictureInPictureEnabled: isPipEnabled(state),
  509. // [iOS] - Transitioning between foreground & background, appState goes from active -> inactive -> background
  510. // and during periods of inactivity such as entering the multitasking view,
  511. // opening the Notification Center or in the event of an incoming call.
  512. _reducedUI: reducedUI || appState !== 'active',
  513. _showLobby: getIsLobbyVisible(state),
  514. _startCarMode: startCarMode,
  515. _toolboxVisible: isToolboxVisible(state)
  516. };
  517. }
  518. export default withSafeAreaInsets(connect(_mapStateToProps)(props => {
  519. const dispatch = useDispatch();
  520. useFocusEffect(useCallback(() => {
  521. dispatch({ type: CONFERENCE_FOCUSED });
  522. setPictureInPictureEnabled(true);
  523. return () => {
  524. dispatch({ type: CONFERENCE_BLURRED });
  525. setPictureInPictureEnabled(false);
  526. };
  527. }, []));
  528. return ( // @ts-ignore
  529. <Conference { ...props } />
  530. );
  531. }));