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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. muteRemoteParticipant
  23. } from '../base/participants';
  24. declare var APP: Object;
  25. const logger = getLogger(__filename);
  26. /**
  27. * Mutes the local participant.
  28. *
  29. * @param {boolean} enable - Whether to mute or unmute.
  30. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  31. * @returns {Function}
  32. */
  33. export function muteLocal(enable: boolean, mediaType: MEDIA_TYPE) {
  34. return (dispatch: Dispatch<any>, getState: Function) => {
  35. const isAudio = mediaType === MEDIA_TYPE.AUDIO;
  36. if (!isAudio && mediaType !== MEDIA_TYPE.VIDEO) {
  37. logger.error(`Unsupported media type: ${mediaType}`);
  38. return;
  39. }
  40. // check for A/V Moderation when trying to unmute
  41. if (!enable && shouldShowModeratedNotification(MEDIA_TYPE.AUDIO, getState())) {
  42. dispatch(showModeratedNotification(MEDIA_TYPE.AUDIO));
  43. return;
  44. }
  45. sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
  46. dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
  47. : setVideoMuted(enable, mediaType, 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: MEDIA_TYPE) {
  61. return (dispatch: Dispatch<any>) => {
  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: MEDIA_TYPE) {
  78. return (dispatch: Dispatch<any>, getState: Function) => {
  79. const state = getState();
  80. const localId = getLocalParticipant(state).id;
  81. const participantIds = state['features/base/participants']
  82. .map(p => p.id);
  83. /* eslint-disable no-confusing-arrow */
  84. participantIds
  85. .filter(id => !exclude.includes(id))
  86. .map(id => id === localId ? muteLocal(true, mediaType) : muteRemote(id, mediaType))
  87. .map(dispatch);
  88. /* eslint-enable no-confusing-arrow */
  89. };
  90. }