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

Conference.native.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 '../../filmstrip';
  7. import { LargeVideo } from '../../large-video';
  8. import { OverlayContainer } from '../../overlay';
  9. import { setToolboxVisible, Toolbox } from '../../toolbox';
  10. import { styles } from './styles';
  11. /**
  12. * The timeout in milliseconds after which the Toolbox will be hidden.
  13. *
  14. * @private
  15. * @type {number}
  16. */
  17. const _TOOLBOX_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 handler which dispatches the (redux) action connect.
  30. *
  31. * @private
  32. * @type {Function}
  33. */
  34. _onConnect: React.PropTypes.func,
  35. /**
  36. * The handler which dispatches the (redux) action disconnect.
  37. *
  38. * @private
  39. * @type {Function}
  40. */
  41. _onDisconnect: React.PropTypes.func,
  42. /**
  43. * The handler which dispatches the (redux) action setToolboxVisible to
  44. * show/hide the Toolbox.
  45. *
  46. * @private
  47. * @type {boolean}
  48. */
  49. _setToolboxVisible: React.PropTypes.func,
  50. /**
  51. * The indicator which determines whether the Toolbox is visible.
  52. *
  53. * @private
  54. * @type {boolean}
  55. */
  56. _toolboxVisible: React.PropTypes.bool
  57. };
  58. /**
  59. * Initializes a new Conference instance.
  60. *
  61. * @param {Object} props - The read-only properties with which the new
  62. * instance is to be initialized.
  63. */
  64. constructor(props) {
  65. super(props);
  66. /**
  67. * The numerical ID of the timeout in milliseconds after which the
  68. * Toolbox will be hidden. To be used with
  69. * {@link WindowTimers#clearTimeout()}.
  70. *
  71. * @private
  72. */
  73. this._toolboxTimeout = undefined;
  74. // Bind event handlers so they are only bound once for every instance.
  75. this._onClick = this._onClick.bind(this);
  76. }
  77. /**
  78. * Inits the Toolbox timeout after the component is initially rendered.
  79. *
  80. * @inheritdoc
  81. * returns {void}
  82. */
  83. componentDidMount() {
  84. this._setToolboxTimeout(this.props._toolboxVisible);
  85. }
  86. /**
  87. * Inits new connection and conference when conference screen is entered.
  88. *
  89. * @inheritdoc
  90. * @returns {void}
  91. */
  92. componentWillMount() {
  93. this.props._onConnect();
  94. }
  95. /**
  96. * Destroys connection, conference and local tracks when conference screen
  97. * is left. Clears {@link #_toolboxTimeout} before the component unmounts.
  98. *
  99. * @inheritdoc
  100. * @returns {void}
  101. */
  102. componentWillUnmount() {
  103. this._clearToolboxTimeout();
  104. this.props._onDisconnect();
  105. }
  106. /**
  107. * Implements React's {@link Component#render()}.
  108. *
  109. * @inheritdoc
  110. * @returns {ReactElement}
  111. */
  112. render() {
  113. return (
  114. <Container
  115. onClick = { this._onClick }
  116. style = { styles.conference }
  117. touchFeedback = { false }>
  118. {/*
  119. * The LargeVideo is the lowermost stacking layer.
  120. */}
  121. <LargeVideo />
  122. {/*
  123. * The Filmstrip is in a stacking layer above the LargeVideo.
  124. * The LargeVideo and the Filmstrip form what the Web/React app
  125. * calls "videospace". Presumably, the name and grouping stem
  126. * from the fact that these two React Components depict the
  127. * videos of the conference's participants.
  128. */}
  129. <Filmstrip />
  130. {/*
  131. * The Toolbox is in a stacking layer above the Filmstrip.
  132. */}
  133. <Toolbox />
  134. {/*
  135. * The dialogs and overlays are in the topmost stacking layers.
  136. * Generally, the dialogs and overlays should not be visible at
  137. * the same time so it is not really defined which one is above
  138. * the other.
  139. */}
  140. <DialogContainer />
  141. <OverlayContainer />
  142. </Container>
  143. );
  144. }
  145. /**
  146. * Clears {@link #_toolboxTimeout} if any.
  147. *
  148. * @private
  149. * @returns {void}
  150. */
  151. _clearToolboxTimeout() {
  152. if (this._toolboxTimeout) {
  153. clearTimeout(this._toolboxTimeout);
  154. this._toolboxTimeout = undefined;
  155. }
  156. }
  157. /**
  158. * Changes the value of the toolboxVisible state, thus allowing us to switch
  159. * between Toolbox and Filmstrip and change their visibility.
  160. *
  161. * @private
  162. * @returns {void}
  163. */
  164. _onClick() {
  165. const toolboxVisible = !this.props._toolboxVisible;
  166. this.props._setToolboxVisible(toolboxVisible);
  167. this._setToolboxTimeout(toolboxVisible);
  168. }
  169. /**
  170. * Triggers the default Toolbox timeout.
  171. *
  172. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  173. * currently visible.
  174. * @private
  175. * @returns {void}
  176. */
  177. _setToolboxTimeout(toolboxVisible) {
  178. this._clearToolboxTimeout();
  179. if (toolboxVisible) {
  180. this._toolboxTimeout
  181. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  182. }
  183. }
  184. }
  185. /**
  186. * Maps dispatching of some action to React component props.
  187. *
  188. * @param {Function} dispatch - Redux action dispatcher.
  189. * @private
  190. * @returns {{
  191. * _onConnect: Function,
  192. * _onDisconnect: Function,
  193. * _setToolboxVisible: Function
  194. * }}
  195. */
  196. function _mapDispatchToProps(dispatch) {
  197. return {
  198. /**
  199. * Dispatched an action connecting to the conference.
  200. *
  201. * @returns {Object} Dispatched action.
  202. * @private
  203. */
  204. _onConnect() {
  205. return dispatch(connect());
  206. },
  207. /**
  208. * Dispatches an action disconnecting from the conference.
  209. *
  210. * @returns {Object} Dispatched action.
  211. * @private
  212. */
  213. _onDisconnect() {
  214. return dispatch(disconnect());
  215. },
  216. /**
  217. * Dispatches an action changing the visiblity of the Toolbox.
  218. *
  219. * @param {boolean} visible - True to show the Toolbox or false to hide
  220. * it.
  221. * @returns {Object} Dispatched action.
  222. * @private
  223. */
  224. _setToolboxVisible(visible: boolean) {
  225. return dispatch(setToolboxVisible(visible));
  226. }
  227. };
  228. }
  229. /**
  230. * Maps (parts of) the Redux state to the associated Conference's props.
  231. *
  232. * @param {Object} state - The Redux state.
  233. * @private
  234. * @returns {{
  235. * _toolboxVisible: boolean
  236. * }}
  237. */
  238. function _mapStateToProps(state) {
  239. return {
  240. /**
  241. * The indicator which determines whether the Toolbox is visible.
  242. *
  243. * @private
  244. * @type {boolean}
  245. */
  246. _toolboxVisible: state['features/toolbox'].visible
  247. };
  248. }
  249. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  250. Conference);