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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 } from '../../../base/toolbox';
  16. import type { AbstractButtonProps } from '../../../base/toolbox';
  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 = IconRaisedHand;
  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(participantUpdated({
  71. // XXX Only the local participant is allowed to update without
  72. // stating the JitsiConference instance (i.e. participant property
  73. // `conference` for a remote participant) because the local
  74. // participant is uniquely identified by the very fact that there is
  75. // only one local participant.
  76. id: this.props._localParticipant.id,
  77. local: true,
  78. raisedHand: enable
  79. }));
  80. }
  81. }
  82. /**
  83. * Maps part of the Redux state to the props of this component.
  84. *
  85. * @param {Object} state - The Redux state.
  86. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  87. * @private
  88. * @returns {Props}
  89. */
  90. function _mapStateToProps(state, ownProps): Object {
  91. const _localParticipant = getLocalParticipant(state);
  92. const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
  93. const { visible = enabled } = ownProps;
  94. return {
  95. _localParticipant,
  96. _raisedHand: _localParticipant.raisedHand,
  97. visible
  98. };
  99. }
  100. export default translate(connect(_mapStateToProps)(RaiseHandButton));