Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

actions.any.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. import { setKnockingParticipantApproval } from '../lobby/actions';
  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. * @returns {Function}
  35. */
  36. export function muteLocal(enable: boolean, mediaType: MEDIA_TYPE) {
  37. return (dispatch: Dispatch<any>, getState: Function) => {
  38. const isAudio = mediaType === MEDIA_TYPE.AUDIO;
  39. if (!isAudio && mediaType !== MEDIA_TYPE.VIDEO) {
  40. logger.error(`Unsupported media type: ${mediaType}`);
  41. return;
  42. }
  43. // check for A/V Moderation when trying to unmute
  44. if (!enable && shouldShowModeratedNotification(MEDIA_TYPE.AUDIO, getState())) {
  45. dispatch(showModeratedNotification(MEDIA_TYPE.AUDIO));
  46. return;
  47. }
  48. sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
  49. dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
  50. : setVideoMuted(enable, mediaType, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));
  51. // FIXME: The old conference logic still relies on this event being emitted.
  52. typeof APP === 'undefined'
  53. || APP.UI.emitEvent(isAudio ? UIEvents.AUDIO_MUTED : UIEvents.VIDEO_MUTED, enable);
  54. };
  55. }
  56. /**
  57. * Mutes the remote participant with the given ID.
  58. *
  59. * @param {string} participantId - ID of the participant to mute.
  60. * @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
  61. * @returns {Function}
  62. */
  63. export function muteRemote(participantId: string, mediaType: MEDIA_TYPE) {
  64. return (dispatch: Dispatch<any>) => {
  65. if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
  66. logger.error(`Unsupported media type: ${mediaType}`);
  67. return;
  68. }
  69. sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
  70. dispatch(muteRemoteParticipant(participantId, mediaType));
  71. };
  72. }
  73. /**
  74. * Mutes all participants.
  75. *
  76. * @param {Array<string>} exclude - Array of participant IDs to not mute.
  77. * @param {MEDIA_TYPE} mediaType - The media type to mute.
  78. * @returns {Function}
  79. */
  80. export function muteAllParticipants(exclude: Array<string>, mediaType: MEDIA_TYPE) {
  81. return (dispatch: Dispatch<any>, getState: Function) => {
  82. const state = getState();
  83. const localId = getLocalParticipant(state).id;
  84. if (!exclude.includes(localId)) {
  85. dispatch(muteLocal(true, mediaType));
  86. }
  87. getRemoteParticipants(state).forEach((p, id) => {
  88. if (exclude.includes(id)) {
  89. return;
  90. }
  91. dispatch(muteRemote(id, mediaType));
  92. });
  93. };
  94. }
  95. /**
  96. * Admit all knocking participants.
  97. *
  98. * @param {Array<Object>} knockingParticipants - Array of participants waiting in lobby.
  99. * @param {boolean} lobbyEnabled - Is lobby mode enabled.
  100. *
  101. * @returns {Function}
  102. */
  103. export function admitAllKnockingParticipants(knockingParticipants: Array<Object>, lobbyEnabled: boolean) {
  104. return (dispatch: Dispatch<any>) => {
  105. const knockingParticipantsIds = knockingParticipants.map(participant => participant.id);
  106. knockingParticipantsIds
  107. .map(id => lobbyEnabled && setKnockingParticipantApproval(id, true))
  108. .map(dispatch);
  109. };
  110. }
  111. /**
  112. * Don't allow participants to unmute.
  113. *
  114. * @returns {Function}
  115. */
  116. export function dontAllowUnmute() {
  117. return (dispatch: Dispatch<any>, getState: Function) => {
  118. const state = getState();
  119. const participants = state['features/base/participants'];
  120. participants
  121. .map(p => !getIsParticipantAudioMuted(p) && setAudioMuted(true));
  122. };
  123. }