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.

RaiseHandButton.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // @flow
  2. import { type Dispatch } from 'redux';
  3. import {
  4. createToolbarEvent,
  5. sendAnalytics
  6. } from '../../../analytics';
  7. import { RAISE_HAND_ENABLED, getFeatureFlag } from '../../../base/flags';
  8. import { translate } from '../../../base/i18n';
  9. import { IconRaiseHand } from '../../../base/icons';
  10. import {
  11. getLocalParticipant,
  12. hasRaisedHand,
  13. raiseHand
  14. } from '../../../base/participants';
  15. import { connect } from '../../../base/redux';
  16. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  17. /**
  18. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  19. */
  20. type Props = AbstractButtonProps & {
  21. /**
  22. * The local participant.
  23. */
  24. _localParticipant: Object,
  25. /**
  26. * Whether the participant raused their hand or not.
  27. */
  28. _raisedHand: boolean,
  29. /**
  30. * The redux {@code dispatch} function.
  31. */
  32. dispatch: Dispatch<any>
  33. };
  34. /**
  35. * An implementation of a button to raise or lower hand.
  36. */
  37. class RaiseHandButton extends AbstractButton<Props, *> {
  38. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  39. icon = IconRaiseHand;
  40. label = 'toolbar.raiseYourHand';
  41. toggledLabel = 'toolbar.lowerYourHand';
  42. /**
  43. * Handles clicking / pressing the button.
  44. *
  45. * @override
  46. * @protected
  47. * @returns {void}
  48. */
  49. _handleClick() {
  50. this._toggleRaisedHand();
  51. }
  52. /**
  53. * Indicates whether this button is in toggled state or not.
  54. *
  55. * @override
  56. * @protected
  57. * @returns {boolean}
  58. */
  59. _isToggled() {
  60. return this.props._raisedHand;
  61. }
  62. /**
  63. * Toggles the rased hand status of the local participant.
  64. *
  65. * @returns {void}
  66. */
  67. _toggleRaisedHand() {
  68. const enable = !this.props._raisedHand;
  69. sendAnalytics(createToolbarEvent('raise.hand', { enable }));
  70. this.props.dispatch(raiseHand(enable));
  71. }
  72. }
  73. /**
  74. * Maps part of the Redux state to the props of this component.
  75. *
  76. * @param {Object} state - The Redux state.
  77. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  78. * @private
  79. * @returns {Props}
  80. */
  81. function _mapStateToProps(state, ownProps): Object {
  82. const _localParticipant = getLocalParticipant(state);
  83. const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
  84. const { visible = enabled } = ownProps;
  85. return {
  86. _localParticipant,
  87. _raisedHand: hasRaisedHand(_localParticipant),
  88. visible
  89. };
  90. }
  91. export default translate(connect(_mapStateToProps)(RaiseHandButton));