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.

AskToUnmuteButton.tsx 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // @flow
  2. import React, { useCallback, useMemo } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useDispatch } from 'react-redux';
  5. import { approveParticipantAudio, approveParticipantVideo } from '../../../av-moderation/actions';
  6. import { IconMic, IconVideo } from '../../../base/icons/svg';
  7. import { MEDIA_TYPE, MediaType } from '../../../base/media/constants';
  8. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  9. type Props = {
  10. buttonType: MediaType;
  11. /**
  12. * The ID for the participant on which the button will act.
  13. */
  14. participantID: string;
  15. };
  16. const AskToUnmuteButton = ({ buttonType, participantID }: Props) => {
  17. const dispatch = useDispatch();
  18. const { t } = useTranslation();
  19. const _onClick = useCallback(() => {
  20. if (buttonType === MEDIA_TYPE.AUDIO) {
  21. dispatch(approveParticipantAudio(participantID));
  22. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  23. dispatch(approveParticipantVideo(participantID));
  24. }
  25. }, [ participantID, buttonType ]);
  26. const text = useMemo(() => {
  27. if (buttonType === MEDIA_TYPE.AUDIO) {
  28. return t('participantsPane.actions.askUnmute');
  29. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  30. return t('participantsPane.actions.allowVideo');
  31. }
  32. return '';
  33. }, [ buttonType ]);
  34. const icon = useMemo(() => {
  35. if (buttonType === MEDIA_TYPE.AUDIO) {
  36. return IconMic;
  37. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  38. return IconVideo;
  39. }
  40. }, [ buttonType ]);
  41. return (
  42. <ContextMenuItem
  43. accessibilityLabel = { text }
  44. icon = { icon }
  45. onClick = { _onClick }
  46. testId = { `unmute-${buttonType}-${participantID}` }
  47. text = { text } />
  48. );
  49. };
  50. export default AskToUnmuteButton;