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.5KB

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