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.

SecondaryToolbar.web.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { FeedbackButton } from '../../feedback';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import {
  7. toggleSideToolbarContainer
  8. } from '../actions';
  9. import { getToolbarClassNames } from '../functions';
  10. import Toolbar from './Toolbar';
  11. declare var APP: Object;
  12. /**
  13. * Implementation of secondary toolbar React component.
  14. *
  15. * @class SecondaryToolbar
  16. * @extends Component
  17. */
  18. class SecondaryToolbar extends Component {
  19. state: Object;
  20. /**
  21. * Secondary toolbar property types.
  22. *
  23. * @static
  24. */
  25. static propTypes = {
  26. /**
  27. * The indicator which determines whether the local participant is a
  28. * guest in the conference.
  29. */
  30. _isGuest: React.PropTypes.bool,
  31. /**
  32. * Handler dispatching toggle toolbar container.
  33. */
  34. _onSideToolbarContainerToggled: React.PropTypes.func,
  35. /**
  36. * Contains map of secondary toolbar buttons.
  37. */
  38. _secondaryToolbarButtons: React.PropTypes.instanceOf(Map),
  39. /**
  40. * Shows whether toolbox is visible.
  41. */
  42. _visible: React.PropTypes.bool
  43. };
  44. /**
  45. * Register legacy UI listener.
  46. *
  47. * @returns {void}
  48. */
  49. componentDidMount(): void {
  50. APP.UI.addListener(
  51. UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  52. this.props._onSideToolbarContainerToggled);
  53. }
  54. /**
  55. * Unregisters legacy UI listener.
  56. *
  57. * @returns {void}
  58. */
  59. componentWillUnmount(): void {
  60. APP.UI.removeListener(
  61. UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  62. this.props._onSideToolbarContainerToggled);
  63. }
  64. /**
  65. * Renders secondary toolbar component.
  66. *
  67. * @returns {ReactElement}
  68. */
  69. render(): ReactElement<*> | null {
  70. const { _secondaryToolbarButtons } = this.props;
  71. // The number of buttons to show in the toolbar isn't fixed, it depends
  72. // on the availability of features and configuration parameters. So
  73. // there may be nothing to render.
  74. if (_secondaryToolbarButtons.size === 0) {
  75. return null;
  76. }
  77. const { secondaryToolbarClassName } = getToolbarClassNames(this.props);
  78. return (
  79. <Toolbar
  80. className = { secondaryToolbarClassName }
  81. toolbarButtons = { _secondaryToolbarButtons }
  82. tooltipPosition = { 'right' }>
  83. <FeedbackButton />
  84. </Toolbar>
  85. );
  86. }
  87. }
  88. /**
  89. * Maps some of Redux actions to component's props.
  90. *
  91. * @param {Function} dispatch - Redux action dispatcher.
  92. * @returns {{
  93. * _onSideToolbarContainerToggled
  94. * }}
  95. * @private
  96. */
  97. function _mapDispatchToProps(dispatch: Function): Object {
  98. return {
  99. /**
  100. * Dispatches an action signalling that side toolbar container is
  101. * toggled.
  102. *
  103. * @param {string} containerId - Id of side toolbar container.
  104. * @returns {Object} Dispatched action.
  105. */
  106. _onSideToolbarContainerToggled(containerId: string) {
  107. return dispatch(toggleSideToolbarContainer(containerId));
  108. }
  109. };
  110. }
  111. /**
  112. * Maps part of Redux state to component's props.
  113. *
  114. * @param {Object} state - Snapshot of Redux store.
  115. * @returns {{
  116. * _isGuest: boolean,
  117. * _secondaryToolbarButtons: Map,
  118. * _visible: boolean
  119. * }}
  120. * @private
  121. */
  122. function _mapStateToProps(state: Object): Object {
  123. const { isGuest } = state['features/jwt'];
  124. const { secondaryToolbarButtons, visible } = state['features/toolbox'];
  125. return {
  126. /**
  127. * The indicator which determines whether the local participant is a
  128. * guest in the conference.
  129. *
  130. * @private
  131. * @type {boolean}
  132. */
  133. _isGuest: isGuest,
  134. /**
  135. * Default toolbar buttons for secondary toolbar.
  136. *
  137. * @private
  138. * @type {Map}
  139. */
  140. _secondaryToolbarButtons: secondaryToolbarButtons,
  141. /**
  142. * The indicator which determines whether the {@code SecondaryToolbar}
  143. * is visible.
  144. *
  145. * @private
  146. * @type {boolean}
  147. */
  148. _visible: visible
  149. };
  150. }
  151. export default connect(_mapStateToProps, _mapDispatchToProps)(SecondaryToolbar);