You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbox.web.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import {
  6. setDefaultToolboxButtons,
  7. setToolboxAlwaysVisible
  8. } from '../actions';
  9. import {
  10. abstractMapStateToProps
  11. } from '../functions';
  12. import Notice from './Notice';
  13. import PrimaryToolbar from './PrimaryToolbar';
  14. import SecondaryToolbar from './SecondaryToolbar';
  15. declare var APP: Object;
  16. declare var config: Object;
  17. declare var interfaceConfig: Object;
  18. /**
  19. * Implements the conference toolbox on React/Web.
  20. */
  21. class Toolbox extends Component<*> {
  22. /**
  23. * App component's property types.
  24. *
  25. * @static
  26. */
  27. static propTypes = {
  28. /**
  29. * Indicates if the toolbox should always be visible.
  30. */
  31. _alwaysVisible: PropTypes.bool,
  32. /**
  33. * Handler dispatching setting default buttons action.
  34. */
  35. _setDefaultToolboxButtons: PropTypes.func,
  36. /**
  37. * Handler dispatching reset always visible toolbox action.
  38. */
  39. _setToolboxAlwaysVisible: PropTypes.func,
  40. /**
  41. * Represents conference subject.
  42. */
  43. _subject: PropTypes.string,
  44. /**
  45. * Flag showing whether to set subject slide in animation.
  46. */
  47. _subjectSlideIn: PropTypes.bool,
  48. /**
  49. * Property containing toolbox timeout id.
  50. */
  51. _timeoutID: PropTypes.number
  52. };
  53. /**
  54. * Invokes reset always visible toolbox after mounting the component and
  55. * registers legacy UI listeners.
  56. *
  57. * @returns {void}
  58. */
  59. componentDidMount(): void {
  60. this.props._setToolboxAlwaysVisible();
  61. // FIXME The redux action SET_DEFAULT_TOOLBOX_BUTTONS and related source
  62. // code such as the redux action creator setDefaultToolboxButtons and
  63. // _setDefaultToolboxButtons were introduced to solve the following bug
  64. // in the implementation of features/toolbar at the time of this
  65. // writing: getDefaultToolboxButtons uses interfaceConfig which is not
  66. // in the redux store at the time of this writing yet interfaceConfig is
  67. // modified after getDefaultToolboxButtons is called.
  68. // SET_DEFAULT_TOOLBOX_BUTTONS represents/implements an explicit delay
  69. // of the invocation of getDefaultToolboxButtons until, heuristically,
  70. // all existing changes to interfaceConfig have been applied already in
  71. // our known execution paths.
  72. this.props._setDefaultToolboxButtons();
  73. }
  74. /**
  75. * Implements React's {@link Component#render()}.
  76. *
  77. * @inheritdoc
  78. * @returns {ReactElement}
  79. */
  80. render(): React$Element<*> {
  81. return (
  82. <div className = 'toolbox'>
  83. {
  84. this._renderSubject()
  85. }
  86. {
  87. this._renderToolbars()
  88. }
  89. <div id = 'sideToolbarContainer' />
  90. </div>
  91. );
  92. }
  93. /**
  94. * Returns React element representing toolbox subject.
  95. *
  96. * @returns {ReactElement}
  97. * @private
  98. */
  99. _renderSubject(): React$Element<*> | null {
  100. const { _subjectSlideIn, _subject } = this.props;
  101. const classNames = [ 'subject' ];
  102. if (!_subject) {
  103. return null;
  104. }
  105. if (_subjectSlideIn) {
  106. classNames.push('subject_slide-in');
  107. } else {
  108. classNames.push('subject_slide-out');
  109. }
  110. // XXX: Since chat is now not reactified we have to dangerously set
  111. // inner HTML into the component. This has to be refactored while
  112. // reactification of the Chat.js
  113. const innerHtml = {
  114. __html: _subject
  115. };
  116. return (
  117. <div
  118. className = { classNames.join(' ') }
  119. // eslint-disable-next-line react/no-danger
  120. dangerouslySetInnerHTML = { innerHtml }
  121. id = 'subject' />
  122. );
  123. }
  124. /**
  125. * Renders primary and secondary toolbars.
  126. *
  127. * @returns {ReactElement}
  128. * @private
  129. */
  130. _renderToolbars(): React$Element<*> | null {
  131. // In case we're not in alwaysVisible mode the toolbox should not be
  132. // shown until timeoutID is initialized.
  133. if (!this.props._alwaysVisible && this.props._timeoutID === null) {
  134. return null;
  135. }
  136. return (
  137. <div className = 'toolbox-toolbars'>
  138. <Notice />
  139. <PrimaryToolbar />
  140. <SecondaryToolbar />
  141. </div>
  142. );
  143. }
  144. }
  145. /**
  146. * Maps parts of Redux actions to component props.
  147. *
  148. * @param {Function} dispatch - Redux action dispatcher.
  149. * @returns {{
  150. * _setDefaultToolboxButtons: Function,
  151. * _setToolboxAlwaysVisible: Function
  152. * }}
  153. * @private
  154. */
  155. function _mapDispatchToProps(dispatch: Function): Object {
  156. return {
  157. /**
  158. * Dispatches a (redux) action to set the default toolbar buttons.
  159. *
  160. * @returns {Object} Dispatched action.
  161. */
  162. _setDefaultToolboxButtons() {
  163. dispatch(setDefaultToolboxButtons());
  164. },
  165. /**
  166. * Dispatches a (redux) action to reset the permanent visibility of
  167. * the Toolbox.
  168. *
  169. * @returns {Object} Dispatched action.
  170. */
  171. _setToolboxAlwaysVisible() {
  172. dispatch(setToolboxAlwaysVisible(
  173. config.alwaysVisibleToolbar === true
  174. || interfaceConfig.filmStripOnly));
  175. }
  176. };
  177. }
  178. /**
  179. * Maps parts of toolbox state to component props.
  180. *
  181. * @param {Object} state - Redux state.
  182. * @private
  183. * @returns {{
  184. * _alwaysVisible: boolean,
  185. * _audioMuted: boolean,
  186. * _subjectSlideIn: boolean,
  187. * _videoMuted: boolean
  188. * }}
  189. */
  190. function _mapStateToProps(state: Object): Object {
  191. const {
  192. alwaysVisible,
  193. subject,
  194. subjectSlideIn,
  195. timeoutID
  196. } = state['features/toolbox'];
  197. return {
  198. ...abstractMapStateToProps(state),
  199. /**
  200. * Indicates if the toolbox should always be visible.
  201. *
  202. * @private
  203. * @type {boolean}
  204. */
  205. _alwaysVisible: alwaysVisible,
  206. /**
  207. * Property containing conference subject.
  208. *
  209. * @private
  210. * @type {string}
  211. */
  212. _subject: subject,
  213. /**
  214. * Flag showing whether to set subject slide in animation.
  215. *
  216. * @private
  217. * @type {boolean}
  218. */
  219. _subjectSlideIn: subjectSlideIn,
  220. /**
  221. * Property containing toolbox timeout id.
  222. *
  223. * @private
  224. * @type {number}
  225. */
  226. _timeoutID: timeoutID
  227. };
  228. }
  229. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbox);