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

Conference.js 14KB

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