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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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
  90. ? <FeedbackButton tooltipPosition = 'right' /> : null }
  91. </Toolbar>
  92. );
  93. }
  94. }
  95. /**
  96. * Maps some of Redux actions to component's props.
  97. *
  98. * @param {Function} dispatch - Redux action dispatcher.
  99. * @returns {{
  100. * _onSideToolbarContainerToggled
  101. * }}
  102. * @private
  103. */
  104. function _mapDispatchToProps(dispatch: Function): Object {
  105. return {
  106. /**
  107. * Dispatches an action signalling that side toolbar container is
  108. * toggled.
  109. *
  110. * @param {string} containerId - Id of side toolbar container.
  111. * @returns {Object} Dispatched action.
  112. */
  113. _onSideToolbarContainerToggled(containerId: string) {
  114. dispatch(toggleSideToolbarContainer(containerId));
  115. }
  116. };
  117. }
  118. /**
  119. * Maps part of Redux state to component's props.
  120. *
  121. * @param {Object} state - Snapshot of Redux store.
  122. * @returns {{
  123. * _isGuest: boolean,
  124. * _secondaryToolbarButtons: Map,
  125. * _visible: boolean
  126. * }}
  127. * @private
  128. */
  129. function _mapStateToProps(state: Object): Object {
  130. const { isGuest } = state['features/jwt'];
  131. const { secondaryToolbarButtons, visible } = state['features/toolbox'];
  132. const { callStatsID } = state['features/base/config'];
  133. return {
  134. /**
  135. * Application ID for callstats.io API.
  136. */
  137. _callStatsID: callStatsID,
  138. /**
  139. * The indicator which determines whether the local participant is a
  140. * guest in the conference.
  141. *
  142. * @private
  143. * @type {boolean}
  144. */
  145. _isGuest: isGuest,
  146. /**
  147. * Default toolbar buttons for secondary toolbar.
  148. *
  149. * @private
  150. * @type {Map}
  151. */
  152. _secondaryToolbarButtons: secondaryToolbarButtons,
  153. /**
  154. * The indicator which determines whether the {@code SecondaryToolbar}
  155. * is visible.
  156. *
  157. * @private
  158. * @type {boolean}
  159. */
  160. _visible: visible
  161. };
  162. }
  163. export default connect(_mapStateToProps, _mapDispatchToProps)(SecondaryToolbar);