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

Conference.js 17KB

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