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

Conference.native.js 12KB

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