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

Conference.js 14KB

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