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

Conference.js 13KB

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