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

Conference.native.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { BackHandler, StatusBar, View } from 'react-native';
  4. import { connect as reactReduxConnect } from 'react-redux';
  5. import { appNavigate } from '../../app';
  6. import { connect, disconnect } from '../../base/connection';
  7. import { getParticipantCount } from '../../base/participants';
  8. import { Container, LoadingIndicator, TintedView } from '../../base/react';
  9. import {
  10. makeAspectRatioAware
  11. } from '../../base/responsive-ui';
  12. import { TestConnectionInfo } from '../../base/testing';
  13. import { createDesiredLocalTracks } from '../../base/tracks';
  14. import { ConferenceNotification } from '../../calendar-sync';
  15. import { Chat } from '../../chat';
  16. import {
  17. Filmstrip,
  18. isFilmstripVisible,
  19. TileView
  20. } from '../../filmstrip';
  21. import { LargeVideo } from '../../large-video';
  22. import { CalleeInfoContainer } from '../../invite';
  23. import { Captions } from '../../subtitles';
  24. import { setToolboxVisible, Toolbox } from '../../toolbox';
  25. import { shouldDisplayTileView } from '../../video-layout';
  26. import DisplayNameLabel from './DisplayNameLabel';
  27. import styles from './styles';
  28. /**
  29. * The type of the React {@code Component} props of {@link Conference}.
  30. */
  31. type Props = {
  32. /**
  33. * The indicator which determines that we are still connecting to the
  34. * conference which includes establishing the XMPP connection and then
  35. * joining the room. If truthy, then an activity/loading indicator will be
  36. * rendered.
  37. *
  38. * @private
  39. */
  40. _connecting: boolean,
  41. /**
  42. * Set to {@code true} when the filmstrip is currently visible.
  43. *
  44. * @private
  45. */
  46. _filmstripVisible: boolean,
  47. /**
  48. * Current conference's full URL.
  49. *
  50. * @private
  51. */
  52. _locationURL: URL,
  53. /**
  54. * The handler which dispatches the (redux) action connect.
  55. *
  56. * @private
  57. * @returns {void}
  58. */
  59. _onConnect: Function,
  60. /**
  61. * The handler which dispatches the (redux) action disconnect.
  62. *
  63. * @private
  64. * @returns {void}
  65. */
  66. _onDisconnect: Function,
  67. /**
  68. * Handles a hardware button press for back navigation. Leaves the
  69. * associated {@code Conference}.
  70. *
  71. * @private
  72. * @returns {boolean} As the associated conference is unconditionally left
  73. * and exiting the app while it renders a {@code Conference} is undesired,
  74. * {@code true} is always returned.
  75. */
  76. _onHardwareBackPress: Function,
  77. /**
  78. * The number of participants in the conference.
  79. *
  80. * @private
  81. */
  82. _participantCount: number,
  83. /**
  84. * The indicator which determines whether the UI is reduced (to accommodate
  85. * smaller display areas).
  86. *
  87. * @private
  88. */
  89. _reducedUI: boolean,
  90. /**
  91. * The current conference room name.
  92. *
  93. * @private
  94. */
  95. _room: string,
  96. /**
  97. * The handler which dispatches the (redux) action {@link setToolboxVisible}
  98. * to show/hide the {@link Toolbox}.
  99. *
  100. * @param {boolean} visible - {@code true} to show the {@code Toolbox} or
  101. * {@code false} to hide it.
  102. * @private
  103. * @returns {void}
  104. */
  105. _setToolboxVisible: Function,
  106. /**
  107. * Whether or not the layout should change to support tile view mode.
  108. *
  109. * @private
  110. */
  111. _shouldDisplayTileView: boolean,
  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 Component<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 && 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. _reducedUI,
  214. _shouldDisplayTileView
  215. } = this.props;
  216. return (
  217. <Container style = { styles.conference }>
  218. <StatusBar
  219. barStyle = 'light-content'
  220. hidden = { true }
  221. translucent = { true } />
  222. <Chat />
  223. {/*
  224. * The LargeVideo is the lowermost stacking layer.
  225. */
  226. _shouldDisplayTileView
  227. ? <TileView onClick = { this._onClick } />
  228. : <LargeVideo onClick = { this._onClick } />
  229. }
  230. {/*
  231. * If there is a ringing call, show the callee's info.
  232. */
  233. _reducedUI || <CalleeInfoContainer />
  234. }
  235. {/*
  236. * The activity/loading indicator goes above everything, except
  237. * the toolbox/toolbars and the dialogs.
  238. */
  239. _connecting
  240. && <TintedView>
  241. <LoadingIndicator />
  242. </TintedView>
  243. }
  244. <View
  245. pointerEvents = 'box-none'
  246. style = { styles.toolboxAndFilmstripContainer }>
  247. <Captions onPress = { this._onClick } />
  248. <DisplayNameLabel />
  249. {/*
  250. * The Toolbox is in a stacking layer bellow the Filmstrip.
  251. */}
  252. <Toolbox />
  253. {/*
  254. * The Filmstrip is in a stacking layer above the
  255. * LargeVideo. The LargeVideo and the Filmstrip form what
  256. * the Web/React app calls "videospace". Presumably, the
  257. * name and grouping stem from the fact that these two
  258. * React Components depict the videos of the conference's
  259. * participants.
  260. */
  261. _shouldDisplayTileView ? undefined : <Filmstrip />
  262. }
  263. </View>
  264. <TestConnectionInfo />
  265. {
  266. this._renderConferenceNotification()
  267. }
  268. </Container>
  269. );
  270. }
  271. _onClick: () => void;
  272. /**
  273. * Changes the value of the toolboxVisible state, thus allowing us to switch
  274. * between Toolbox and Filmstrip and change their visibility.
  275. *
  276. * @private
  277. * @returns {void}
  278. */
  279. _onClick() {
  280. if (this.props._toolboxAlwaysVisible) {
  281. return;
  282. }
  283. const toolboxVisible = !this.props._toolboxVisible;
  284. this.props._setToolboxVisible(toolboxVisible);
  285. }
  286. /**
  287. * Renders the conference notification badge if the feature is enabled.
  288. *
  289. * @private
  290. * @returns {React$Node}
  291. */
  292. _renderConferenceNotification() {
  293. // XXX If the calendar feature is disabled on a platform, then we don't
  294. // have its components exported so an undefined check is necessary.
  295. return (
  296. !this.props._reducedUI && ConferenceNotification
  297. ? <ConferenceNotification />
  298. : undefined);
  299. }
  300. }
  301. /**
  302. * Maps dispatching of some action to React component props.
  303. *
  304. * @param {Function} dispatch - Redux action dispatcher.
  305. * @private
  306. * @returns {{
  307. * _onConnect: Function,
  308. * _onDisconnect: Function,
  309. * _onHardwareBackPress: Function,
  310. * _setToolboxVisible: Function
  311. * }}
  312. */
  313. function _mapDispatchToProps(dispatch) {
  314. return {
  315. /**
  316. * Dispatches actions to create the desired local tracks and for
  317. * connecting to the conference.
  318. *
  319. * @private
  320. * @returns {void}
  321. */
  322. _onConnect() {
  323. dispatch(createDesiredLocalTracks());
  324. dispatch(connect());
  325. },
  326. /**
  327. * Dispatches an action disconnecting from the conference.
  328. *
  329. * @private
  330. * @returns {void}
  331. */
  332. _onDisconnect() {
  333. dispatch(disconnect());
  334. },
  335. /**
  336. * Handles a hardware button press for back navigation. Leaves the
  337. * associated {@code Conference}.
  338. *
  339. * @returns {boolean} As the associated conference is unconditionally
  340. * left and exiting the app while it renders a {@code Conference} is
  341. * undesired, {@code true} is always returned.
  342. */
  343. _onHardwareBackPress() {
  344. dispatch(appNavigate(undefined));
  345. return true;
  346. },
  347. /**
  348. * Dispatches an action changing the visibility of the {@link Toolbox}.
  349. *
  350. * @private
  351. * @param {boolean} visible - Pass {@code true} to show the
  352. * {@code Toolbox} or {@code false} to hide it.
  353. * @returns {void}
  354. */
  355. _setToolboxVisible(visible) {
  356. dispatch(setToolboxVisible(visible));
  357. }
  358. };
  359. }
  360. /**
  361. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  362. *
  363. * @param {Object} state - The redux state.
  364. * @private
  365. * @returns {{
  366. * _connecting: boolean,
  367. * _filmstripVisible: boolean,
  368. * _locationURL: URL,
  369. * _participantCount: number,
  370. * _reducedUI: boolean,
  371. * _room: string,
  372. * _toolboxVisible: boolean,
  373. * _toolboxAlwaysVisible: boolean
  374. * }}
  375. */
  376. function _mapStateToProps(state) {
  377. const { connecting, connection, locationURL }
  378. = state['features/base/connection'];
  379. const {
  380. conference,
  381. joining,
  382. leaving,
  383. room
  384. } = state['features/base/conference'];
  385. const { reducedUI } = state['features/base/responsive-ui'];
  386. const { alwaysVisible, visible } = state['features/toolbox'];
  387. // XXX There is a window of time between the successful establishment of the
  388. // XMPP connection and the subsequent commencement of joining the MUC during
  389. // which the app does not appear to be doing anything according to the redux
  390. // state. In order to not toggle the _connecting props during the window of
  391. // time in question, define _connecting as follows:
  392. // - the XMPP connection is connecting, or
  393. // - the XMPP connection is connected and the conference is joining, or
  394. // - the XMPP connection is connected and we have no conference yet, nor we
  395. // are leaving one.
  396. const connecting_
  397. = connecting || (connection && (joining || (!conference && !leaving)));
  398. return {
  399. /**
  400. * The indicator which determines that we are still connecting to the
  401. * conference which includes establishing the XMPP connection and then
  402. * joining the room. If truthy, then an activity/loading indicator will
  403. * be rendered.
  404. *
  405. * @private
  406. * @type {boolean}
  407. */
  408. _connecting: Boolean(connecting_),
  409. /**
  410. * Is {@code true} when the filmstrip is currently visible.
  411. */
  412. _filmstripVisible: isFilmstripVisible(state),
  413. /**
  414. * Current conference's full URL.
  415. *
  416. * @private
  417. * @type {URL}
  418. */
  419. _locationURL: locationURL,
  420. /**
  421. * The number of participants in the conference.
  422. *
  423. * @private
  424. * @type {number}
  425. */
  426. _participantCount: getParticipantCount(state),
  427. /**
  428. * The indicator which determines whether the UI is reduced (to
  429. * accommodate smaller display areas).
  430. *
  431. * @private
  432. * @type {boolean}
  433. */
  434. _reducedUI: reducedUI,
  435. /**
  436. * The current conference room name.
  437. *
  438. * @private
  439. * @type {string}
  440. */
  441. _room: room,
  442. /**
  443. * Whether or not the layout should change to support tile view mode.
  444. *
  445. * @private
  446. * @type {boolean}
  447. */
  448. _shouldDisplayTileView: shouldDisplayTileView(state),
  449. /**
  450. * The indicator which determines whether the Toolbox is visible.
  451. *
  452. * @private
  453. * @type {boolean}
  454. */
  455. _toolboxVisible: visible,
  456. /**
  457. * The indicator which determines whether the Toolbox is always visible.
  458. *
  459. * @private
  460. * @type {boolean}
  461. */
  462. _toolboxAlwaysVisible: alwaysVisible
  463. };
  464. }
  465. // $FlowFixMe
  466. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  467. makeAspectRatioAware(Conference));