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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import React, { Component } from 'react';
  2. import { connect as reactReduxConnect } from 'react-redux';
  3. import { connect, disconnect } from '../../base/connection';
  4. import { DialogContainer } from '../../base/dialog';
  5. import { Container } from '../../base/react';
  6. import { Filmstrip } from '../../filmstrip';
  7. import { LargeVideo } from '../../large-video';
  8. import { setToolboxVisible, Toolbox } from '../../toolbox';
  9. import { styles } from './styles';
  10. /**
  11. * The timeout in milliseconds after which the Toolbox will be hidden.
  12. *
  13. * @private
  14. * @type {number}
  15. */
  16. const _TOOLBOX_TIMEOUT_MS = 5000;
  17. /**
  18. * The conference page of the mobile (i.e. React Native) application.
  19. */
  20. class Conference extends Component {
  21. /**
  22. * Conference component's property types.
  23. *
  24. * @static
  25. */
  26. static propTypes = {
  27. /**
  28. * The handler which dispatches the (redux) action connect.
  29. *
  30. * @private
  31. * @type {Function}
  32. */
  33. _onConnect: React.PropTypes.func,
  34. /**
  35. * The handler which dispatches the (redux) action disconnect.
  36. *
  37. * @private
  38. * @type {Function}
  39. */
  40. _onDisconnect: React.PropTypes.func,
  41. /**
  42. * The handler which dispatches the (redux) action setToolboxVisible to
  43. * show/hide the Toolbox.
  44. *
  45. * @private
  46. * @type {boolean}
  47. */
  48. _setToolboxVisible: React.PropTypes.func,
  49. /**
  50. * The indicator which determines whether the Toolbox is visible.
  51. *
  52. * @private
  53. * @type {boolean}
  54. */
  55. _toolboxVisible: React.PropTypes.bool
  56. };
  57. /**
  58. * Initializes a new Conference instance.
  59. *
  60. * @param {Object} props - The read-only properties with which the new
  61. * instance is to be initialized.
  62. */
  63. constructor(props) {
  64. super(props);
  65. /**
  66. * The numerical ID of the timeout in milliseconds after which the
  67. * Toolbox will be hidden. To be used with
  68. * {@link WindowTimers#clearTimeout()}.
  69. *
  70. * @private
  71. */
  72. this._toolboxTimeout = undefined;
  73. // Bind event handlers so they are only bound once for every instance.
  74. this._onClick = this._onClick.bind(this);
  75. }
  76. /**
  77. * Inits the Toolbox timeout after the component is initially rendered.
  78. *
  79. * @inheritdoc
  80. * returns {void}
  81. */
  82. componentDidMount() {
  83. this._setToolboxTimeout(this.props._toolboxVisible);
  84. }
  85. /**
  86. * Inits new connection and conference when conference screen is entered.
  87. *
  88. * @inheritdoc
  89. * @returns {void}
  90. */
  91. componentWillMount() {
  92. this.props._onConnect();
  93. }
  94. /**
  95. * Destroys connection, conference and local tracks when conference screen
  96. * is left. Clears {@link #_toolboxTimeout} before the component unmounts.
  97. *
  98. * @inheritdoc
  99. * @returns {void}
  100. */
  101. componentWillUnmount() {
  102. this._clearToolboxTimeout();
  103. this.props._onDisconnect();
  104. }
  105. /**
  106. * Implements React's {@link Component#render()}.
  107. *
  108. * @inheritdoc
  109. * @returns {ReactElement}
  110. */
  111. render() {
  112. return (
  113. <Container
  114. onClick = { this._onClick }
  115. style = { styles.conference }
  116. touchFeedback = { false }>
  117. <LargeVideo />
  118. <Toolbox />
  119. <Filmstrip />
  120. <DialogContainer />
  121. </Container>
  122. );
  123. }
  124. /**
  125. * Clears {@link #_toolboxTimeout} if any.
  126. *
  127. * @private
  128. * @returns {void}
  129. */
  130. _clearToolboxTimeout() {
  131. if (this._toolboxTimeout) {
  132. clearTimeout(this._toolboxTimeout);
  133. this._toolboxTimeout = undefined;
  134. }
  135. }
  136. /**
  137. * Changes the value of the toolboxVisible state, thus allowing us to switch
  138. * between Toolbox and Filmstrip and change their visibility.
  139. *
  140. * @private
  141. * @returns {void}
  142. */
  143. _onClick() {
  144. const toolboxVisible = !this.props._toolboxVisible;
  145. this.props._setToolboxVisible(toolboxVisible);
  146. this._setToolboxTimeout(toolboxVisible);
  147. }
  148. /**
  149. * Triggers the default Toolbox timeout.
  150. *
  151. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  152. * currently visible.
  153. * @private
  154. * @returns {void}
  155. */
  156. _setToolboxTimeout(toolboxVisible) {
  157. this._clearToolboxTimeout();
  158. if (toolboxVisible) {
  159. this._toolboxTimeout
  160. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  161. }
  162. }
  163. }
  164. /**
  165. * Maps dispatching of some action to React component props.
  166. *
  167. * @param {Function} dispatch - Redux action dispatcher.
  168. * @private
  169. * @returns {{
  170. * _onConnect: Function,
  171. * _onDisconnect: Function,
  172. * _setToolboxVisible: Function
  173. * }}
  174. */
  175. function _mapDispatchToProps(dispatch) {
  176. return {
  177. /**
  178. * Dispatched an action connecting to the conference.
  179. *
  180. * @returns {Object} Dispatched action.
  181. * @private
  182. */
  183. _onConnect() {
  184. return dispatch(connect());
  185. },
  186. /**
  187. * Dispatches an action disconnecting from the conference.
  188. *
  189. * @returns {Object} Dispatched action.
  190. * @private
  191. */
  192. _onDisconnect() {
  193. return dispatch(disconnect());
  194. },
  195. /**
  196. * Dispatches an action changing the visiblity of the Toolbox.
  197. *
  198. * @param {boolean} visible - True to show the Toolbox or false to hide
  199. * it.
  200. * @returns {Object} Dispatched action.
  201. * @private
  202. */
  203. _setToolboxVisible(visible: boolean) {
  204. return dispatch(setToolboxVisible(visible));
  205. }
  206. };
  207. }
  208. /**
  209. * Maps (parts of) the Redux state to the associated Conference's props.
  210. *
  211. * @param {Object} state - The Redux state.
  212. * @private
  213. * @returns {{
  214. * _toolboxVisible: boolean
  215. * }}
  216. */
  217. function _mapStateToProps(state) {
  218. return {
  219. /**
  220. * The indicator which determines whether the Toolbox is visible.
  221. *
  222. * @private
  223. * @type {boolean}
  224. */
  225. _toolboxVisible: state['features/toolbox'].visible
  226. };
  227. }
  228. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  229. Conference);