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 13KB

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