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.

actions.any.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {
  2. AUDIO_MUTE,
  3. VIDEO_MUTE,
  4. createRemoteMuteConfirmedEvent,
  5. createToolbarEvent
  6. } from '../analytics/AnalyticsEvents';
  7. import { sendAnalytics } from '../analytics/functions';
  8. import { IStore } from '../app/types';
  9. import { rejectParticipantAudio, rejectParticipantVideo, showModeratedNotification } from '../av-moderation/actions';
  10. import { shouldShowModeratedNotification } from '../av-moderation/functions';
  11. import { setAudioMuted, setVideoMuted } from '../base/media/actions';
  12. import { MEDIA_TYPE, MediaType, VIDEO_MUTISM_AUTHORITY } from '../base/media/constants';
  13. import { muteRemoteParticipant } from '../base/participants/actions';
  14. import { getLocalParticipant, getRemoteParticipants } from '../base/participants/functions';
  15. import { toggleScreensharing } from '../base/tracks/actions';
  16. import { isModerationNotificationDisplayed } from '../notifications/functions';
  17. import logger from './logger';
  18. /**
  19. * Mutes the local participant.
  20. *
  21. * @param {boolean} enable - Whether to mute or unmute.
  22. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  23. * @param {boolean} stopScreenSharing - Whether or not to stop the screensharing.
  24. * @returns {Function}
  25. */
  26. export function muteLocal(enable: boolean, mediaType: MediaType, stopScreenSharing = false) {
  27. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  28. const isAudio = mediaType === MEDIA_TYPE.AUDIO;
  29. if (!isAudio && mediaType !== MEDIA_TYPE.VIDEO) {
  30. logger.error(`Unsupported media type: ${mediaType}`);
  31. return;
  32. }
  33. // check for A/V Moderation when trying to unmute
  34. if (!enable && shouldShowModeratedNotification(MEDIA_TYPE.AUDIO, getState())) {
  35. if (!isModerationNotificationDisplayed(MEDIA_TYPE.AUDIO, getState())) {
  36. dispatch(showModeratedNotification(MEDIA_TYPE.AUDIO));
  37. }
  38. return;
  39. }
  40. if (enable && stopScreenSharing) {
  41. dispatch(toggleScreensharing(false, false));
  42. }
  43. sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
  44. dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
  45. : setVideoMuted(enable, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));
  46. // FIXME: The old conference logic still relies on this event being emitted.
  47. if (typeof APP !== 'undefined') {
  48. isAudio ? APP.conference.muteAudio(enable) : APP.conference.muteVideo(enable, false);
  49. }
  50. };
  51. }
  52. /**
  53. * Mutes the remote participant with the given ID.
  54. *
  55. * @param {string} participantId - ID of the participant to mute.
  56. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  57. * @returns {Function}
  58. */
  59. export function muteRemote(participantId: string, mediaType: MediaType) {
  60. return (dispatch: IStore['dispatch']) => {
  61. if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
  62. logger.error(`Unsupported media type: ${mediaType}`);
  63. return;
  64. }
  65. sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
  66. dispatch(muteRemoteParticipant(participantId, mediaType));
  67. };
  68. }
  69. /**
  70. * Mutes all participants.
  71. *
  72. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  73. * @param {MEDIA_TYPE} mediaType - The media type to mute.
  74. * @returns {Function}
  75. */
  76. export function muteAllParticipants(exclude: Array<string>, mediaType: MediaType) {
  77. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  78. const state = getState();
  79. const localId = getLocalParticipant(state)?.id ?? '';
  80. if (!exclude.includes(localId)) {
  81. dispatch(muteLocal(true, mediaType, mediaType !== MEDIA_TYPE.AUDIO));
  82. }
  83. getRemoteParticipants(state).forEach((p, id) => {
  84. if (exclude.includes(id)) {
  85. return;
  86. }
  87. dispatch(muteRemote(id, mediaType));
  88. if (mediaType === MEDIA_TYPE.AUDIO) {
  89. dispatch(rejectParticipantAudio(id));
  90. } else {
  91. dispatch(rejectParticipantVideo(id));
  92. }
  93. });
  94. };
  95. }