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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { IconRaisedHand } from '../../../base/icons';
  10. import {
  11. getLocalParticipant,
  12. participantUpdated
  13. } from '../../../base/participants';
  14. import { connect } from '../../../base/redux';
  15. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  16. /**
  17. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  18. */
  19. type Props = AbstractButtonProps & {
  20. /**
  21. * The local participant.
  22. */
  23. _localParticipant: Object,
  24. /**
  25. * Whether the participant raused their hand or not.
  26. */
  27. _raisedHand: boolean,
  28. /**
  29. * The redux {@code dispatch} function.
  30. */
  31. dispatch: Dispatch<any>
  32. };
  33. /**
  34. * An implementation of a button to raise or lower hand.
  35. */
  36. class RaiseHandButton extends AbstractButton<Props, *> {
  37. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  38. icon = IconRaisedHand;
  39. label = 'toolbar.raiseYourHand';
  40. toggledLabel = 'toolbar.lowerYourHand';
  41. /**
  42. * Handles clicking / pressing the button.
  43. *
  44. * @override
  45. * @protected
  46. * @returns {void}
  47. */
  48. _handleClick() {
  49. this._toggleRaisedHand();
  50. }
  51. /**
  52. * Indicates whether this button is in toggled state or not.
  53. *
  54. * @override
  55. * @protected
  56. * @returns {boolean}
  57. */
  58. _isToggled() {
  59. return this.props._raisedHand;
  60. }
  61. /**
  62. * Toggles the rased hand status of the local participant.
  63. *
  64. * @returns {void}
  65. */
  66. _toggleRaisedHand() {
  67. const enable = !this.props._raisedHand;
  68. sendAnalytics(createToolbarEvent('raise.hand', { enable }));
  69. this.props.dispatch(participantUpdated({
  70. // XXX Only the local participant is allowed to update without
  71. // stating the JitsiConference instance (i.e. participant property
  72. // `conference` for a remote participant) because the local
  73. // participant is uniquely identified by the very fact that there is
  74. // only one local participant.
  75. id: this.props._localParticipant.id,
  76. local: true,
  77. raisedHand: enable
  78. }));
  79. }
  80. }
  81. /**
  82. * Maps part of the Redux state to the props of this component.
  83. *
  84. * @param {Object} state - The Redux state.
  85. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  86. * @private
  87. * @returns {Props}
  88. */
  89. function _mapStateToProps(state, ownProps): Object {
  90. const _localParticipant = getLocalParticipant(state);
  91. const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
  92. const { visible = enabled } = ownProps;
  93. return {
  94. _localParticipant,
  95. _raisedHand: _localParticipant.raisedHand,
  96. visible
  97. };
  98. }
  99. export default translate(connect(_mapStateToProps)(RaiseHandButton));