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

Conference.native.js 15KB

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