From c0617b8c16a221c3a5f1530819501fa5485044bf Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 1 Nov 2024 13:07:04 -0500 Subject: [PATCH] fix: Detection of muting, checks only audio source. Fixes ArrayIndexOutOfBoundsException when participant is audio and video muted. --- .../jigasi/TranscriptionGatewaySession.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java b/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java index 03b7c134..797f187f 100644 --- a/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java +++ b/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java @@ -19,7 +19,6 @@ import net.java.sip.communicator.impl.protocol.jabber.*; import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.Message; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.service.protocol.media.*; import org.jitsi.utils.concurrent.*; @@ -38,6 +37,7 @@ import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.*; /** * A TranscriptionGatewaySession is able to join a JVB conference and @@ -354,26 +354,32 @@ void notifyChatRoomMemberLeft(ChatRoomMember chatMember) **/ private void flushParticipantTranscriptionBufferOnMute(ChatRoomMember chatMember, Presence presence) { - boolean hasMuted = false; - StandardExtensionElement sourceInfo = (StandardExtensionElement) presence.getExtensionElement("SourceInfo", - "jabber:client"); + final AtomicBoolean muted = new AtomicBoolean(false); + StandardExtensionElement sourceInfo = + (StandardExtensionElement) presence.getExtensionElement("SourceInfo", "jabber:client"); if (sourceInfo != null) { String mutedText = sourceInfo.getText(); JSONParser jsonParser = new JSONParser(); try { - JSONObject jsonObject = (JSONObject) jsonParser.parse(mutedText); - String participantKey = jsonObject.keySet().toArray()[0].toString(); - JSONObject mutedJsonObject = (JSONObject) jsonParser.parse(jsonObject.get(participantKey).toString()); - hasMuted = (boolean) mutedJsonObject.get("muted"); + HashMap jsonObject = (HashMap) jsonParser.parse(mutedText); + jsonObject.forEach((key, value) -> + { + // check only audio source info + if (key.endsWith("a0")) + { + Object isMuted = value.get("muted"); + muted.set(isMuted != null && (boolean) isMuted); + } + }); } catch (Exception e) { logger.error(this.callContext + " Error parsing presence while checking if participant is muted", e); } - if (hasMuted) + if (muted.get()) { this.transcriber.flushParticipantAudioBuffer(getParticipantIdentifier(chatMember)); }