您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. // @flow
  2. import React from 'react';
  3. import { NativeModules, SafeAreaView, StatusBar } from 'react-native';
  4. import LinearGradient from 'react-native-linear-gradient';
  5. import { appNavigate } from '../../../app/actions';
  6. import { PIP_ENABLED, FULLSCREEN_ENABLED, getFeatureFlag } from '../../../base/flags';
  7. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  8. import { connect } from '../../../base/redux';
  9. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  10. import { TestConnectionInfo } from '../../../base/testing';
  11. import { ConferenceNotification, isCalendarEnabled } from '../../../calendar-sync';
  12. import { Chat } from '../../../chat';
  13. import { DisplayNameLabel } from '../../../display-name';
  14. import { SharedDocument } from '../../../etherpad';
  15. import {
  16. FILMSTRIP_SIZE,
  17. Filmstrip,
  18. isFilmstripVisible,
  19. TileView
  20. } from '../../../filmstrip';
  21. import { AddPeopleDialog, CalleeInfoContainer } from '../../../invite';
  22. import { LargeVideo } from '../../../large-video';
  23. import { KnockingParticipantList } from '../../../lobby';
  24. import { BackButtonRegistry } from '../../../mobile/back-button';
  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 Labels from './Labels';
  35. import LonelyMeetingExperience from './LonelyMeetingExperience';
  36. import NavigationBar from './NavigationBar';
  37. import styles, { NAVBAR_GRADIENT_COLORS } from './styles';
  38. /**
  39. * The type of the React {@code Component} props of {@link Conference}.
  40. */
  41. type Props = AbstractProps & {
  42. /**
  43. * Application's aspect ratio.
  44. */
  45. _aspectRatio: Symbol,
  46. /**
  47. * Wherther the calendar feature is enabled or not.
  48. */
  49. _calendarEnabled: boolean,
  50. /**
  51. * The indicator which determines that we are still connecting to the
  52. * conference which includes establishing the XMPP connection and then
  53. * joining the room. If truthy, then an activity/loading indicator will be
  54. * rendered.
  55. */
  56. _connecting: boolean,
  57. /**
  58. * Set to {@code true} when the filmstrip is currently visible.
  59. */
  60. _filmstripVisible: boolean,
  61. /**
  62. * The indicator which determines whether fullscreen (immersive) mode is enabled.
  63. */
  64. _fullscreenEnabled: 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. _aspectRatio,
  209. _connecting,
  210. _filmstripVisible,
  211. _largeVideoParticipantId,
  212. _reducedUI,
  213. _shouldDisplayTileView,
  214. _toolboxVisible
  215. } = this.props;
  216. const showGradient = _toolboxVisible;
  217. const applyGradientStretching
  218. = _filmstripVisible && _aspectRatio === ASPECT_RATIO_NARROW && !_shouldDisplayTileView;
  219. if (_reducedUI) {
  220. return this._renderContentForReducedUi();
  221. }
  222. return (
  223. <>
  224. {/*
  225. * The LargeVideo is the lowermost stacking layer.
  226. */
  227. _shouldDisplayTileView
  228. ? <TileView onClick = { this._onClick } />
  229. : <LargeVideo onClick = { this._onClick } />
  230. }
  231. {/*
  232. * If there is a ringing call, show the callee's info.
  233. */
  234. <CalleeInfoContainer />
  235. }
  236. {/*
  237. * The activity/loading indicator goes above everything, except
  238. * the toolbox/toolbars and the dialogs.
  239. */
  240. _connecting
  241. && <TintedView>
  242. <LoadingIndicator />
  243. </TintedView>
  244. }
  245. <SafeAreaView
  246. pointerEvents = 'box-none'
  247. style = { styles.toolboxAndFilmstripContainer }>
  248. { showGradient && <LinearGradient
  249. colors = { NAVBAR_GRADIENT_COLORS }
  250. end = {{
  251. x: 0.0,
  252. y: 0.0
  253. }}
  254. pointerEvents = 'none'
  255. start = {{
  256. x: 0.0,
  257. y: 1.0
  258. }}
  259. style = { [
  260. styles.bottomGradient,
  261. applyGradientStretching ? styles.gradientStretchBottom : undefined
  262. ] } />}
  263. <Labels />
  264. <Captions onPress = { this._onClick } />
  265. { _shouldDisplayTileView || <Container style = { styles.displayNameContainer }>
  266. <DisplayNameLabel participantId = { _largeVideoParticipantId } />
  267. </Container> }
  268. <LonelyMeetingExperience />
  269. { _shouldDisplayTileView ? undefined : <Filmstrip /> }
  270. <Toolbox />
  271. </SafeAreaView>
  272. <SafeAreaView
  273. pointerEvents = 'box-none'
  274. style = { styles.navBarSafeView }>
  275. <NavigationBar />
  276. { this._renderNotificationsContainer() }
  277. <KnockingParticipantList />
  278. </SafeAreaView>
  279. <TestConnectionInfo />
  280. { this._renderConferenceNotification() }
  281. { this._renderConferenceModals() }
  282. </>
  283. );
  284. }
  285. /**
  286. * Renders the content for the Conference container when in "reduced UI" mode.
  287. *
  288. * @private
  289. * @returns {React$Element}
  290. */
  291. _renderContentForReducedUi() {
  292. const { _connecting } = this.props;
  293. return (
  294. <>
  295. <LargeVideo onClick = { this._onClick } />
  296. {
  297. _connecting
  298. && <TintedView>
  299. <LoadingIndicator />
  300. </TintedView>
  301. }
  302. </>
  303. );
  304. }
  305. /**
  306. * Renders a container for notifications to be displayed by the
  307. * base/notifications feature.
  308. *
  309. * @private
  310. * @returns {React$Element}
  311. */
  312. _renderNotificationsContainer() {
  313. const notificationsStyle = {};
  314. // In the landscape mode (wide) there's problem with notifications being
  315. // shadowed by the filmstrip rendered on the right. This makes the "x"
  316. // button not clickable. In order to avoid that a margin of the
  317. // filmstrip's size is added to the right.
  318. //
  319. // Pawel: after many attempts I failed to make notifications adjust to
  320. // their contents width because of column and rows being used in the
  321. // flex layout. The only option that seemed to limit the notification's
  322. // size was explicit 'width' value which is not better than the margin
  323. // added here.
  324. const { _aspectRatio, _filmstripVisible } = this.props;
  325. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  326. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  327. }
  328. return super.renderNotificationsContainer(
  329. {
  330. style: notificationsStyle
  331. }
  332. );
  333. }
  334. _setToolboxVisible: (boolean) => void;
  335. /**
  336. * Dispatches an action changing the visibility of the {@link Toolbox}.
  337. *
  338. * @private
  339. * @param {boolean} visible - Pass {@code true} to show the
  340. * {@code Toolbox} or {@code false} to hide it.
  341. * @returns {void}
  342. */
  343. _setToolboxVisible(visible) {
  344. this.props.dispatch(setToolboxVisible(visible));
  345. }
  346. }
  347. /**
  348. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  349. *
  350. * @param {Object} state - The redux state.
  351. * @private
  352. * @returns {Props}
  353. */
  354. function _mapStateToProps(state) {
  355. const { connecting, connection } = state['features/base/connection'];
  356. const {
  357. conference,
  358. joining,
  359. membersOnly,
  360. leaving
  361. } = state['features/base/conference'];
  362. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  363. // XXX There is a window of time between the successful establishment of the
  364. // XMPP connection and the subsequent commencement of joining the MUC during
  365. // which the app does not appear to be doing anything according to the redux
  366. // state. In order to not toggle the _connecting props during the window of
  367. // time in question, define _connecting as follows:
  368. // - the XMPP connection is connecting, or
  369. // - the XMPP connection is connected and the conference is joining, or
  370. // - the XMPP connection is connected and we have no conference yet, nor we
  371. // are leaving one.
  372. const connecting_
  373. = connecting || (connection && (!membersOnly && (joining || (!conference && !leaving))));
  374. return {
  375. ...abstractMapStateToProps(state),
  376. _aspectRatio: aspectRatio,
  377. _calendarEnabled: isCalendarEnabled(state),
  378. _connecting: Boolean(connecting_),
  379. _filmstripVisible: isFilmstripVisible(state),
  380. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  381. _largeVideoParticipantId: state['features/large-video'].participantId,
  382. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  383. _reducedUI: reducedUI,
  384. _toolboxVisible: isToolboxVisible(state)
  385. };
  386. }
  387. export default connect(_mapStateToProps)(Conference);