Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(external-api): fire participantMuted event for all mute state changes (#16893)

Mihaela Dumitruc457ed0d3ceb
diff --git a/modules/API/API.js b/modules/API/API.js
index ecdb197cc2..b154f45570 100755
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -240,13 +240,27 @@ function initCommands() {
APP.store.dispatch(muteAllParticipants(exclude, muteMediaType));
},
'mute-remote-participant': (participantId, mediaType) => {
- if (!isLocalParticipantModerator(APP.store.getState())) {
- logger.error('Missing moderator rights to mute remote participant');
+ const state = APP.store.getState();
+ const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
+ const localParticipant = getLocalParticipant(state);
+
+ // Check if targeting the local participant
+ if (participantId === localParticipant?.id) {
+
+ if (muteMediaType === MEDIA_TYPE.AUDIO) {
+ APP.conference.toggleAudioMuted(false);
+ } else if (muteMediaType === MEDIA_TYPE.VIDEO) {
+ APP.conference.toggleVideoMuted(false, true);
+ }
return;
}
- const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
+ if (!isLocalParticipantModerator(state)) {
+ logger.error('Missing moderator rights to mute remote participant');
+
+ return;
+ }
APP.store.dispatch(muteRemote(participantId, muteMediaType));
},
@@ -1417,17 +1431,15 @@ class API {
*
* @param {string} participantId - The ID of the participant.
* @param {boolean} isMuted - True if muted, false if unmuted.
- * @param {string} mediaType - Media type that was muted ('audio', 'video', or 'desktop').
- * @param {boolean} isSelfMuted - True if participant muted themselves, false if muted by moderator.
+ * @param {string} mediaType - Media type that was muted ('audio' or 'video').
* @returns {void}
*/
- notifyParticipantMuted(participantId, isMuted, mediaType, isSelfMuted = true) {
+ notifyParticipantMuted(participantId, isMuted, mediaType) {
this._sendEvent({
name: 'participant-muted',
id: participantId,
isMuted,
- mediaType,
- isSelfMuted
+ mediaType
});
}
diff --git a/react/features/base/media/subscriber.ts b/react/features/base/media/subscriber.ts
index 513cd7e147..842a516260 100644
--- a/react/features/base/media/subscriber.ts
+++ b/react/features/base/media/subscriber.ts
@@ -1,4 +1,5 @@
import { IReduxState, IStore } from '../../app/types';
+import { getLocalParticipant } from '../participants/functions';
import StateListenerRegistry from '../redux/StateListenerRegistry';
/**
@@ -13,6 +14,13 @@ StateListenerRegistry.register(
if (muted !== previousMuted) {
APP.API.notifyAudioMutedStatusChanged(muted);
+
+ // Also fire the participantMuted event for consistency
+ const localParticipant = getLocalParticipant(store.getState());
+
+ if (localParticipant) {
+ APP.API.notifyParticipantMuted(localParticipant.id, muted, 'audio');
+ }
}
}
);
diff --git a/react/features/base/tracks/middleware.web.ts b/react/features/base/tracks/middleware.web.ts
index 1df33ecd25..1c347c9369 100644
--- a/react/features/base/tracks/middleware.web.ts
+++ b/react/features/base/tracks/middleware.web.ts
@@ -51,7 +51,7 @@ import './subscriber.web';
MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
case TRACK_ADDED: {
- const { local } = action.track;
+ const { local, jitsiTrack } = action.track;
// The devices list needs to be refreshed when no initial video permissions
// were granted and a local video track is added by umuting the video.
@@ -65,6 +65,16 @@ MiddlewareRegistry.register(store => next => action => {
if (participantId) {
logTracksForParticipant(store.getState()['features/base/tracks'], participantId, 'Track added');
+
+ // Fire participantMuted event for initial state of remote tracks
+ if (typeof action.track?.muted !== 'undefined' && jitsiTrack) {
+ const isVideoTrack = jitsiTrack.getType() !== MEDIA_TYPE.AUDIO;
+ const mediaType = isVideoTrack
+ ? (jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP ? 'desktop' : 'video')
+ : 'audio';
+
+ APP.API.notifyParticipantMuted(participantId, action.track.muted, mediaType);
+ }
}
return result;
@@ -119,6 +129,16 @@ MiddlewareRegistry.register(store => next => action => {
// TODO Remove the following calls to APP.UI once components interested
// in track mute changes are moved into React and/or redux.
+ const { jitsiTrack } = action.track;
+ const participantID = jitsiTrack.getParticipantId();
+ const isVideoTrack = jitsiTrack.type !== MEDIA_TYPE.AUDIO;
+ const local = jitsiTrack.isLocal();
+
+ // Get old muted state BEFORE updating
+ const tracks = store.getState()['features/base/tracks'];
+ const oldTrack = tracks.find((t: ITrack) => t.jitsiTrack === jitsiTrack);
+ const oldMutedState = oldTrack?.muted;
+
const result = next(action);
const state = store.getState();
@@ -126,11 +146,6 @@ MiddlewareRegistry.register(store => next => action => {
return result;
}
- const { jitsiTrack } = action.track;
- const participantID = jitsiTrack.getParticipantId();
- const isVideoTrack = jitsiTrack.type !== MEDIA_TYPE.AUDIO;
- const local = jitsiTrack.isLocal();
-
if (isVideoTrack) {
if (local && !(jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP)) {
APP.conference.setVideoMuteStatus();
@@ -144,12 +159,14 @@ MiddlewareRegistry.register(store => next => action => {
if (typeof action.track?.muted !== 'undefined' && participantID && !local) {
logTracksForParticipant(store.getState()['features/base/tracks'], participantID, 'Track updated');
- // Notify external API when remote participant mutes/unmutes themselves
- const mediaType = isVideoTrack
- ? (jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP ? 'desktop' : 'video')
- : 'audio';
+ // Fire participantMuted event only if muted state actually changed
+ if (oldMutedState !== action.track.muted) {
+ const mediaType = isVideoTrack
+ ? (jitsiTrack.getVideoType() === VIDEO_TYPE.DESKTOP ? 'desktop' : 'video')
+ : 'audio';
- APP.API.notifyParticipantMuted(participantID, action.track.muted, mediaType, true);
+ APP.API.notifyParticipantMuted(participantID, action.track.muted, mediaType);
+ }
}
return result;
diff --git a/react/features/base/tracks/subscriber.web.ts b/react/features/base/tracks/subscriber.web.ts
index 1fba331c3e..fea8c51ce4 100644
--- a/react/features/base/tracks/subscriber.web.ts
+++ b/react/features/base/tracks/subscriber.web.ts
@@ -4,7 +4,7 @@ import { isEqual, sortBy } from 'lodash-es';
import VideoLayout from '../../../../modules/UI/videolayout/VideoLayout';
import { getAutoPinSetting } from '../../video-layout/functions.any';
import { MEDIA_TYPE } from '../media/constants';
-import { getScreenshareParticipantIds } from '../participants/functions';
+import { getLocalParticipant, getScreenshareParticipantIds } from '../participants/functions';
import StateListenerRegistry from '../redux/StateListenerRegistry';
import { isLocalTrackMuted } from './functions';
@@ -47,6 +47,13 @@ StateListenerRegistry.register(
/* listener */ (muted, store, previousMuted) => {
if (muted !== previousMuted) {
APP.API.notifyVideoMutedStatusChanged(muted);
+
+ // Also fire the participantMuted event for consistency
+ const localParticipant = getLocalParticipant(store.getState());
+
+ if (localParticipant) {
+ APP.API.notifyParticipantMuted(localParticipant.id, muted, 'video');
+ }
}
}
);
diff --git a/react/features/video-menu/actions.any.ts b/react/features/video-menu/actions.any.ts
index a324624b88..a48ab22f81 100644
--- a/react/features/video-menu/actions.any.ts
+++ b/react/features/video-menu/actions.any.ts
@@ -73,11 +73,6 @@ export function muteRemote(participantId: string, mediaType: MediaType) {
const muteMediaType = mediaType === MEDIA_TYPE.SCREENSHARE ? 'desktop' : mediaType;
dispatch(muteRemoteParticipant(participantId, muteMediaType));
-
- // Notify external API that participant was muted by moderator
- if (typeof APP !== 'undefined') {
- APP.API.notifyParticipantMuted(participantId, true, muteMediaType, false);
- }
};
}