Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Conference.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. // @flow
  2. import { useIsFocused } from '@react-navigation/native';
  3. import React, { useEffect } from 'react';
  4. import { BackHandler, NativeModules, SafeAreaView, StatusBar, 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. _fullscreenEnabled
  231. } = this.props;
  232. return (
  233. <Container
  234. style = { [
  235. styles.conference,
  236. _brandingStyles
  237. ] }>
  238. <BrandingImageBackground />
  239. <StatusBar
  240. barStyle = 'light-content'
  241. hidden = { _fullscreenEnabled }
  242. translucent = { _fullscreenEnabled } />
  243. { this._renderContent() }
  244. </Container>
  245. );
  246. }
  247. _onClick: () => void;
  248. /**
  249. * Changes the value of the toolboxVisible state, thus allowing us to switch
  250. * between Toolbox and Filmstrip and change their visibility.
  251. *
  252. * @private
  253. * @returns {void}
  254. */
  255. _onClick() {
  256. this._setToolboxVisible(!this.props._toolboxVisible);
  257. }
  258. _onHardwareBackPress: () => boolean;
  259. /**
  260. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  261. * (if supported) or leaves the associated {@code Conference} otherwise.
  262. *
  263. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  264. */
  265. _onHardwareBackPress() {
  266. let p;
  267. if (this.props._pictureInPictureEnabled) {
  268. const { PictureInPicture } = NativeModules;
  269. p = PictureInPicture.enterPictureInPicture();
  270. } else {
  271. p = Promise.reject(new Error('PiP not enabled'));
  272. }
  273. p.catch(() => {
  274. this.props.dispatch(appNavigate(undefined));
  275. });
  276. return true;
  277. }
  278. /**
  279. * Renders the conference notification badge if the feature is enabled.
  280. *
  281. * @private
  282. * @returns {React$Node}
  283. */
  284. _renderConferenceNotification() {
  285. const { _calendarEnabled, _reducedUI } = this.props;
  286. return (
  287. _calendarEnabled && !_reducedUI
  288. ? <ConferenceNotification />
  289. : undefined);
  290. }
  291. _createOnPress: (string) => void;
  292. /**
  293. * Creates a function to be invoked when the onPress of the touchables are
  294. * triggered.
  295. *
  296. * @param {string} label - The identifier of the label that's onLayout is
  297. * triggered.
  298. * @returns {Function}
  299. */
  300. _createOnPress(label) {
  301. return () => {
  302. const { visibleExpandedLabel } = this.state;
  303. const newVisibleExpandedLabel
  304. = visibleExpandedLabel === label ? undefined : label;
  305. clearTimeout(this._expandedLabelTimeout.current);
  306. this.setState({
  307. visibleExpandedLabel: newVisibleExpandedLabel
  308. });
  309. if (newVisibleExpandedLabel) {
  310. this._expandedLabelTimeout.current = setTimeout(() => {
  311. this.setState({
  312. visibleExpandedLabel: undefined
  313. });
  314. }, EXPANDED_LABEL_TIMEOUT);
  315. }
  316. };
  317. }
  318. /**
  319. * Renders the content for the Conference container.
  320. *
  321. * @private
  322. * @returns {React$Element}
  323. */
  324. _renderContent() {
  325. const {
  326. _connecting,
  327. _isOneToOneConference,
  328. _largeVideoParticipantId,
  329. _reducedUI,
  330. _shouldDisplayTileView,
  331. _toolboxVisible
  332. } = this.props;
  333. if (_reducedUI) {
  334. return this._renderContentForReducedUi();
  335. }
  336. return (
  337. <>
  338. {/*
  339. * The LargeVideo is the lowermost stacking layer.
  340. */
  341. _shouldDisplayTileView
  342. ? <TileView onClick = { this._onClick } />
  343. : <LargeVideo onClick = { this._onClick } />
  344. }
  345. {/*
  346. * If there is a ringing call, show the callee's info.
  347. */
  348. <CalleeInfoContainer />
  349. }
  350. {/*
  351. * The activity/loading indicator goes above everything, except
  352. * the toolbox/toolbars and the dialogs.
  353. */
  354. _connecting
  355. && <TintedView>
  356. <LoadingIndicator />
  357. </TintedView>
  358. }
  359. <View
  360. pointerEvents = 'box-none'
  361. style = { styles.toolboxAndFilmstripContainer }>
  362. <Captions onPress = { this._onClick } />
  363. {
  364. _shouldDisplayTileView || (
  365. !_isOneToOneConference
  366. && <Container style = { styles.displayNameContainer }>
  367. <DisplayNameLabel
  368. participantId = { _largeVideoParticipantId } />
  369. </Container>
  370. )
  371. }
  372. <LonelyMeetingExperience />
  373. { _shouldDisplayTileView || <><Filmstrip /><Toolbox /></> }
  374. </View>
  375. <SafeAreaView
  376. pointerEvents = 'box-none'
  377. style = {
  378. _toolboxVisible
  379. ? styles.titleBarSafeViewColor
  380. : styles.titleBarSafeViewTransparent }>
  381. <TitleBar _createOnPress = { this._createOnPress } />
  382. </SafeAreaView>
  383. <SafeAreaView
  384. pointerEvents = 'box-none'
  385. style = {
  386. _toolboxVisible
  387. ? [ styles.titleBarSafeViewTransparent, { top: this.props.insets.top + 50 } ]
  388. : styles.titleBarSafeViewTransparent
  389. }>
  390. <View
  391. pointerEvents = 'box-none'
  392. style = { styles.expandedLabelWrapper }>
  393. <ExpandedLabelPopup visibleExpandedLabel = { this.state.visibleExpandedLabel } />
  394. </View>
  395. <View
  396. pointerEvents = 'box-none'
  397. style = { styles.alwaysOnTitleBar }>
  398. {/* eslint-disable-next-line react/jsx-no-bind */}
  399. <AlwaysOnLabels createOnPress = { this._createOnPress } />
  400. </View>
  401. {this._renderNotificationsContainer()}
  402. <KnockingParticipantList />
  403. </SafeAreaView>
  404. <TestConnectionInfo />
  405. { this._renderConferenceNotification() }
  406. {_shouldDisplayTileView && <Toolbox />}
  407. </>
  408. );
  409. }
  410. /**
  411. * Renders the content for the Conference container when in "reduced UI" mode.
  412. *
  413. * @private
  414. * @returns {React$Element}
  415. */
  416. _renderContentForReducedUi() {
  417. const { _connecting } = this.props;
  418. return (
  419. <>
  420. <LargeVideo onClick = { this._onClick } />
  421. {
  422. _connecting
  423. && <TintedView>
  424. <LoadingIndicator />
  425. </TintedView>
  426. }
  427. </>
  428. );
  429. }
  430. /**
  431. * Renders a container for notifications to be displayed by the
  432. * base/notifications feature.
  433. *
  434. * @private
  435. * @returns {React$Element}
  436. */
  437. _renderNotificationsContainer() {
  438. const notificationsStyle = {};
  439. // In the landscape mode (wide) there's problem with notifications being
  440. // shadowed by the filmstrip rendered on the right. This makes the "x"
  441. // button not clickable. In order to avoid that a margin of the
  442. // filmstrip's size is added to the right.
  443. //
  444. // Pawel: after many attempts I failed to make notifications adjust to
  445. // their contents width because of column and rows being used in the
  446. // flex layout. The only option that seemed to limit the notification's
  447. // size was explicit 'width' value which is not better than the margin
  448. // added here.
  449. const { _aspectRatio, _filmstripVisible } = this.props;
  450. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  451. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  452. }
  453. return super.renderNotificationsContainer(
  454. {
  455. style: notificationsStyle
  456. }
  457. );
  458. }
  459. _setToolboxVisible: (boolean) => void;
  460. /**
  461. * Dispatches an action changing the visibility of the {@link Toolbox}.
  462. *
  463. * @private
  464. * @param {boolean} visible - Pass {@code true} to show the
  465. * {@code Toolbox} or {@code false} to hide it.
  466. * @returns {void}
  467. */
  468. _setToolboxVisible(visible) {
  469. this.props.dispatch(setToolboxVisible(visible));
  470. }
  471. }
  472. /**
  473. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  474. *
  475. * @param {Object} state - The redux state.
  476. * @private
  477. * @returns {Props}
  478. */
  479. function _mapStateToProps(state) {
  480. const { isOpen } = state['features/participants-pane'];
  481. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  482. const { backgroundColor } = state['features/dynamic-branding'];
  483. const { startCarMode } = state['features/base/settings'];
  484. const { enabled: audioOnlyEnabled } = state['features/base/audio-only'];
  485. const participantCount = getParticipantCount(state);
  486. const brandingStyles = backgroundColor ? {
  487. backgroundColor
  488. } : undefined;
  489. return {
  490. ...abstractMapStateToProps(state),
  491. _aspectRatio: aspectRatio,
  492. _audioOnlyEnabled: Boolean(audioOnlyEnabled),
  493. _brandingStyles: brandingStyles,
  494. _calendarEnabled: isCalendarEnabled(state),
  495. _connecting: isConnecting(state),
  496. _filmstripVisible: isFilmstripVisible(state),
  497. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  498. _isOneToOneConference: Boolean(participantCount === 2),
  499. _isParticipantsPaneOpen: isOpen,
  500. _largeVideoParticipantId: state['features/large-video'].participantId,
  501. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  502. _reducedUI: reducedUI,
  503. _shouldEnableAutoKnock: shouldEnableAutoKnock(state),
  504. _showLobby: getIsLobbyVisible(state),
  505. _startCarMode: startCarMode,
  506. _toolboxVisible: isToolboxVisible(state)
  507. };
  508. }
  509. export default withSafeAreaInsets(connect(_mapStateToProps)(props => {
  510. const isFocused = useIsFocused();
  511. useEffect(() => {
  512. if (isFocused) {
  513. setPictureInPictureEnabled(true);
  514. } else {
  515. setPictureInPictureEnabled(false);
  516. }
  517. // We also need to disable PiP when we are back on the WelcomePage
  518. return () => setPictureInPictureEnabled(false);
  519. }, [ isFocused ]);
  520. return (
  521. <Conference { ...props } />
  522. );
  523. }));