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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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>
  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>
  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. * _locked: boolean,
  201. * _subjectSlideIn: boolean,
  202. * _videoMuted: boolean
  203. * }}
  204. */
  205. function _mapStateToProps(state: Object): Object {
  206. const {
  207. alwaysVisible,
  208. subject,
  209. subjectSlideIn,
  210. timeoutID
  211. } = state['features/toolbox'];
  212. return {
  213. ...abstractMapStateToProps(state),
  214. /**
  215. * Indicates if the toolbox should always be visible.
  216. *
  217. * @private
  218. * @type {boolean}
  219. */
  220. _alwaysVisible: alwaysVisible,
  221. /**
  222. * Property containing conference subject.
  223. *
  224. * @private
  225. * @type {string}
  226. */
  227. _subject: subject,
  228. /**
  229. * Flag showing whether to set subject slide in animation.
  230. *
  231. * @private
  232. * @type {boolean}
  233. */
  234. _subjectSlideIn: subjectSlideIn,
  235. /**
  236. * Property containing toolbox timeout id.
  237. *
  238. * @private
  239. * @type {number}
  240. */
  241. _timeoutID: timeoutID
  242. };
  243. }
  244. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbox);