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

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