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

Conference.native.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 overlays need to be bellow the Toolbox so that the user
  132. * may tap the ToolbarButtons.
  133. */}
  134. <OverlayContainer />
  135. {/*
  136. * The Toolbox is in a stacking layer above the Filmstrip.
  137. */}
  138. <Toolbox />
  139. {/*
  140. * The dialogs are in the topmost stacking layers.
  141. */}
  142. <DialogContainer />
  143. </Container>
  144. );
  145. }
  146. /**
  147. * Clears {@link #_toolboxTimeout} if any.
  148. *
  149. * @private
  150. * @returns {void}
  151. */
  152. _clearToolboxTimeout() {
  153. if (this._toolboxTimeout) {
  154. clearTimeout(this._toolboxTimeout);
  155. this._toolboxTimeout = undefined;
  156. }
  157. }
  158. /**
  159. * Changes the value of the toolboxVisible state, thus allowing us to switch
  160. * between Toolbox and Filmstrip and change their visibility.
  161. *
  162. * @private
  163. * @returns {void}
  164. */
  165. _onClick() {
  166. const toolboxVisible = !this.props._toolboxVisible;
  167. this.props._setToolboxVisible(toolboxVisible);
  168. this._setToolboxTimeout(toolboxVisible);
  169. }
  170. /**
  171. * Triggers the default Toolbox timeout.
  172. *
  173. * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
  174. * currently visible.
  175. * @private
  176. * @returns {void}
  177. */
  178. _setToolboxTimeout(toolboxVisible) {
  179. this._clearToolboxTimeout();
  180. if (toolboxVisible) {
  181. this._toolboxTimeout
  182. = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
  183. }
  184. }
  185. }
  186. /**
  187. * Maps dispatching of some action to React component props.
  188. *
  189. * @param {Function} dispatch - Redux action dispatcher.
  190. * @private
  191. * @returns {{
  192. * _onConnect: Function,
  193. * _onDisconnect: Function,
  194. * _setToolboxVisible: Function
  195. * }}
  196. */
  197. function _mapDispatchToProps(dispatch) {
  198. return {
  199. /**
  200. * Dispatched an action connecting to the conference.
  201. *
  202. * @returns {Object} Dispatched action.
  203. * @private
  204. */
  205. _onConnect() {
  206. dispatch(connect());
  207. },
  208. /**
  209. * Dispatches an action disconnecting from the conference.
  210. *
  211. * @returns {Object} Dispatched action.
  212. * @private
  213. */
  214. _onDisconnect() {
  215. dispatch(disconnect());
  216. },
  217. /**
  218. * Dispatches an action changing the visiblity of the Toolbox.
  219. *
  220. * @param {boolean} visible - True to show the Toolbox or false to hide
  221. * it.
  222. * @returns {Object} Dispatched action.
  223. * @private
  224. */
  225. _setToolboxVisible(visible: boolean) {
  226. dispatch(setToolboxVisible(visible));
  227. }
  228. };
  229. }
  230. /**
  231. * Maps (parts of) the Redux state to the associated Conference's props.
  232. *
  233. * @param {Object} state - The Redux state.
  234. * @private
  235. * @returns {{
  236. * _toolboxVisible: boolean
  237. * }}
  238. */
  239. function _mapStateToProps(state) {
  240. return {
  241. /**
  242. * The indicator which determines whether the Toolbox is visible.
  243. *
  244. * @private
  245. * @type {boolean}
  246. */
  247. _toolboxVisible: state['features/toolbox'].visible
  248. };
  249. }
  250. export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
  251. Conference);