您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Conference.native.js 6.6KB

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