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

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