Skip to content

Commit

Permalink
feat: Read visitor configuration from MUC config form. (jitsi#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev authored Dec 13, 2023
1 parent 660d705 commit 713f6fb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ interface ChatRoom {
/** Whether a lobby is enabled for the room. Read from the MUC config form. */
val lobbyEnabled: Boolean

/** Whether the visitors feature is enabled for the room. Read from the MUC config form. */
val visitorsEnabled: Boolean?

/** The number of participants in the room after which new endpoints should be redirected to visitors.
* Read from the MUC config form. */
val participantsSoftLimit: Int?

val debugState: OrderedJsonObject

/** Returns the number of members that currently have their audio sources unmuted. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ class ChatRoomImpl(
}
}

override var visitorsEnabled: Boolean? = null
private set(value) {
if (value != field) {
logger.info("Visitors is now: $value")
field = value
}
}

override var participantsSoftLimit: Int? = null
private set(value) {
if (value != field) {
logger.info("ParticipantsSoftLimit is now $value.")
field = value
}
}

private val avModerationByMediaType = ConcurrentHashMap<MediaType, AvModerationForMediaType>()

/** The emitter used to fire events. */
Expand Down Expand Up @@ -262,6 +278,10 @@ class ChatRoomImpl(
private fun parseConfigForm(configForm: Form) {
lobbyEnabled =
configForm.getField(MucConfigFormManager.MUC_ROOMCONFIG_MEMBERSONLY)?.firstValue?.toBoolean() ?: false
visitorsEnabled =
configForm.getField(MucConfigFields.VISITORS_ENABLED)?.firstValue?.toBoolean()
participantsSoftLimit =
configForm.getField(MucConfigFields.PARTICIPANTS_SOFT_LIMIT)?.firstValue?.toInt()
}

override fun leave() {
Expand Down Expand Up @@ -544,6 +564,8 @@ class ChatRoomImpl(
const val MAIN_ROOM = "muc#roominfo_breakout_main_room"
const val MEETING_ID = "muc#roominfo_meetingId"
const val WHOIS = "muc#roomconfig_whois"
const val PARTICIPANTS_SOFT_LIMIT = "muc#roominfo_participantsSoftLimit"
const val VISITORS_ENABLED = "muc#roominfo_visitorsEnabled"
}

internal inner class MemberListener : ParticipantStatusListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ public String redirectVisitor(boolean visitorRequested)

// We don't support both visitors and a lobby. Once a lobby is enabled we don't use visitors anymore.
ChatRoom chatRoom = this.chatRoom;
if (chatRoom != null && chatRoom.getLobbyEnabled())
if (chatRoom != null && (chatRoom.getLobbyEnabled() || Boolean.FALSE.equals(chatRoom.getVisitorsEnabled())))
{
return null;
}
Expand All @@ -1688,13 +1688,19 @@ public String redirectVisitor(boolean visitorRequested)
}

long participantCount = getUserParticipantCount();
boolean visitorsAlreadyUsed = false;
boolean visitorsAlreadyUsed;
synchronized (visitorChatRooms)
{
visitorsAlreadyUsed = !visitorChatRooms.isEmpty();
}

if (visitorsAlreadyUsed || visitorRequested || participantCount >= VisitorsConfig.config.getMaxParticipants())
int participantsSoftLimit = VisitorsConfig.config.getMaxParticipants();
if (chatRoom != null && chatRoom.getParticipantsSoftLimit() != null && chatRoom.getParticipantsSoftLimit() > 0)
{
participantsSoftLimit = chatRoom.getParticipantsSoftLimit();
}

if (visitorsAlreadyUsed || visitorRequested || participantCount >= participantsSoftLimit)
{
return selectVisitorNode();
}
Expand Down

0 comments on commit 713f6fb

Please sign in to comment.