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

Conference.js 18KB

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