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 7.2KB

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