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

Conference.native.js 7.4KB

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