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

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