您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RaiseHandButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @flow
  2. import { type Dispatch } from 'redux';
  3. import {
  4. createToolbarEvent,
  5. sendAnalytics
  6. } from '../../../analytics';
  7. import { translate } from '../../../base/i18n';
  8. import {
  9. getLocalParticipant,
  10. participantUpdated
  11. } from '../../../base/participants';
  12. import { connect } from '../../../base/redux';
  13. import { AbstractButton } from '../../../base/toolbox';
  14. import type { AbstractButtonProps } from '../../../base/toolbox';
  15. /**
  16. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  17. */
  18. type Props = AbstractButtonProps & {
  19. /**
  20. * The local participant.
  21. */
  22. _localParticipant: Object,
  23. /**
  24. * Whether the participant raused their hand or not.
  25. */
  26. _raisedHand: boolean,
  27. /**
  28. * The redux {@code dispatch} function.
  29. */
  30. dispatch: Dispatch<any>
  31. };
  32. /**
  33. * An implementation of a button to raise or lower hand.
  34. */
  35. class RaiseHandButton extends AbstractButton<Props, *> {
  36. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  37. iconName = 'raised-hand';
  38. label = 'toolbar.raiseYourHand';
  39. toggledIconName = 'raised-hand';
  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. * @private
  86. * @returns {{
  87. * _raisedHand: boolean
  88. * }}
  89. */
  90. function _mapStateToProps(state): Object {
  91. const _localParticipant = getLocalParticipant(state);
  92. return {
  93. _localParticipant,
  94. _raisedHand: _localParticipant.raisedHand
  95. };
  96. }
  97. export default translate(connect(_mapStateToProps)(RaiseHandButton));