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

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