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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 { 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. dispatch: React.PropTypes.func
  28. }
  29. /**
  30. * Initializes a new Conference instance.
  31. *
  32. * @param {Object} props - The read-only properties with which the new
  33. * instance is to be initialized.
  34. */
  35. constructor(props) {
  36. super(props);
  37. this.state = { toolbarVisible: true };
  38. /**
  39. * The numerical ID of the timeout in milliseconds after which the
  40. * toolbar will be hidden. To be used with
  41. * {@link WindowTimers#clearTimeout()}.
  42. *
  43. * @private
  44. */
  45. this._toolbarTimeout = undefined;
  46. // Bind event handlers so they are only bound once for every instance.
  47. this._onClick = this._onClick.bind(this);
  48. }
  49. /**
  50. * Inits the toolbar timeout after the component is initially rendered.
  51. *
  52. * @inheritdoc
  53. * returns {void}
  54. */
  55. componentDidMount() {
  56. this._setToolbarTimeout(this.state.toolbarVisible);
  57. }
  58. /**
  59. * Inits new connection and conference when conference screen is entered.
  60. *
  61. * @inheritdoc
  62. * @returns {void}
  63. */
  64. componentWillMount() {
  65. this.props.dispatch(connect());
  66. }
  67. /**
  68. * Destroys connection, conference and local tracks when conference screen
  69. * is left. Clears {@link #_toolbarTimeout} before the component unmounts.
  70. *
  71. * @inheritdoc
  72. * @returns {void}
  73. */
  74. componentWillUnmount() {
  75. this._clearToolbarTimeout();
  76. this.props.dispatch(disconnect());
  77. }
  78. /**
  79. * Implements React's {@link Component#render()}.
  80. *
  81. * @inheritdoc
  82. * @returns {ReactElement}
  83. */
  84. render() {
  85. const toolbarVisible = this.state.toolbarVisible;
  86. return (
  87. <Container
  88. onClick = { this._onClick }
  89. style = { styles.conference }
  90. touchFeedback = { false }>
  91. <LargeVideo />
  92. <Toolbar visible = { toolbarVisible } />
  93. <FilmStrip visible = { !toolbarVisible } />
  94. <DialogContainer />
  95. </Container>
  96. );
  97. }
  98. /**
  99. * Clears {@link #_toolbarTimeout} if any.
  100. *
  101. * @private
  102. * @returns {void}
  103. */
  104. _clearToolbarTimeout() {
  105. if (this._toolbarTimeout) {
  106. clearTimeout(this._toolbarTimeout);
  107. this._toolbarTimeout = undefined;
  108. }
  109. }
  110. /**
  111. * Changes the value of the toolbarVisible state, thus allowing us to
  112. * 'switch' between toolbar and filmstrip views and change the visibility of
  113. * the above.
  114. *
  115. * @private
  116. * @returns {void}
  117. */
  118. _onClick() {
  119. const toolbarVisible = !this.state.toolbarVisible;
  120. this.setState({ toolbarVisible });
  121. this._setToolbarTimeout(toolbarVisible);
  122. }
  123. /**
  124. * Triggers the default toolbar timeout.
  125. *
  126. * @param {boolean} toolbarVisible - Indicates if the toolbar is currently
  127. * visible.
  128. * @private
  129. * @returns {void}
  130. */
  131. _setToolbarTimeout(toolbarVisible) {
  132. this._clearToolbarTimeout();
  133. if (toolbarVisible) {
  134. this._toolbarTimeout
  135. = setTimeout(this._onClick, _TOOLBAR_TIMEOUT_MS);
  136. }
  137. }
  138. }
  139. export default reactReduxConnect()(Conference);