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.5KB

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