Skip to content

Commit

Permalink
Fix logic on when to ignore member role changes, and when to log abou…
Browse files Browse the repository at this point in the history
…t them. (#1208)
  • Loading branch information
JonathanLennox authored and damencho committed Feb 19, 2025
1 parent 25ef40f commit ae76ef8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ class ChatRoomMemberImpl(

var newRole: MemberRole = MemberRole.VISITOR
chatRoom.getOccupant(this)?.let { newRole = fromSmack(it.role, it.affiliation) }
if (!firstPresence && presence.type != Presence.Type.unavailable &&
(role == MemberRole.VISITOR) != (newRole == MemberRole.VISITOR)
) {
// This will mess up various member counts
if (!firstPresence && (role == MemberRole.VISITOR) != (newRole == MemberRole.VISITOR)) {
// Allowing this to change would mess up various member counts, ignore the change
// TODO: Should we try to update them, instead?
logger.warn("Member role changed from $role to $newRole - not supported!")
if (presence.type != Presence.Type.unavailable) {
logger.warn("Member role changed from $role to $newRole - not supported!")
}
} else {
role = newRole
}
Expand All @@ -214,35 +214,37 @@ class ChatRoomMemberImpl(
statsId = it.statsId
}

presence.getExtension(JitsiParticipantCodecList::class.java)?.let {
if (!firstPresence && it.codecs != videoCodecs) {
logger.warn("Video codec list changed from $videoCodecs to ${it.codecs} - not supported!")
} else {
val newVideoCodecs =
presence.getExtension(JitsiParticipantCodecList::class.java)?.let {
if (!it.codecs.contains("vp8")) {
if (firstPresence) {
logger.warn("Video codec list {${it.codecs}} does not contain vp8! Adding manually.")
}
videoCodecs = it.codecs + "vp8"
it.codecs + "vp8"
} else {
videoCodecs = it.codecs
it.codecs
}
}
} ?: // Older clients sent a single codec in codecType rather than all supported ones in codecList
presence.getExtensionElement("jitsi_participant_codecType", "jabber:client")?.let {
if (it is StandardExtensionElement) {
val codec = it.text.lowercase()
val codecList = if (codec == "vp8") {
listOf(codec)
} else {
listOf(codec, "vp8")
}
if (!firstPresence && codecList != videoCodecs) {
logger.warn("Video codec list changed from $videoCodecs to $codecList - not supported!")
} ?: // Older clients sent a single codec in codecType rather than all supported ones in codecList
presence.getExtensionElement("jitsi_participant_codecType", "jabber:client")?.let {
if (it is StandardExtensionElement) {
val codec = it.text.lowercase()
if (codec == "vp8") {
listOf(codec)
} else {
listOf(codec, "vp8")
}
} else {
videoCodecs = codecList
null
}
}
if (!firstPresence && newVideoCodecs != videoCodecs) {
// Allowing this to change would mess up visitor codec preference counts, ignore the change
if (role == MemberRole.VISITOR && presence.type != Presence.Type.unavailable && newVideoCodecs != null) {
logger.warn("Visitor video codec list changed from $videoCodecs to $newVideoCodecs - not supported!")
}
} else {
videoCodecs = newVideoCodecs
}
}

override fun toString() = "ChatMember[id=$name role=$role]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ default JibriSipGateway getJibriSipGateway()
/**
* Used for av moderation, when we want to mute all participants.
* @param mediaType the media type we want to mute.
* @param actor the entity that requested the mute.
*/
void muteAllParticipants(MediaType mediaType);
void muteAllParticipants(MediaType mediaType, EntityFullJid actor);

/**
* Return {@code true} if the user with the given JID should be allowed to invite jigasi to this conference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ else if (member.isJigasi())
/**
* Mutes all participants (except jibri or jigasi without "audioMute" support). Will block for colibri responses.
*/
public void muteAllParticipants(MediaType mediaType)
public void muteAllParticipants(MediaType mediaType, EntityFullJid actor)
{
Set<Participant> participantsToMute = new HashSet<>();
synchronized (participantLock)
Expand All @@ -1659,6 +1659,12 @@ public void muteAllParticipants(MediaType mediaType)
continue;
}

// we skip the participant that enabled the av moderation
if (participant.getMucJid().equals(actor))
{
continue;
}

participantsToMute.add(participant);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class AvModerationHandler(
logger.info(
"Moderation for $mediaType in $conferenceJid was enabled by ${incomingJson["actor"]}"
)
// let's mute everyone
conference.muteAllParticipants(mediaType)
// let's mute everyone except the actor
conference.muteAllParticipants(
mediaType,
JidCreate.entityFullFrom(incomingJson["actor"]?.toString())
)
}
}
incomingJson["whitelists"]?.let {
Expand Down

0 comments on commit ae76ef8

Please sign in to comment.