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.js 4.0KB

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