選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Conference.native.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. // @flow
  2. import React, { Component } from 'react';
  3. // eslint-disable-next-line react-native/split-platform-components
  4. import { BackAndroid, BackHandler, StatusBar, View } from 'react-native';
  5. import { connect as reactReduxConnect } from 'react-redux';
  6. import { appNavigate } from '../../app';
  7. import { connect, disconnect } from '../../base/connection';
  8. import { DialogContainer } from '../../base/dialog';
  9. import { CalleeInfoContainer } from '../../base/jwt';
  10. import { Container, LoadingIndicator, TintedView } from '../../base/react';
  11. import { createDesiredLocalTracks } from '../../base/tracks';
  12. import { ConferenceNotification } from '../../calendar-sync';
  13. import { Filmstrip } from '../../filmstrip';
  14. import { LargeVideo } from '../../large-video';
  15. import { setToolboxVisible, Toolbox } from '../../toolbox';
  16. import styles from './styles';
  17. /**
  18. * The timeout in milliseconds after which the Toolbox will be hidden.
  19. *
  20. * @private
  21. * @type {number}
  22. */
  23. const _TOOLBOX_TIMEOUT_MS = 5000;
  24. /**
  25. * The type of the React {@code Component} props of {@link Conference}.
  26. */
  27. type Props = {
  28. /**
  29. * The indicator which determines that we are still connecting to the
  30. * conference which includes establishing the XMPP connection and then
  31. * joining the room. If truthy, then an activity/loading indicator will
  32. * be rendered.
  33. *
  34. * @private
  35. */
  36. _connecting: boolean,
  37. /**
  38. * The handler which dispatches the (redux) action connect.
  39. *
  40. * @private
  41. */
  42. _onConnect: Function,
  43. /**
  44. * The handler which dispatches the (redux) action disconnect.
  45. *
  46. * @private
  47. */
  48. _onDisconnect: Function,
  49. /**
  50. * Handles a hardware button press for back navigation. Leaves the
  51. * associated {@code Conference}.
  52. *
  53. * @private
  54. * @returns {boolean} As the associated conference is unconditionally
  55. * left and exiting the app while it renders a {@code Conference} is
  56. * undesired, {@code true} is always returned.
  57. */
  58. _onHardwareBackPress: Function,
  59. /**
  60. * The indicator which determines whether the UI is reduced (to accommodate
  61. * smaller display areas).
  62. *
  63. * @private
  64. */
  65. _reducedUI: boolean,
  66. /**
  67. * The handler which dispatches the (redux) action setToolboxVisible to
  68. * show/hide the Toolbox.
  69. *
  70. * @private
  71. */
  72. _setToolboxVisible: Function,
  73. /**
  74. * The indicator which determines whether the Toolbox is visible.
  75. *
  76. * @private
  77. */
  78. _toolboxVisible: boolean
  79. };
  80. /**
  81. * The conference page of the mobile (i.e. React Native) application.
  82. */
  83. class Conference extends Component<Props> {
  84. _backHandler: ?BackHandler;
  85. _toolboxTimeout: ?number;
  86. /**
  87. * Initializes a new Conference instance.
  88. *
  89. * @param {Object} props - The read-only properties with which the new
  90. * instance is to be initialized.
  91. */
  92. constructor(props) {
  93. super(props);
  94. /**
  95. * The numerical ID of the timeout in milliseconds after which the
  96. * Toolbox will be hidden. To be used with
  97. * {@link WindowTimers#clearTimeout()}.
  98. *
  99. * @private
  100. */
  101. this._toolboxTimeout = undefined;
  102. // Bind event handlers so they are only bound once per instance.
  103. this._onClick = this._onClick.bind(this);
  104. this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
  105. }
  106. /**
  107. * Implements {@link Component#componentDidMount()}. Invoked immediately
  108. * after this component is mounted.
  109. *
  110. * @inheritdoc
  111. * @returns {void}
  112. */
  113. componentDidMount() {
  114. // Set handling any hardware button presses for back navigation up.
  115. const backHandler = BackHandler || BackAndroid;
  116. if (backHandler) {
  117. this._backHandler = backHandler;
  118. backHandler.addEventListener(
  119. 'hardwareBackPress',
  120. this._onHardwareBackPress);
  121. }
  122. this._setToolboxTimeout(this.props._toolboxVisible);
  123. }
  124. /**
  125. * Implements {@link Component#componentWillMount()}. Invoked immediately
  126. * before mounting occurs. Connects the conference described by the redux
  127. * store/state.
  128. *
  129. * @inheritdoc
  130. * @returns {void}
  131. */
  132. componentWillMount() {
  133. this.props._onConnect();
  134. }
  135. /**
  136. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  137. * before this component is unmounted and destroyed. Disconnects the
  138. * conference described by the redux store/state.
  139. *
  140. * @inheritdoc
  141. * @returns {void}
  142. */
  143. componentWillUnmount() {
  144. // Tear handling any hardware button presses for back navigation down.
  145. const backHandler = this._backHandler;
  146. if (backHandler) {
  147. this._backHandler = undefined;
  148. backHandler.removeEventListener(
  149. 'hardwareBackPress',
  150. this._onHardwareBackPress);
  151. }
  152. this._clearToolboxTimeout();
  153. this.props._onDisconnect();
  154. }
  155. /**
  156. * Implements React's {@link Component#render()}.
  157. *
  158. * @inheritdoc
  159. * @returns {ReactElement}
  160. */
  161. render() {
  162. return (
  163. <Container
  164. accessibilityLabel = 'Conference'
  165. accessible = { false }
  166. onClick = { this._onClick }
  167. style = { styles.conference }
  168. touchFeedback = { false }>
  169. <StatusBar
  170. hidden = { true }
  171. translucent = { true } />
  172. {/*
  173. * The LargeVideo is the lowermost stacking layer.
  174. */}
  175. <LargeVideo />
  176. {/*
  177. * If there is a ringing call, show the callee's info.
  178. */
  179. this.props._reducedUI || <CalleeInfoContainer />
  180. }
  181. {/*
  182. * The activity/loading indicator goes above everything, except
  183. * the toolbox/toolbars and the dialogs.
  184. */
  185. this.props._connecting
  186. && <TintedView>
  187. <LoadingIndicator />
  188. </TintedView>
  189. }
  190. <View style = { styles.toolboxAndFilmstripContainer } >
  191. {/*
  192. * The Toolbox is in a stacking layer bellow the Filmstrip.
  193. */}
  194. <Toolbox />
  195. {/*
  196. * The Filmstrip is in a stacking layer above the
  197. * LargeVideo. The LargeVideo and the Filmstrip form what
  198. * the Web/React app calls "videospace". Presumably, the
  199. * name and grouping stem from the fact that these two
  200. * React Components depict the videos of the conference's
  201. * participants.
  202. */}
  203. <Filmstrip />
  204. </View>
  205. <ConferenceNotification />
  206. {/*
  207. * The dialogs are in the topmost stacking layers.
  208. */
  209. this.props._reducedUI || <DialogContainer />
  210. }
  211. </Container>
  212. );
  213. }
  214. /**
  215. * Clears {@link #_toolboxTimeout} if any.
  216. *
  217. * @private
  218. * @returns {void}
  219. */
  220. _clearToolboxTimeout() {
  221. if (this._toolboxTimeout) {
  222. clearTimeout(this._toolboxTimeout);
  223. this._toolboxTimeout = undefined;
  224. }
  225. }
  226. _onClick: () => void;
  227. /**
  228. * Changes the value of the toolboxVisible state, thus allowing us to switch
  229. * between Toolbox and Filmstrip and change their visibility.
  230. *
  231. * @private
  232. * @returns {void}
  233. */
  234. _onClick() {
  235. const toolboxVisible = !this.props._toolboxVisible;
  236. this.props._setToolboxVisible(toolboxVisible);
  237. // XXX If the user taps to toggle the visibility of the Toolbox, then no
  238. // automatic toggling of the visibility should happen.
  239. this._clearToolboxTimeout();
  240. }
  241. _onHardwareBackPress: () => boolean;
  242. /**
  243. * Handles a hardware button press for back navigation.
  244. *
  245. * @returns {boolean} If the hardware button press for back navigation was
  246. * handled by this {@code Conference}, then {@code true}; otherwise,
  247. * {@code false}.
  248. */
  249. _onHardwareBackPress() {
  250. return this._backHandler && this.props._onHardwareBackPress();
  251. }
  252. /**
  253. * Triggers the default Toolbox timeout.
  254. *
  255. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  256. * currently visible.
  257. * @private
  258. * @returns {void}
  259. */
  260. _setToolboxTimeout(toolboxVisible) {
  261. this._clearToolboxTimeout();
  262. if (toolboxVisible) {
  263. this._toolboxTimeout
  264. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  265. }
  266. }
  267. }
  268. /**
  269. * Maps dispatching of some action to React component props.
  270. *
  271. * @param {Function} dispatch - Redux action dispatcher.
  272. * @private
  273. * @returns {{
  274. * _onConnect: Function,
  275. * _onDisconnect: Function,
  276. * _setToolboxVisible: Function
  277. * }}
  278. */
  279. function _mapDispatchToProps(dispatch) {
  280. return {
  281. /**
  282. * Dispatches actions to create the desired local tracks and for
  283. * connecting to the conference.
  284. *
  285. * @returns {void}
  286. * @private
  287. */
  288. _onConnect() {
  289. dispatch(createDesiredLocalTracks());
  290. dispatch(connect());
  291. },
  292. /**
  293. * Dispatches an action disconnecting from the conference.
  294. *
  295. * @returns {void}
  296. * @private
  297. */
  298. _onDisconnect() {
  299. dispatch(disconnect());
  300. },
  301. /**
  302. * Handles a hardware button press for back navigation. Leaves the
  303. * associated {@code Conference}.
  304. *
  305. * @returns {boolean} As the associated conference is unconditionally
  306. * left and exiting the app while it renders a {@code Conference} is
  307. * undesired, {@code true} is always returned.
  308. */
  309. _onHardwareBackPress() {
  310. dispatch(appNavigate(undefined));
  311. return true;
  312. },
  313. /**
  314. * Dispatches an action changing the visibility of the Toolbox.
  315. *
  316. * @param {boolean} visible - True to show the Toolbox or false to hide
  317. * it.
  318. * @returns {void}
  319. * @private
  320. */
  321. _setToolboxVisible(visible) {
  322. dispatch(setToolboxVisible(visible));
  323. }
  324. };
  325. }
  326. /**
  327. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  328. *
  329. * @param {Object} state - The redux state.
  330. * @private
  331. * @returns {{
  332. * _connecting: boolean,
  333. * _reducedUI: boolean,
  334. * _toolboxVisible: boolean
  335. * }}
  336. */
  337. function _mapStateToProps(state) {
  338. const { connecting, connection } = state['features/base/connection'];
  339. const { conference, joining, leaving } = state['features/base/conference'];
  340. const { reducedUI } = state['features/base/responsive-ui'];
  341. // XXX There is a window of time between the successful establishment of the
  342. // XMPP connection and the subsequent commencement of joining the MUC during
  343. // which the app does not appear to be doing anything according to the redux
  344. // state. In order to not toggle the _connecting props during the window of
  345. // time in question, define _connecting as follows:
  346. // - the XMPP connection is connecting, or
  347. // - the XMPP connection is connected and the conference is joining, or
  348. // - the XMPP connection is connected and we have no conference yet, nor we
  349. // are leaving one.
  350. const connecting_
  351. = connecting || (connection && (joining || (!conference && !leaving)));
  352. return {
  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. * The indicator which determines whether the UI is reduced (to
  365. * accommodate smaller display areas).
  366. *
  367. * @private
  368. * @type {boolean}
  369. */
  370. _reducedUI: reducedUI,
  371. /**
  372. * The indicator which determines whether the Toolbox is visible.
  373. *
  374. * @private
  375. * @type {boolean}
  376. */
  377. _toolboxVisible: state['features/toolbox'].visible
  378. };
  379. }
  380. // $FlowFixMe
  381. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  382. Conference);