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

Conference.native.js 15KB

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