Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AskUnmuteButton.ts 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { connect } from 'react-redux';
  2. import { IReduxState } from '../../../app/types';
  3. import { approveParticipant } from '../../../av-moderation/actions';
  4. import { isSupported } from '../../../av-moderation/functions';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { IconMic, IconVideo } from '../../../base/icons/svg';
  7. import { MEDIA_TYPE } from '../../../base/media/constants';
  8. import { getParticipantById, isLocalParticipantModerator } from '../../../base/participants/functions';
  9. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  10. import { isForceMuted } from '../../../participants-pane/functions';
  11. export interface IProps extends AbstractButtonProps {
  12. /**
  13. * Whether or not the participant is audio force muted.
  14. */
  15. isAudioForceMuted: boolean;
  16. /**
  17. * Whether or not the participant is video force muted.
  18. */
  19. isVideoForceMuted: boolean;
  20. /**
  21. * The ID of the participant object that this button is supposed to
  22. * ask to unmute.
  23. */
  24. participantID: string;
  25. }
  26. /**
  27. * An abstract remote video menu button which asks the remote participant to unmute.
  28. */
  29. class AskUnmuteButton extends AbstractButton<IProps> {
  30. accessibilityLabel = 'participantsPane.actions.askUnmute';
  31. icon = IconMic;
  32. label = 'participantsPane.actions.askUnmute';
  33. /**
  34. * Gets the current label.
  35. *
  36. * @returns {string}
  37. */
  38. _getLabel() {
  39. const { isAudioForceMuted, isVideoForceMuted } = this.props;
  40. if (!isAudioForceMuted && isVideoForceMuted) {
  41. return 'participantsPane.actions.allowVideo';
  42. }
  43. return this.label;
  44. }
  45. /**
  46. * Gets the current icon.
  47. *
  48. * @returns {string}
  49. */
  50. _getIcon() {
  51. const { isAudioForceMuted, isVideoForceMuted } = this.props;
  52. if (!isAudioForceMuted && isVideoForceMuted) {
  53. return IconVideo;
  54. }
  55. return this.icon;
  56. }
  57. /**
  58. * Handles clicking / pressing the button, and asks the participant to unmute.
  59. *
  60. * @private
  61. * @returns {void}
  62. */
  63. _handleClick() {
  64. const { dispatch, participantID } = this.props;
  65. dispatch(approveParticipant(participantID));
  66. }
  67. }
  68. /**
  69. * Maps part of the Redux state to the props of this component.
  70. *
  71. * @param {Object} state - The Redux state.
  72. * @param {Object} ownProps - Properties of component.
  73. * @returns {IProps}
  74. */
  75. function mapStateToProps(state: IReduxState, ownProps: any) {
  76. const { participantID } = ownProps;
  77. const participant = getParticipantById(state, participantID);
  78. return {
  79. isAudioForceMuted: isForceMuted(participant, MEDIA_TYPE.AUDIO, state),
  80. isVideoForceMuted: isForceMuted(participant, MEDIA_TYPE.VIDEO, state),
  81. visible: isLocalParticipantModerator(state) && isSupported()(state)
  82. };
  83. }
  84. export default translate(connect(mapStateToProps)(AskUnmuteButton));