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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 '../../film-strip';
  7. import { LargeVideo } from '../../large-video';
  8. import { setToolbarVisible, Toolbar } from '../../toolbar';
  9. import { styles } from './styles';
  10. /**
  11. * The timeout in milliseconds after which the toolbar will be hidden.
  12. *
  13. * @private
  14. * @type {number}
  15. */
  16. const _TOOLBAR_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 setTooblarVisible to
  43. * show/hide the toolbar.
  44. *
  45. * @private
  46. * @type {boolean}
  47. */
  48. _setToolbarVisible: React.PropTypes.func,
  49. /**
  50. * The indicator which determines whether toolbar is visible.
  51. *
  52. * @private
  53. * @type {boolean}
  54. */
  55. _toolbarVisible: 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. * toolbar will be hidden. To be used with
  68. * {@link WindowTimers#clearTimeout()}.
  69. *
  70. * @private
  71. */
  72. this._toolbarTimeout = 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 toolbar timeout after the component is initially rendered.
  78. *
  79. * @inheritdoc
  80. * returns {void}
  81. */
  82. componentDidMount() {
  83. this._setToolbarTimeout(this.props._toolbarVisible);
  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 #_toolbarTimeout} before the component unmounts.
  97. *
  98. * @inheritdoc
  99. * @returns {void}
  100. */
  101. componentWillUnmount() {
  102. this._clearToolbarTimeout();
  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. <Toolbar />
  119. <FilmStrip />
  120. <DialogContainer />
  121. </Container>
  122. );
  123. }
  124. /**
  125. * Clears {@link #_toolbarTimeout} if any.
  126. *
  127. * @private
  128. * @returns {void}
  129. */
  130. _clearToolbarTimeout() {
  131. if (this._toolbarTimeout) {
  132. clearTimeout(this._toolbarTimeout);
  133. this._toolbarTimeout = undefined;
  134. }
  135. }
  136. /**
  137. * Changes the value of the toolbarVisible state, thus allowing us to
  138. * 'switch' between toolbar and filmstrip views and change the visibility of
  139. * the above.
  140. *
  141. * @private
  142. * @returns {void}
  143. */
  144. _onClick() {
  145. const toolbarVisible = !this.props._toolbarVisible;
  146. this.props._setToolbarVisible(toolbarVisible);
  147. this._setToolbarTimeout(toolbarVisible);
  148. }
  149. /**
  150. * Triggers the default toolbar timeout.
  151. *
  152. * @param {boolean} toolbarVisible - Indicates if the toolbar is currently
  153. * visible.
  154. * @private
  155. * @returns {void}
  156. */
  157. _setToolbarTimeout(toolbarVisible) {
  158. this._clearToolbarTimeout();
  159. if (toolbarVisible) {
  160. this._toolbarTimeout
  161. = setTimeout(this._onClick, _TOOLBAR_TIMEOUT_MS);
  162. }
  163. }
  164. }
  165. /**
  166. * Maps dispatching of some action to React component props.
  167. *
  168. * @param {Function} dispatch - Redux action dispatcher.
  169. * @private
  170. * @returns {{
  171. * _onConnect: Function,
  172. * _onDisconnect: Function,
  173. * _setToolbarVisible: Function
  174. * }}
  175. */
  176. function _mapDispatchToProps(dispatch) {
  177. return {
  178. /**
  179. * Dispatched an action connecting to the conference.
  180. *
  181. * @returns {Object} Dispatched action.
  182. * @private
  183. */
  184. _onConnect() {
  185. return dispatch(connect());
  186. },
  187. /**
  188. * Dispatches an action disconnecting from the conference.
  189. *
  190. * @returns {Object} Dispatched action.
  191. * @private
  192. */
  193. _onDisconnect() {
  194. return dispatch(disconnect());
  195. },
  196. /**
  197. * Dispatched an action changing visiblity of the toolbar.
  198. *
  199. * @param {boolean} isVisible - Flag showing whether toolbar is
  200. * visible.
  201. * @returns {Object} Dispatched action.
  202. * @private
  203. */
  204. _setToolbarVisible(isVisible: boolean) {
  205. return dispatch(setToolbarVisible(isVisible));
  206. }
  207. };
  208. }
  209. /**
  210. * Maps (parts of) the Redux state to the associated Conference's props.
  211. *
  212. * @param {Object} state - The Redux state.
  213. * @private
  214. * @returns {{
  215. * _toolbarVisible: boolean
  216. * }}
  217. */
  218. function _mapStateToProps(state) {
  219. return {
  220. /**
  221. * The indicator which determines whether toolbar is visible.
  222. *
  223. * @private
  224. * @type {boolean}
  225. */
  226. _toolbarVisible: state['features/toolbar'].visible
  227. };
  228. }
  229. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  230. Conference);