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

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