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

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