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

actions.any.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 { getIsParticipantAudioMuted } from '../base/tracks';
  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. dispatch(showModeratedNotification(MEDIA_TYPE.AUDIO));
  45. return;
  46. }
  47. sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
  48. dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
  49. : setVideoMuted(enable, mediaType, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));
  50. // FIXME: The old conference logic still relies on this event being emitted.
  51. typeof APP === 'undefined'
  52. || APP.UI.emitEvent(isAudio ? UIEvents.AUDIO_MUTED : UIEvents.VIDEO_MUTED, enable);
  53. };
  54. }
  55. /**
  56. * Mutes the remote participant with the given ID.
  57. *
  58. * @param {string} participantId - ID of the participant to mute.
  59. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  60. * @returns {Function}
  61. */
  62. export function muteRemote(participantId: string, mediaType: MEDIA_TYPE) {
  63. return (dispatch: Dispatch<any>) => {
  64. if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
  65. logger.error(`Unsupported media type: ${mediaType}`);
  66. return;
  67. }
  68. sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
  69. dispatch(muteRemoteParticipant(participantId, mediaType));
  70. };
  71. }
  72. /**
  73. * Mutes all participants.
  74. *
  75. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  76. * @param {MEDIA_TYPE} mediaType - The media type to mute.
  77. * @returns {Function}
  78. */
  79. export function muteAllParticipants(exclude: Array<string>, mediaType: MEDIA_TYPE) {
  80. return (dispatch: Dispatch<any>, getState: Function) => {
  81. const state = getState();
  82. const localId = getLocalParticipant(state).id;
  83. if (!exclude.includes(localId)) {
  84. dispatch(muteLocal(true, mediaType));
  85. }
  86. getRemoteParticipants(state).forEach((p, id) => {
  87. if (exclude.includes(id)) {
  88. return;
  89. }
  90. dispatch(muteRemote(id, mediaType));
  91. });
  92. };
  93. }
  94. /**
  95. * Don't allow participants to unmute video/audio.
  96. *
  97. * @returns {Function}
  98. */
  99. export function blockParticipantsAudioVideo() {
  100. return (dispatch: Dispatch<any>, getState: Function) => {
  101. const state = getState();
  102. const participants = state['features/base/participants'];
  103. participants
  104. .map(p => !getIsParticipantAudioMuted(p) && setAudioMuted(true));
  105. };
  106. }