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

Conference.js 18KB

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