You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Conference.native.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { connect as reactReduxConnect } from 'react-redux';
  5. import { connect, disconnect } from '../../base/connection';
  6. import { DialogContainer } from '../../base/dialog';
  7. import { Container, LoadingIndicator } from '../../base/react';
  8. import { createDesiredLocalTracks } from '../../base/tracks';
  9. import { Filmstrip } from '../../filmstrip';
  10. import { LargeVideo } from '../../large-video';
  11. import { OverlayContainer } from '../../overlay';
  12. import { setToolboxVisible, Toolbox } from '../../toolbox';
  13. import styles from './styles';
  14. /**
  15. * The timeout in milliseconds after which the Toolbox will be hidden.
  16. *
  17. * @private
  18. * @type {number}
  19. */
  20. const _TOOLBOX_TIMEOUT_MS = 5000;
  21. /**
  22. * The conference page of the mobile (i.e. React Native) application.
  23. */
  24. class Conference extends Component {
  25. /**
  26. * Conference component's property types.
  27. *
  28. * @static
  29. */
  30. static propTypes = {
  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
  35. * be rendered.
  36. *
  37. * @private
  38. */
  39. _connecting: PropTypes.bool,
  40. /**
  41. * The handler which dispatches the (redux) action connect.
  42. *
  43. * @private
  44. */
  45. _onConnect: PropTypes.func,
  46. /**
  47. * The handler which dispatches the (redux) action disconnect.
  48. *
  49. * @private
  50. */
  51. _onDisconnect: PropTypes.func,
  52. /**
  53. * The handler which dispatches the (redux) action setToolboxVisible to
  54. * show/hide the Toolbox.
  55. *
  56. * @private
  57. */
  58. _setToolboxVisible: PropTypes.func,
  59. /**
  60. * The indicator which determines whether the Toolbox is visible.
  61. *
  62. * @private
  63. */
  64. _toolboxVisible: PropTypes.bool
  65. };
  66. /**
  67. * Initializes a new Conference instance.
  68. *
  69. * @param {Object} props - The read-only properties with which the new
  70. * instance is to be initialized.
  71. */
  72. constructor(props) {
  73. super(props);
  74. /**
  75. * The numerical ID of the timeout in milliseconds after which the
  76. * Toolbox will be hidden. To be used with
  77. * {@link WindowTimers#clearTimeout()}.
  78. *
  79. * @private
  80. */
  81. this._toolboxTimeout = undefined;
  82. // Bind event handlers so they are only bound once for every instance.
  83. this._onClick = this._onClick.bind(this);
  84. }
  85. /**
  86. * Inits the Toolbox timeout after the component is initially rendered.
  87. *
  88. * @inheritdoc
  89. * returns {void}
  90. */
  91. componentDidMount() {
  92. this._setToolboxTimeout(this.props._toolboxVisible);
  93. }
  94. /**
  95. * Inits new connection and conference when conference screen is entered.
  96. *
  97. * @inheritdoc
  98. * @returns {void}
  99. */
  100. componentWillMount() {
  101. this.props._onConnect();
  102. }
  103. /**
  104. * Destroys connection, conference and local tracks when conference screen
  105. * is left. Clears {@link #_toolboxTimeout} before the component unmounts.
  106. *
  107. * @inheritdoc
  108. * @returns {void}
  109. */
  110. componentWillUnmount() {
  111. this._clearToolboxTimeout();
  112. this.props._onDisconnect();
  113. }
  114. /**
  115. * Implements React's {@link Component#render()}.
  116. *
  117. * @inheritdoc
  118. * @returns {ReactElement}
  119. */
  120. render() {
  121. return (
  122. <Container
  123. onClick = { this._onClick }
  124. style = { styles.conference }
  125. touchFeedback = { false }>
  126. {/*
  127. * The LargeVideo is the lowermost stacking layer.
  128. */}
  129. <LargeVideo />
  130. {/*
  131. * The Filmstrip is in a stacking layer above the LargeVideo.
  132. * The LargeVideo and the Filmstrip form what the Web/React app
  133. * calls "videospace". Presumably, the name and grouping stem
  134. * from the fact that these two React Components depict the
  135. * videos of the conference's participants.
  136. */}
  137. <Filmstrip />
  138. {/*
  139. * The overlays need to be bellow the Toolbox so that the user
  140. * may tap the ToolbarButtons.
  141. */}
  142. <OverlayContainer />
  143. {/*
  144. * The activity/loading indicator goes above everything, except
  145. * the toolbox/toolbars and the dialogs.
  146. */
  147. this.props._connecting
  148. && <View style = { styles.connectingIndicator }>
  149. <LoadingIndicator />
  150. </View>
  151. }
  152. {/*
  153. * The Toolbox is in a stacking layer above the Filmstrip.
  154. */}
  155. <Toolbox />
  156. {/*
  157. * The dialogs are in the topmost stacking layers.
  158. */}
  159. <DialogContainer />
  160. </Container>
  161. );
  162. }
  163. /**
  164. * Clears {@link #_toolboxTimeout} if any.
  165. *
  166. * @private
  167. * @returns {void}
  168. */
  169. _clearToolboxTimeout() {
  170. if (this._toolboxTimeout) {
  171. clearTimeout(this._toolboxTimeout);
  172. this._toolboxTimeout = undefined;
  173. }
  174. }
  175. /**
  176. * Changes the value of the toolboxVisible state, thus allowing us to switch
  177. * between Toolbox and Filmstrip and change their visibility.
  178. *
  179. * @private
  180. * @returns {void}
  181. */
  182. _onClick() {
  183. const toolboxVisible = !this.props._toolboxVisible;
  184. this.props._setToolboxVisible(toolboxVisible);
  185. this._setToolboxTimeout(toolboxVisible);
  186. }
  187. /**
  188. * Triggers the default Toolbox timeout.
  189. *
  190. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  191. * currently visible.
  192. * @private
  193. * @returns {void}
  194. */
  195. _setToolboxTimeout(toolboxVisible) {
  196. this._clearToolboxTimeout();
  197. if (toolboxVisible) {
  198. this._toolboxTimeout
  199. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  200. }
  201. }
  202. }
  203. /**
  204. * Maps dispatching of some action to React component props.
  205. *
  206. * @param {Function} dispatch - Redux action dispatcher.
  207. * @private
  208. * @returns {{
  209. * _onConnect: Function,
  210. * _onDisconnect: Function,
  211. * _setToolboxVisible: Function
  212. * }}
  213. */
  214. function _mapDispatchToProps(dispatch) {
  215. return {
  216. /**
  217. * Dispatches actions to create the desired local tracks and for
  218. * connecting to the conference.
  219. *
  220. * @returns {void}
  221. * @private
  222. */
  223. _onConnect() {
  224. dispatch(createDesiredLocalTracks());
  225. dispatch(connect());
  226. },
  227. /**
  228. * Dispatches an action disconnecting from the conference.
  229. *
  230. * @returns {void}
  231. * @private
  232. */
  233. _onDisconnect() {
  234. dispatch(disconnect());
  235. },
  236. /**
  237. * Dispatches an action changing the visiblity of the Toolbox.
  238. *
  239. * @param {boolean} visible - True to show the Toolbox or false to hide
  240. * it.
  241. * @returns {void}
  242. * @private
  243. */
  244. _setToolboxVisible(visible: boolean) {
  245. dispatch(setToolboxVisible(visible));
  246. }
  247. };
  248. }
  249. /**
  250. * Maps (parts of) the Redux state to the associated Conference's props.
  251. *
  252. * @param {Object} state - The Redux state.
  253. * @private
  254. * @returns {{
  255. * _connecting: boolean,
  256. * _toolboxVisible: boolean
  257. * }}
  258. */
  259. function _mapStateToProps(state) {
  260. const { connecting, connection } = state['features/base/connection'];
  261. const { conference, joining, leaving } = state['features/base/conference'];
  262. // XXX There is a window of time between the successful establishment of the
  263. // XMPP connection and the subsequent commencement of joining the MUC during
  264. // which the app does not appear to be doing anything according to the redux
  265. // state. In order to not toggle the _connecting props during the window of
  266. // time in question, define _connecting as follows:
  267. // - the XMPP connection is connecting, or
  268. // - the XMPP connection is connected and the conference is joining, or
  269. // - the XMPP connection is connected and we have no conference yet, nor we
  270. // are leaving one.
  271. const connecting_
  272. = connecting || (connection && (joining || (!conference && !leaving)));
  273. return {
  274. /**
  275. * The indicator which determines that we are still connecting to the
  276. * conference which includes establishing the XMPP connection and then
  277. * joining the room. If truthy, then an activity/loading indicator will
  278. * be rendered.
  279. *
  280. * @private
  281. * @type {boolean}
  282. */
  283. _connecting: Boolean(connecting_),
  284. /**
  285. * The indicator which determines whether the Toolbox is visible.
  286. *
  287. * @private
  288. * @type {boolean}
  289. */
  290. _toolboxVisible: state['features/toolbox'].visible
  291. };
  292. }
  293. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  294. Conference);