Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. // @flow
  2. import React from 'react';
  3. import { BackHandler, SafeAreaView, StatusBar, View } from 'react-native';
  4. import { appNavigate } from '../../../app';
  5. import { connect, disconnect } from '../../../base/connection';
  6. import { getParticipantCount } from '../../../base/participants';
  7. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  8. import { connect as reactReduxConnect } from '../../../base/redux';
  9. import {
  10. isNarrowAspectRatio,
  11. makeAspectRatioAware
  12. } from '../../../base/responsive-ui';
  13. import { TestConnectionInfo } from '../../../base/testing';
  14. import { createDesiredLocalTracks } from '../../../base/tracks';
  15. import { ConferenceNotification } from '../../../calendar-sync';
  16. import { Chat } from '../../../chat';
  17. import { DisplayNameLabel } from '../../../display-name';
  18. import {
  19. FILMSTRIP_SIZE,
  20. Filmstrip,
  21. isFilmstripVisible,
  22. TileView
  23. } from '../../../filmstrip';
  24. import { LargeVideo } from '../../../large-video';
  25. import { AddPeopleDialog, CalleeInfoContainer } from '../../../invite';
  26. import { Captions } from '../../../subtitles';
  27. import { 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 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. * The indicator which determines that we are still connecting to the
  42. * conference which includes establishing the XMPP connection and then
  43. * joining the room. If truthy, then an activity/loading indicator will be
  44. * rendered.
  45. *
  46. * @private
  47. */
  48. _connecting: boolean,
  49. /**
  50. * Set to {@code true} when the filmstrip is currently visible.
  51. *
  52. * @private
  53. */
  54. _filmstripVisible: boolean,
  55. /**
  56. * The ID of the participant currently on stage (if any)
  57. */
  58. _largeVideoParticipantId: string,
  59. /**
  60. * Current conference's full URL.
  61. *
  62. * @private
  63. */
  64. _locationURL: URL,
  65. /**
  66. * The handler which dispatches the (redux) action connect.
  67. *
  68. * @private
  69. * @returns {void}
  70. */
  71. _onConnect: Function,
  72. /**
  73. * The handler which dispatches the (redux) action disconnect.
  74. *
  75. * @private
  76. * @returns {void}
  77. */
  78. _onDisconnect: Function,
  79. /**
  80. * Handles a hardware button press for back navigation. Leaves the
  81. * associated {@code Conference}.
  82. *
  83. * @private
  84. * @returns {boolean} As the associated conference is unconditionally left
  85. * and exiting the app while it renders a {@code Conference} is undesired,
  86. * {@code true} is always returned.
  87. */
  88. _onHardwareBackPress: Function,
  89. /**
  90. * The number of participants in the conference.
  91. *
  92. * @private
  93. */
  94. _participantCount: number,
  95. /**
  96. * The indicator which determines whether the UI is reduced (to accommodate
  97. * smaller display areas).
  98. *
  99. * @private
  100. */
  101. _reducedUI: boolean,
  102. /**
  103. * The handler which dispatches the (redux) action {@link setToolboxVisible}
  104. * to show/hide the {@link Toolbox}.
  105. *
  106. * @param {boolean} visible - {@code true} to show the {@code Toolbox} or
  107. * {@code false} to hide it.
  108. * @private
  109. * @returns {void}
  110. */
  111. _setToolboxVisible: Function,
  112. /**
  113. * The indicator which determines whether the Toolbox is visible.
  114. *
  115. * @private
  116. */
  117. _toolboxVisible: boolean,
  118. /**
  119. * The indicator which determines whether the Toolbox is always visible.
  120. *
  121. * @private
  122. */
  123. _toolboxAlwaysVisible: boolean
  124. };
  125. /**
  126. * The conference page of the mobile (i.e. React Native) application.
  127. */
  128. class Conference extends AbstractConference<Props, *> {
  129. /**
  130. * Initializes a new Conference instance.
  131. *
  132. * @param {Object} props - The read-only properties with which the new
  133. * instance is to be initialized.
  134. */
  135. constructor(props) {
  136. super(props);
  137. // Bind event handlers so they are only bound once per instance.
  138. this._onClick = this._onClick.bind(this);
  139. }
  140. /**
  141. * Implements {@link Component#componentDidMount()}. Invoked immediately
  142. * after this component is mounted.
  143. *
  144. * @inheritdoc
  145. * @returns {void}
  146. */
  147. componentDidMount() {
  148. this.props._onConnect();
  149. BackHandler.addEventListener(
  150. 'hardwareBackPress',
  151. this.props._onHardwareBackPress);
  152. // Show the toolbox if we are the only participant; otherwise, the whole
  153. // UI looks too unpopulated the LargeVideo visible.
  154. const { _participantCount, _setToolboxVisible } = this.props;
  155. _participantCount === 1 && _setToolboxVisible(true);
  156. }
  157. /**
  158. * Implements React's {@link Component#componentDidUpdate()}.
  159. *
  160. * @inheritdoc
  161. */
  162. componentDidUpdate(pevProps: Props) {
  163. const {
  164. _locationURL: oldLocationURL,
  165. _participantCount: oldParticipantCount,
  166. _room: oldRoom
  167. } = pevProps;
  168. const {
  169. _locationURL: newLocationURL,
  170. _participantCount: newParticipantCount,
  171. _room: newRoom,
  172. _setToolboxVisible,
  173. _toolboxVisible
  174. } = this.props;
  175. // If the location URL changes we need to reconnect.
  176. oldLocationURL !== newLocationURL && newRoom && this.props._onDisconnect();
  177. // Start the connection process when there is a (valid) room.
  178. oldRoom !== newRoom && newRoom && this.props._onConnect();
  179. if (oldParticipantCount === 1
  180. && newParticipantCount > 1
  181. && _toolboxVisible) {
  182. _setToolboxVisible(false);
  183. } else if (oldParticipantCount > 1
  184. && newParticipantCount === 1
  185. && !_toolboxVisible) {
  186. _setToolboxVisible(true);
  187. }
  188. }
  189. /**
  190. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  191. * before this component is unmounted and destroyed. Disconnects the
  192. * conference described by the redux store/state.
  193. *
  194. * @inheritdoc
  195. * @returns {void}
  196. */
  197. componentWillUnmount() {
  198. // Tear handling any hardware button presses for back navigation down.
  199. BackHandler.removeEventListener(
  200. 'hardwareBackPress',
  201. this.props._onHardwareBackPress);
  202. this.props._onDisconnect();
  203. }
  204. /**
  205. * Implements React's {@link Component#render()}.
  206. *
  207. * @inheritdoc
  208. * @returns {ReactElement}
  209. */
  210. render() {
  211. const {
  212. _connecting,
  213. _largeVideoParticipantId,
  214. _reducedUI,
  215. _shouldDisplayTileView
  216. } = this.props;
  217. return (
  218. <Container style = { styles.conference }>
  219. <StatusBar
  220. barStyle = 'light-content'
  221. hidden = { true }
  222. translucent = { true } />
  223. <Chat />
  224. <AddPeopleDialog />
  225. {/*
  226. * The LargeVideo is the lowermost stacking layer.
  227. */
  228. _shouldDisplayTileView
  229. ? <TileView onClick = { this._onClick } />
  230. : <LargeVideo onClick = { this._onClick } />
  231. }
  232. {/*
  233. * If there is a ringing call, show the callee's info.
  234. */
  235. _reducedUI || <CalleeInfoContainer />
  236. }
  237. {/*
  238. * The activity/loading indicator goes above everything, except
  239. * the toolbox/toolbars and the dialogs.
  240. */
  241. _connecting
  242. && <TintedView>
  243. <LoadingIndicator />
  244. </TintedView>
  245. }
  246. <View
  247. pointerEvents = 'box-none'
  248. style = { styles.toolboxAndFilmstripContainer }>
  249. <Labels />
  250. <Captions onPress = { this._onClick } />
  251. { _shouldDisplayTileView || <DisplayNameLabel participantId = { _largeVideoParticipantId } /> }
  252. {/*
  253. * The Toolbox is in a stacking layer bellow the Filmstrip.
  254. */}
  255. <Toolbox />
  256. {/*
  257. * The Filmstrip is in a stacking layer above the
  258. * LargeVideo. The LargeVideo and the Filmstrip form what
  259. * the Web/React app calls "videospace". Presumably, the
  260. * name and grouping stem from the fact that these two
  261. * React Components depict the videos of the conference's
  262. * participants.
  263. */
  264. _shouldDisplayTileView ? undefined : <Filmstrip />
  265. }
  266. </View>
  267. <SafeAreaView
  268. pointerEvents = 'box-none'
  269. style = { styles.navBarSafeView }>
  270. <NavigationBar />
  271. { this.renderNotificationsContainer() }
  272. </SafeAreaView>
  273. <TestConnectionInfo />
  274. {
  275. this._renderConferenceNotification()
  276. }
  277. </Container>
  278. );
  279. }
  280. _onClick: () => void;
  281. /**
  282. * Changes the value of the toolboxVisible state, thus allowing us to switch
  283. * between Toolbox and Filmstrip and change their visibility.
  284. *
  285. * @private
  286. * @returns {void}
  287. */
  288. _onClick() {
  289. if (this.props._toolboxAlwaysVisible) {
  290. return;
  291. }
  292. const toolboxVisible = !this.props._toolboxVisible;
  293. this.props._setToolboxVisible(toolboxVisible);
  294. }
  295. /**
  296. * Renders the conference notification badge if the feature is enabled.
  297. *
  298. * @private
  299. * @returns {React$Node}
  300. */
  301. _renderConferenceNotification() {
  302. // XXX If the calendar feature is disabled on a platform, then we don't
  303. // have its components exported so an undefined check is necessary.
  304. return (
  305. !this.props._reducedUI && ConferenceNotification
  306. ? <ConferenceNotification />
  307. : undefined);
  308. }
  309. /**
  310. * Renders a container for notifications to be displayed by the
  311. * base/notifications feature.
  312. *
  313. * @private
  314. * @returns {React$Element}
  315. */
  316. renderNotificationsContainer() {
  317. const notificationsStyle = {};
  318. // In the landscape mode (wide) there's problem with notifications being
  319. // shadowed by the filmstrip rendered on the right. This makes the "x"
  320. // button not clickable. In order to avoid that a margin of the
  321. // filmstrip's size is added to the right.
  322. //
  323. // Pawel: after many attempts I failed to make notifications adjust to
  324. // their contents width because of column and rows being used in the
  325. // flex layout. The only option that seemed to limit the notification's
  326. // size was explicit 'width' value which is not better than the margin
  327. // added here.
  328. if (this.props._filmstripVisible && !isNarrowAspectRatio(this)) {
  329. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  330. }
  331. return super.renderNotificationsContainer(
  332. {
  333. style: notificationsStyle
  334. }
  335. );
  336. }
  337. }
  338. /**
  339. * Maps dispatching of some action to React component props.
  340. *
  341. * @param {Function} dispatch - Redux action dispatcher.
  342. * @private
  343. * @returns {{
  344. * _onConnect: Function,
  345. * _onDisconnect: Function,
  346. * _onHardwareBackPress: Function,
  347. * _setToolboxVisible: Function
  348. * }}
  349. */
  350. function _mapDispatchToProps(dispatch) {
  351. return {
  352. /**
  353. * Dispatches actions to create the desired local tracks and for
  354. * connecting to the conference.
  355. *
  356. * @private
  357. * @returns {void}
  358. */
  359. _onConnect() {
  360. dispatch(createDesiredLocalTracks());
  361. dispatch(connect());
  362. },
  363. /**
  364. * Dispatches an action disconnecting from the conference.
  365. *
  366. * @private
  367. * @returns {void}
  368. */
  369. _onDisconnect() {
  370. dispatch(disconnect());
  371. },
  372. /**
  373. * Handles a hardware button press for back navigation. Leaves the
  374. * associated {@code Conference}.
  375. *
  376. * @returns {boolean} As the associated conference is unconditionally
  377. * left and exiting the app while it renders a {@code Conference} is
  378. * undesired, {@code true} is always returned.
  379. */
  380. _onHardwareBackPress() {
  381. dispatch(appNavigate(undefined));
  382. return true;
  383. },
  384. /**
  385. * Dispatches an action changing the visibility of the {@link Toolbox}.
  386. *
  387. * @private
  388. * @param {boolean} visible - Pass {@code true} to show the
  389. * {@code Toolbox} or {@code false} to hide it.
  390. * @returns {void}
  391. */
  392. _setToolboxVisible(visible) {
  393. dispatch(setToolboxVisible(visible));
  394. }
  395. };
  396. }
  397. /**
  398. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  399. *
  400. * @param {Object} state - The redux state.
  401. * @private
  402. * @returns {Props}
  403. */
  404. function _mapStateToProps(state) {
  405. const { connecting, connection, locationURL }
  406. = state['features/base/connection'];
  407. const {
  408. conference,
  409. joining,
  410. leaving
  411. } = state['features/base/conference'];
  412. const { reducedUI } = state['features/base/responsive-ui'];
  413. const { alwaysVisible, visible } = state['features/toolbox'];
  414. // XXX There is a window of time between the successful establishment of the
  415. // XMPP connection and the subsequent commencement of joining the MUC during
  416. // which the app does not appear to be doing anything according to the redux
  417. // state. In order to not toggle the _connecting props during the window of
  418. // time in question, define _connecting as follows:
  419. // - the XMPP connection is connecting, or
  420. // - the XMPP connection is connected and the conference is joining, or
  421. // - the XMPP connection is connected and we have no conference yet, nor we
  422. // are leaving one.
  423. const connecting_
  424. = connecting || (connection && (joining || (!conference && !leaving)));
  425. return {
  426. ...abstractMapStateToProps(state),
  427. /**
  428. * The indicator which determines that we are still connecting to the
  429. * conference which includes establishing the XMPP connection and then
  430. * joining the room. If truthy, then an activity/loading indicator will
  431. * be rendered.
  432. *
  433. * @private
  434. * @type {boolean}
  435. */
  436. _connecting: Boolean(connecting_),
  437. /**
  438. * Is {@code true} when the filmstrip is currently visible.
  439. */
  440. _filmstripVisible: isFilmstripVisible(state),
  441. /**
  442. * The ID of the participant currently on stage.
  443. */
  444. _largeVideoParticipantId: state['features/large-video'].participantId,
  445. /**
  446. * Current conference's full URL.
  447. *
  448. * @private
  449. * @type {URL}
  450. */
  451. _locationURL: locationURL,
  452. /**
  453. * The number of participants in the conference.
  454. *
  455. * @private
  456. * @type {number}
  457. */
  458. _participantCount: getParticipantCount(state),
  459. /**
  460. * The indicator which determines whether the UI is reduced (to
  461. * accommodate smaller display areas).
  462. *
  463. * @private
  464. * @type {boolean}
  465. */
  466. _reducedUI: reducedUI,
  467. /**
  468. * The indicator which determines whether the Toolbox is visible.
  469. *
  470. * @private
  471. * @type {boolean}
  472. */
  473. _toolboxVisible: visible,
  474. /**
  475. * The indicator which determines whether the Toolbox is always visible.
  476. *
  477. * @private
  478. * @type {boolean}
  479. */
  480. _toolboxAlwaysVisible: alwaysVisible
  481. };
  482. }
  483. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  484. makeAspectRatioAware(Conference));