Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

MuteButton.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React, { useCallback, useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { createRemoteVideoMenuButtonEvent } from '../../../analytics/AnalyticsEvents';
  5. import { sendAnalytics } from '../../../analytics/functions';
  6. import { IReduxState } from '../../../app/types';
  7. import { rejectParticipantAudio } from '../../../av-moderation/actions';
  8. import { IconMicSlash } from '../../../base/icons/svg';
  9. import { MEDIA_TYPE } from '../../../base/media/constants';
  10. import { isRemoteTrackMuted } from '../../../base/tracks/functions.any';
  11. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  12. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  13. import { muteRemote } from '../../actions.any';
  14. import { IButtonProps } from '../../types';
  15. /**
  16. * Implements a React {@link Component} which displays a button for audio muting
  17. * a participant in the conference.
  18. *
  19. * @returns {JSX.Element|null}
  20. */
  21. const MuteButton = ({
  22. notifyClick,
  23. notifyMode,
  24. participantID
  25. }: IButtonProps): JSX.Element | null => {
  26. const { t } = useTranslation();
  27. const dispatch = useDispatch();
  28. const tracks = useSelector((state: IReduxState) => state['features/base/tracks']);
  29. const audioTrackMuted = useMemo(
  30. () => isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID),
  31. [ isRemoteTrackMuted, participantID, tracks ]
  32. );
  33. const handleClick = useCallback(() => {
  34. notifyClick?.();
  35. if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  36. return;
  37. }
  38. sendAnalytics(createRemoteVideoMenuButtonEvent(
  39. 'mute',
  40. {
  41. 'participant_id': participantID
  42. }));
  43. dispatch(muteRemote(participantID, MEDIA_TYPE.AUDIO));
  44. dispatch(rejectParticipantAudio(participantID));
  45. }, [ dispatch, notifyClick, notifyMode, participantID, sendAnalytics ]);
  46. if (audioTrackMuted) {
  47. return null;
  48. }
  49. return (
  50. <ContextMenuItem
  51. accessibilityLabel = { t('dialog.muteParticipantButton') }
  52. className = 'mutelink'
  53. icon = { IconMicSlash }
  54. onClick = { handleClick }
  55. text = { t('dialog.muteParticipantButton') } />
  56. );
  57. };
  58. export default MuteButton;