選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Conference.tsx 19KB

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