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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 { 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. declare var APP: Object;
  26. const logger = getLogger(__filename);
  27. /**
  28. * Mutes the local participant.
  29. *
  30. * @param {boolean} enable - Whether to mute or unmute.
  31. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  32. * @returns {Function}
  33. */
  34. export function muteLocal(enable: boolean, mediaType: MEDIA_TYPE) {
  35. return (dispatch: Dispatch<any>, getState: Function) => {
  36. const isAudio = mediaType === MEDIA_TYPE.AUDIO;
  37. if (!isAudio && mediaType !== MEDIA_TYPE.VIDEO) {
  38. logger.error(`Unsupported media type: ${mediaType}`);
  39. return;
  40. }
  41. // check for A/V Moderation when trying to unmute
  42. if (!enable && shouldShowModeratedNotification(MEDIA_TYPE.AUDIO, getState())) {
  43. dispatch(showModeratedNotification(MEDIA_TYPE.AUDIO));
  44. return;
  45. }
  46. sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
  47. dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
  48. : setVideoMuted(enable, mediaType, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));
  49. // FIXME: The old conference logic still relies on this event being emitted.
  50. typeof APP === 'undefined'
  51. || APP.UI.emitEvent(isAudio ? UIEvents.AUDIO_MUTED : UIEvents.VIDEO_MUTED, enable);
  52. };
  53. }
  54. /**
  55. * Mutes the remote participant with the given ID.
  56. *
  57. * @param {string} participantId - ID of the participant to mute.
  58. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  59. * @returns {Function}
  60. */
  61. export function muteRemote(participantId: string, mediaType: MEDIA_TYPE) {
  62. return (dispatch: Dispatch<any>) => {
  63. if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
  64. logger.error(`Unsupported media type: ${mediaType}`);
  65. return;
  66. }
  67. sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
  68. dispatch(muteRemoteParticipant(participantId, mediaType));
  69. };
  70. }
  71. /**
  72. * Mutes all participants.
  73. *
  74. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  75. * @param {MEDIA_TYPE} mediaType - The media type to mute.
  76. * @returns {Function}
  77. */
  78. export function muteAllParticipants(exclude: Array<string>, mediaType: MEDIA_TYPE) {
  79. return (dispatch: Dispatch<any>, getState: Function) => {
  80. const state = getState();
  81. const localId = getLocalParticipant(state).id;
  82. if (!exclude.includes(localId)) {
  83. dispatch(muteLocal(true, mediaType));
  84. }
  85. getRemoteParticipants(state).forEach((p, id) => {
  86. if (exclude.includes(id)) {
  87. return;
  88. }
  89. dispatch(muteRemote(id, mediaType));
  90. });
  91. };
  92. }