You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Conference.js 17KB

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