Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Conference.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. // @flow
  2. import { useIsFocused } from '@react-navigation/native';
  3. import React, { useEffect } from 'react';
  4. import {
  5. BackHandler,
  6. NativeModules,
  7. Platform,
  8. SafeAreaView,
  9. StatusBar,
  10. View
  11. } from 'react-native';
  12. import { withSafeAreaInsets } from 'react-native-safe-area-context';
  13. import { connect } from 'react-redux';
  14. import { appNavigate } from '../../../app/actions';
  15. import { FULLSCREEN_ENABLED, PIP_ENABLED, getFeatureFlag } from '../../../base/flags';
  16. import { getParticipantCount } from '../../../base/participants';
  17. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  18. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  19. import { TestConnectionInfo } from '../../../base/testing';
  20. import { isCalendarEnabled } from '../../../calendar-sync/functions.native';
  21. import { DisplayNameLabel } from '../../../display-name';
  22. import { BrandingImageBackground } from '../../../dynamic-branding/components/native';
  23. import {
  24. FILMSTRIP_SIZE,
  25. Filmstrip,
  26. TileView,
  27. isFilmstripVisible
  28. } from '../../../filmstrip';
  29. import { CalleeInfoContainer } from '../../../invite';
  30. import { LargeVideo } from '../../../large-video';
  31. import { startKnocking } from '../../../lobby/actions.any';
  32. import { getIsLobbyVisible } from '../../../lobby/functions';
  33. import { navigate }
  34. from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  35. import { shouldEnableAutoKnock } from '../../../mobile/navigation/functions';
  36. import { screen } from '../../../mobile/navigation/routes';
  37. import { setPictureInPictureEnabled } from '../../../mobile/picture-in-picture';
  38. import { Captions } from '../../../subtitles/components';
  39. import { setToolboxVisible } from '../../../toolbox/actions';
  40. import { Toolbox } from '../../../toolbox/components/native';
  41. import { isToolboxVisible } from '../../../toolbox/functions';
  42. import {
  43. AbstractConference,
  44. abstractMapStateToProps
  45. } from '../AbstractConference';
  46. import type { AbstractProps } from '../AbstractConference';
  47. import { isConnecting } from '../functions';
  48. import AlwaysOnLabels from './AlwaysOnLabels';
  49. import ExpandedLabelPopup from './ExpandedLabelPopup';
  50. import LonelyMeetingExperience from './LonelyMeetingExperience';
  51. import TitleBar from './TitleBar';
  52. import { EXPANDED_LABEL_TIMEOUT } from './constants';
  53. import styles from './styles';
  54. /**
  55. * The type of the React {@code Component} props of {@link Conference}.
  56. */
  57. type Props = AbstractProps & {
  58. /**
  59. * Application's aspect ratio.
  60. */
  61. _aspectRatio: Symbol,
  62. /**
  63. * Whether the audio only is enabled or not.
  64. */
  65. _audioOnlyEnabled: boolean,
  66. /**
  67. * Branding styles for conference.
  68. */
  69. _brandingStyles: Object,
  70. /**
  71. * Whether the calendar feature is enabled or not.
  72. */
  73. _calendarEnabled: boolean,
  74. /**
  75. * The indicator which determines that we are still connecting to the
  76. * conference which includes establishing the XMPP connection and then
  77. * joining the room. If truthy, then an activity/loading indicator will be
  78. * rendered.
  79. */
  80. _connecting: boolean,
  81. /**
  82. * Set to {@code true} when the filmstrip is currently visible.
  83. */
  84. _filmstripVisible: boolean,
  85. /**
  86. * The indicator which determines whether fullscreen (immersive) mode is enabled.
  87. */
  88. _fullscreenEnabled: boolean,
  89. /**
  90. * The indicator which determines if the conference type is one to one.
  91. */
  92. _isOneToOneConference: boolean,
  93. /**
  94. * The indicator which determines if the participants pane is open.
  95. */
  96. _isParticipantsPaneOpen: boolean,
  97. /**
  98. * The ID of the participant currently on stage (if any).
  99. */
  100. _largeVideoParticipantId: string,
  101. /**
  102. * Local participant's display name.
  103. */
  104. _localParticipantDisplayName: string,
  105. /**
  106. * Whether Picture-in-Picture is enabled.
  107. */
  108. _pictureInPictureEnabled: boolean,
  109. /**
  110. * The indicator which determines whether the UI is reduced (to accommodate
  111. * smaller display areas).
  112. */
  113. _reducedUI: boolean,
  114. /**
  115. * The indicator which determines whether the Toolbox is visible.
  116. */
  117. _toolboxVisible: boolean,
  118. /**
  119. * Indicates if we should auto-knock.
  120. */
  121. _shouldEnableAutoKnock: boolean,
  122. /**
  123. * Indicates whether the lobby screen should be visible.
  124. */
  125. _showLobby: boolean,
  126. /**
  127. * Indicates whether the car mode is enabled.
  128. */
  129. _startCarMode: boolean,
  130. /**
  131. * The redux {@code dispatch} function.
  132. */
  133. dispatch: Function,
  134. /**
  135. * Object containing the safe area insets.
  136. */
  137. insets: Object,
  138. /**
  139. * Default prop for navigating between screen components(React Navigation).
  140. */
  141. navigation: Object
  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<Props, State> {
  153. /**
  154. * Timeout ref.
  155. */
  156. _expandedLabelTimeout: Object;
  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) {
  164. super(props);
  165. this.state = {
  166. visibleExpandedLabel: undefined
  167. };
  168. this._expandedLabelTimeout = React.createRef();
  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) {
  199. const {
  200. _shouldEnableAutoKnock,
  201. _showLobby,
  202. dispatch
  203. } = this.props;
  204. if (!prevProps._showLobby && _showLobby) {
  205. navigate(screen.lobby.root);
  206. if (_shouldEnableAutoKnock) {
  207. dispatch(startKnocking());
  208. }
  209. }
  210. if (prevProps._showLobby && !_showLobby) {
  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);
  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. _onClick: () => void;
  257. /**
  258. * Changes the value of the toolboxVisible state, thus allowing us to switch
  259. * between Toolbox and Filmstrip and change their visibility.
  260. *
  261. * @private
  262. * @returns {void}
  263. */
  264. _onClick() {
  265. this._setToolboxVisible(!this.props._toolboxVisible);
  266. }
  267. _onHardwareBackPress: () => boolean;
  268. /**
  269. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  270. * (if supported) or leaves the associated {@code Conference} otherwise.
  271. *
  272. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  273. */
  274. _onHardwareBackPress() {
  275. let p;
  276. if (this.props._pictureInPictureEnabled) {
  277. const { PictureInPicture } = NativeModules;
  278. p = PictureInPicture.enterPictureInPicture();
  279. } else {
  280. p = Promise.reject(new Error('PiP not enabled'));
  281. }
  282. p.catch(() => {
  283. this.props.dispatch(appNavigate(undefined));
  284. });
  285. return true;
  286. }
  287. _createOnPress: (string) => void;
  288. /**
  289. * Creates a function to be invoked when the onPress of the touchables are
  290. * triggered.
  291. *
  292. * @param {string} label - The identifier of the label that's onLayout is
  293. * triggered.
  294. * @returns {Function}
  295. */
  296. _createOnPress(label) {
  297. return () => {
  298. const { visibleExpandedLabel } = this.state;
  299. const newVisibleExpandedLabel
  300. = visibleExpandedLabel === label ? undefined : label;
  301. clearTimeout(this._expandedLabelTimeout.current);
  302. this.setState({
  303. visibleExpandedLabel: newVisibleExpandedLabel
  304. });
  305. if (newVisibleExpandedLabel) {
  306. this._expandedLabelTimeout.current = setTimeout(() => {
  307. this.setState({
  308. visibleExpandedLabel: undefined
  309. });
  310. }, EXPANDED_LABEL_TIMEOUT);
  311. }
  312. };
  313. }
  314. /**
  315. * Renders the content for the Conference container.
  316. *
  317. * @private
  318. * @returns {React$Element}
  319. */
  320. _renderContent() {
  321. const {
  322. _connecting,
  323. _isOneToOneConference,
  324. _largeVideoParticipantId,
  325. _reducedUI,
  326. _shouldDisplayTileView,
  327. _toolboxVisible
  328. } = this.props;
  329. if (_reducedUI) {
  330. return this._renderContentForReducedUi();
  331. }
  332. return (
  333. <>
  334. {/*
  335. * The LargeVideo is the lowermost stacking layer.
  336. */
  337. _shouldDisplayTileView
  338. ? <TileView onClick = { this._onClick } />
  339. : <LargeVideo onClick = { this._onClick } />
  340. }
  341. {/*
  342. * If there is a ringing call, show the callee's info.
  343. */
  344. <CalleeInfoContainer />
  345. }
  346. {/*
  347. * The activity/loading indicator goes above everything, except
  348. * the toolbox/toolbars and the dialogs.
  349. */
  350. _connecting
  351. && <TintedView>
  352. <LoadingIndicator />
  353. </TintedView>
  354. }
  355. <View
  356. pointerEvents = 'box-none'
  357. style = { styles.toolboxAndFilmstripContainer }>
  358. <Captions onPress = { this._onClick } />
  359. {
  360. _shouldDisplayTileView || (
  361. !_isOneToOneConference
  362. && <Container style = { styles.displayNameContainer }>
  363. <DisplayNameLabel
  364. participantId = { _largeVideoParticipantId } />
  365. </Container>
  366. )
  367. }
  368. <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 }>
  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
  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 = { styles.alwaysOnTitleBar }>
  401. {/* eslint-disable-next-line react/jsx-no-bind */}
  402. <AlwaysOnLabels createOnPress = { this._createOnPress } />
  403. </View>
  404. </SafeAreaView>
  405. <TestConnectionInfo />
  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. toolboxVisible: this.props._toolboxVisible
  457. }
  458. );
  459. }
  460. _setToolboxVisible: (boolean) => void;
  461. /**
  462. * Dispatches an action changing the visibility of the {@link Toolbox}.
  463. *
  464. * @private
  465. * @param {boolean} visible - Pass {@code true} to show the
  466. * {@code Toolbox} or {@code false} to hide it.
  467. * @returns {void}
  468. */
  469. _setToolboxVisible(visible) {
  470. this.props.dispatch(setToolboxVisible(visible));
  471. }
  472. }
  473. /**
  474. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  475. *
  476. * @param {Object} state - The redux state.
  477. * @private
  478. * @returns {Props}
  479. */
  480. function _mapStateToProps(state) {
  481. const { isOpen } = state['features/participants-pane'];
  482. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  483. const { backgroundColor } = state['features/dynamic-branding'];
  484. const { startCarMode } = state['features/base/settings'];
  485. const { enabled: audioOnlyEnabled } = state['features/base/audio-only'];
  486. const participantCount = getParticipantCount(state);
  487. const brandingStyles = backgroundColor ? {
  488. backgroundColor
  489. } : undefined;
  490. return {
  491. ...abstractMapStateToProps(state),
  492. _aspectRatio: aspectRatio,
  493. _audioOnlyEnabled: Boolean(audioOnlyEnabled),
  494. _brandingStyles: brandingStyles,
  495. _calendarEnabled: isCalendarEnabled(state),
  496. _connecting: isConnecting(state),
  497. _filmstripVisible: isFilmstripVisible(state),
  498. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  499. _isOneToOneConference: Boolean(participantCount === 2),
  500. _isParticipantsPaneOpen: isOpen,
  501. _largeVideoParticipantId: state['features/large-video'].participantId,
  502. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  503. _reducedUI: reducedUI,
  504. _shouldEnableAutoKnock: shouldEnableAutoKnock(state),
  505. _showLobby: getIsLobbyVisible(state),
  506. _startCarMode: startCarMode,
  507. _toolboxVisible: isToolboxVisible(state)
  508. };
  509. }
  510. export default withSafeAreaInsets(connect(_mapStateToProps)(props => {
  511. const isFocused = useIsFocused();
  512. useEffect(() => {
  513. if (isFocused) {
  514. setPictureInPictureEnabled(true);
  515. } else {
  516. setPictureInPictureEnabled(false);
  517. }
  518. // We also need to disable PiP when we are back on the WelcomePage
  519. return () => setPictureInPictureEnabled(false);
  520. }, [ isFocused ]);
  521. return (
  522. <Conference { ...props } />
  523. );
  524. }));