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 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { useCallback, useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch } from 'react-redux';
  4. import { approveParticipantAudio, approveParticipantVideo } from '../../../av-moderation/actions';
  5. import { IconMic, IconVideo } from '../../../base/icons/svg';
  6. import { MEDIA_TYPE, MediaType } from '../../../base/media/constants';
  7. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  8. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  9. import { IButtonProps } from '../../types';
  10. interface IProps extends IButtonProps {
  11. buttonType: MediaType;
  12. }
  13. /**
  14. * Implements a React {@link Component} which displays a button that
  15. * allows the moderator to request from a participant to mute themselves.
  16. *
  17. * @returns {JSX.Element}
  18. */
  19. const AskToUnmuteButton = ({
  20. buttonType,
  21. notifyMode,
  22. notifyClick,
  23. participantID
  24. }: IProps): JSX.Element => {
  25. const dispatch = useDispatch();
  26. const { t } = useTranslation();
  27. const _onClick = useCallback(() => {
  28. notifyClick?.();
  29. if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  30. return;
  31. }
  32. if (buttonType === MEDIA_TYPE.AUDIO) {
  33. dispatch(approveParticipantAudio(participantID));
  34. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  35. dispatch(approveParticipantVideo(participantID));
  36. }
  37. }, [ buttonType, dispatch, notifyClick, notifyMode, participantID ]);
  38. const text = useMemo(() => {
  39. if (buttonType === MEDIA_TYPE.AUDIO) {
  40. return t('participantsPane.actions.askUnmute');
  41. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  42. return t('participantsPane.actions.allowVideo');
  43. }
  44. return '';
  45. }, [ buttonType ]);
  46. const icon = useMemo(() => {
  47. if (buttonType === MEDIA_TYPE.AUDIO) {
  48. return IconMic;
  49. } else if (buttonType === MEDIA_TYPE.VIDEO) {
  50. return IconVideo;
  51. }
  52. }, [ buttonType ]);
  53. return (
  54. <ContextMenuItem
  55. accessibilityLabel = { text }
  56. icon = { icon }
  57. onClick = { _onClick }
  58. testId = { `unmute-${buttonType}-${participantID}` }
  59. text = { text } />
  60. );
  61. };
  62. export default AskToUnmuteButton;