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

Conference.native.js 6.7KB

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