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

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