您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.any.ts 4.2KB

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