您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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 { 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. /**
  273. * Renders the conference notification badge if the feature is enabled.
  274. *
  275. * @private
  276. * @returns {React$Node}
  277. */
  278. _renderConferenceNotification() {
  279. const { _calendarEnabled, _reducedUI } = this.props;
  280. return (
  281. _calendarEnabled && !_reducedUI
  282. ? <ConferenceNotification />
  283. : undefined);
  284. }
  285. _createOnPress: (string) => void;
  286. /**
  287. * Creates a function to be invoked when the onPress of the touchables are
  288. * triggered.
  289. *
  290. * @param {string} label - The identifier of the label that's onLayout is
  291. * triggered.
  292. * @returns {Function}
  293. */
  294. _createOnPress(label) {
  295. return () => {
  296. const { visibleExpandedLabel } = this.state;
  297. const newVisibleExpandedLabel
  298. = visibleExpandedLabel === label ? undefined : label;
  299. clearTimeout(this._expandedLabelTimeout.current);
  300. this.setState({
  301. visibleExpandedLabel: newVisibleExpandedLabel
  302. });
  303. if (newVisibleExpandedLabel) {
  304. this._expandedLabelTimeout.current = setTimeout(() => {
  305. this.setState({
  306. visibleExpandedLabel: undefined
  307. });
  308. }, EXPANDED_LABEL_TIMEOUT);
  309. }
  310. };
  311. }
  312. /**
  313. * Renders the content for the Conference container.
  314. *
  315. * @private
  316. * @returns {React$Element}
  317. */
  318. _renderContent() {
  319. const {
  320. _connecting,
  321. _isOneToOneConference,
  322. _largeVideoParticipantId,
  323. _reducedUI,
  324. _shouldDisplayTileView,
  325. _toolboxVisible
  326. } = this.props;
  327. if (_reducedUI) {
  328. return this._renderContentForReducedUi();
  329. }
  330. return (
  331. <>
  332. {/*
  333. * The LargeVideo is the lowermost stacking layer.
  334. */
  335. _shouldDisplayTileView
  336. ? <TileView onClick = { this._onClick } />
  337. : <LargeVideo onClick = { this._onClick } />
  338. }
  339. {/*
  340. * If there is a ringing call, show the callee's info.
  341. */
  342. <CalleeInfoContainer />
  343. }
  344. {/*
  345. * The activity/loading indicator goes above everything, except
  346. * the toolbox/toolbars and the dialogs.
  347. */
  348. _connecting
  349. && <TintedView>
  350. <LoadingIndicator />
  351. </TintedView>
  352. }
  353. <View
  354. pointerEvents = 'box-none'
  355. style = { styles.toolboxAndFilmstripContainer }>
  356. <Captions onPress = { this._onClick } />
  357. {
  358. _shouldDisplayTileView || (
  359. !_isOneToOneConference
  360. && <Container style = { styles.displayNameContainer }>
  361. <DisplayNameLabel
  362. participantId = { _largeVideoParticipantId } />
  363. </Container>
  364. )
  365. }
  366. <LonelyMeetingExperience />
  367. {
  368. _shouldDisplayTileView
  369. || <>
  370. <Filmstrip />
  371. { this._renderNotificationsContainer() }
  372. <Toolbox />
  373. </>
  374. }
  375. </View>
  376. <SafeAreaView
  377. pointerEvents = 'box-none'
  378. style = {
  379. _toolboxVisible
  380. ? styles.titleBarSafeViewColor
  381. : styles.titleBarSafeViewTransparent }>
  382. <TitleBar _createOnPress = { this._createOnPress } />
  383. </SafeAreaView>
  384. <SafeAreaView
  385. pointerEvents = 'box-none'
  386. style = {
  387. _toolboxVisible
  388. ? [ styles.titleBarSafeViewTransparent, { top: this.props.insets.top + 50 } ]
  389. : styles.titleBarSafeViewTransparent
  390. }>
  391. <View
  392. pointerEvents = 'box-none'
  393. style = { styles.expandedLabelWrapper }>
  394. <ExpandedLabelPopup visibleExpandedLabel = { this.state.visibleExpandedLabel } />
  395. </View>
  396. <View
  397. pointerEvents = 'box-none'
  398. style = { styles.alwaysOnTitleBar }>
  399. {/* eslint-disable-next-line react/jsx-no-bind */}
  400. <AlwaysOnLabels createOnPress = { this._createOnPress } />
  401. </View>
  402. </SafeAreaView>
  403. <TestConnectionInfo />
  404. { this._renderConferenceNotification() }
  405. {_shouldDisplayTileView && <Toolbox />}
  406. </>
  407. );
  408. }
  409. /**
  410. * Renders the content for the Conference container when in "reduced UI" mode.
  411. *
  412. * @private
  413. * @returns {React$Element}
  414. */
  415. _renderContentForReducedUi() {
  416. const { _connecting } = this.props;
  417. return (
  418. <>
  419. <LargeVideo onClick = { this._onClick } />
  420. {
  421. _connecting
  422. && <TintedView>
  423. <LoadingIndicator />
  424. </TintedView>
  425. }
  426. </>
  427. );
  428. }
  429. /**
  430. * Renders a container for notifications to be displayed by the
  431. * base/notifications feature.
  432. *
  433. * @private
  434. * @returns {React$Element}
  435. */
  436. _renderNotificationsContainer() {
  437. const notificationsStyle = {};
  438. // In the landscape mode (wide) there's problem with notifications being
  439. // shadowed by the filmstrip rendered on the right. This makes the "x"
  440. // button not clickable. In order to avoid that a margin of the
  441. // filmstrip's size is added to the right.
  442. //
  443. // Pawel: after many attempts I failed to make notifications adjust to
  444. // their contents width because of column and rows being used in the
  445. // flex layout. The only option that seemed to limit the notification's
  446. // size was explicit 'width' value which is not better than the margin
  447. // added here.
  448. const { _aspectRatio, _filmstripVisible } = this.props;
  449. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  450. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  451. }
  452. return super.renderNotificationsContainer(
  453. {
  454. style: notificationsStyle,
  455. toolboxVisible: this.props._toolboxVisible
  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. }));