Skip to content

Commit 860b639

Browse files
authored
feat: Read list of main room participants, do not redirect them. (#1227)
* feat: Read conference request token. * feat: Parse mainRoomParticipants from metadata. * feat: Send main room participants to main room. * chore: Bump jicoco.
1 parent 5771354 commit 860b639

File tree

10 files changed

+111
-15
lines changed

10 files changed

+111
-15
lines changed

jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoom.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ interface ChatRoom {
7373
/** Returns the number of members that currently have their video sources unmuted. */
7474
var videoSendersCount: Int
7575

76+
val mainRoomParticipants: List<String>
77+
7678
/**
7779
* Joins this chat room with the preconfigured nickname. Returns the fields read from the MUC config form after
7880
* joining.

jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class ChatRoomImpl(
163163
}
164164
}
165165

166+
override var mainRoomParticipants: List<String> = emptyList()
167+
private set
168+
166169
private val avModerationByMediaType = ConcurrentHashMap<MediaType, AvModerationForMediaType>()
167170

168171
/** The emitter used to fire events. */
@@ -279,6 +282,7 @@ class ChatRoomImpl(
279282

280283
override fun setRoomMetadata(roomMetadata: RoomMetadata) {
281284
visitorsLive = roomMetadata.metadata?.visitors?.live == true
285+
mainRoomParticipants = roomMetadata.metadata?.mainMeetingParticipants ?: emptyList()
282286
roomMetadata.metadata?.startMuted?.let {
283287
eventEmitter.fireEvent { startMutedChanged(it.audio == true, it.video == true) }
284288
}

jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/RoomMetadata.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ data class RoomMetadata(
3535
val metadata: Metadata?
3636
) {
3737
@JsonIgnoreProperties(ignoreUnknown = true)
38-
data class Metadata(val visitors: Visitors?, val startMuted: StartMuted?) {
38+
data class Metadata(
39+
val visitors: Visitors?,
40+
val startMuted: StartMuted?,
41+
val mainMeetingParticipants: List<String>?
42+
) {
3943
@JsonIgnoreProperties(ignoreUnknown = true)
4044
data class Visitors(val live: Boolean?)
4145

jicofo-common/src/test/kotlin/org/jitsi/jicofo/xmpp/muc/RoomMetadataTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.jitsi.jicofo.xmpp.muc
1919

2020
import io.kotest.assertions.throwables.shouldThrow
2121
import io.kotest.core.spec.style.ShouldSpec
22+
import io.kotest.matchers.nulls.shouldNotBeNull
2223
import io.kotest.matchers.shouldBe
2324
import io.kotest.matchers.types.shouldBeInstanceOf
2425

@@ -61,6 +62,44 @@ class RoomMetadataTest : ShouldSpec() {
6162
parsed.shouldBeInstanceOf<RoomMetadata>()
6263
parsed.metadata!!.visitors shouldBe null
6364
}
65+
context("With visitors, mainMeetingParticipants, and startMuted") {
66+
RoomMetadata.parse(
67+
"""
68+
{
69+
"metadata": {
70+
"transcriberType": "EGHT_WHISPER",
71+
"visitors": {
72+
"live": true
73+
},
74+
"mainMeetingParticipants": [
75+
"user_id_1",
76+
"user_id_2"
77+
],
78+
"startMuted": {
79+
"audio": true
80+
}
81+
},
82+
"type": "room_metadata"
83+
}
84+
""".trimIndent()
85+
).apply {
86+
shouldBeInstanceOf<RoomMetadata>()
87+
metadata.apply {
88+
shouldNotBeNull()
89+
visitors.apply {
90+
shouldNotBeNull()
91+
live shouldBe true
92+
}
93+
mainMeetingParticipants shouldBe listOf("user_id_1", "user_id_2")
94+
startMuted.apply {
95+
shouldNotBeNull()
96+
audio shouldBe true
97+
video shouldBe null
98+
}
99+
}
100+
type shouldBe "room_metadata"
101+
}
102+
}
64103
}
65104
context("Invalid") {
66105
context("Missing type") {

jicofo/pom.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,24 @@
8484
<!-- org.jitsi -->
8585
<dependency>
8686
<groupId>${project.groupId}</groupId>
87-
<artifactId>jicoco-health-checker</artifactId>
87+
<artifactId>jicoco-config</artifactId>
8888
</dependency>
8989
<dependency>
9090
<groupId>${project.groupId}</groupId>
91-
<artifactId>jicoco-config</artifactId>
91+
<artifactId>jicoco-health-checker</artifactId>
9292
</dependency>
9393
<dependency>
9494
<groupId>${project.groupId}</groupId>
95-
<artifactId>jicoco-metrics</artifactId>
95+
<artifactId>jicoco-jwt</artifactId>
9696
</dependency>
9797
<dependency>
9898
<groupId>${project.groupId}</groupId>
9999
<artifactId>jitsi-metaconfig</artifactId>
100100
</dependency>
101+
<dependency>
102+
<groupId>${project.groupId}</groupId>
103+
<artifactId>jicoco-metrics</artifactId>
104+
</dependency>
101105
<dependency>
102106
<groupId>${project.groupId}</groupId>
103107
<artifactId>jitsi-utils</artifactId>
@@ -117,7 +121,6 @@
117121
<dependency>
118122
<groupId>com.fasterxml.jackson.module</groupId>
119123
<artifactId>jackson-module-kotlin</artifactId>
120-
<version>2.14.1</version>
121124
</dependency>
122125
<!-- https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations -->
123126
<dependency>

jicofo/src/main/java/org/jitsi/jicofo/conference/JitsiMeetConferenceImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ public int moveEndpoints(@NotNull Bridge bridge, int numEps)
17991799
* @return the name of the visitor node if it should be redirected, and null otherwise.
18001800
*/
18011801
@Nullable
1802-
public String redirectVisitor(boolean visitorRequested)
1802+
public String redirectVisitor(boolean visitorRequested, @Nullable String userId)
18031803
throws Exception
18041804
{
18051805
if (!VisitorsConfig.config.getEnabled())
@@ -1809,9 +1809,14 @@ public String redirectVisitor(boolean visitorRequested)
18091809

18101810
// We don't support both visitors and a lobby. Once a lobby is enabled we don't use visitors anymore.
18111811
ChatRoom chatRoom = this.chatRoom;
1812-
if (chatRoom != null && (chatRoom.getLobbyEnabled() || Boolean.FALSE.equals(chatRoom.getVisitorsEnabled())))
1812+
if (chatRoom != null)
18131813
{
1814-
return null;
1814+
if (chatRoom.getLobbyEnabled()
1815+
|| Boolean.FALSE.equals(chatRoom.getVisitorsEnabled())
1816+
|| (userId != null && chatRoom.getMainRoomParticipants().contains(userId)))
1817+
{
1818+
return null;
1819+
}
18151820
}
18161821
if (VisitorsConfig.config.getRequireMucConfigFlag())
18171822
{

jicofo/src/main/kotlin/org/jitsi/jicofo/ConferenceRequest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.jitsi.jicofo
1919

20+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
2021
import com.fasterxml.jackson.annotation.JsonInclude
2122
import com.fasterxml.jackson.core.JsonProcessingException
2223
import com.fasterxml.jackson.databind.JsonMappingException
@@ -30,6 +31,7 @@ import kotlin.jvm.Throws
3031
* The initial request to create or join a conference, a generic version of [ConferenceIq].
3132
*/
3233
@JsonInclude(JsonInclude.Include.NON_EMPTY)
34+
@JsonIgnoreProperties(ignoreUnknown = true)
3335
class ConferenceRequest(
3436
var room: String? = null,
3537
var ready: Boolean? = null,
@@ -41,7 +43,7 @@ class ConferenceRequest(
4143
val properties: MutableMap<String, String> = mutableMapOf()
4244
) {
4345
@Throws(XmppStringprepException::class)
44-
fun toConferenceIq() = ConferenceIq().apply {
46+
fun toConferenceIq(token: String? = null) = ConferenceIq().apply {
4547
this@ConferenceRequest.room?.let {
4648
room = JidCreate.entityBareFrom(it)
4749
}
@@ -63,6 +65,9 @@ class ConferenceRequest(
6365
this@ConferenceRequest.vnode?.let {
6466
vnode = it
6567
}
68+
token?.let {
69+
setToken(it)
70+
}
6671
this@ConferenceRequest.properties.forEach { (k, v) -> addProperty(k, v) }
6772
}
6873

jicofo/src/main/kotlin/org/jitsi/jicofo/ktor/Application.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import io.ktor.server.response.respond
3333
import io.ktor.server.response.respondText
3434
import io.ktor.server.routing.Route
3535
import io.ktor.server.routing.RoutingCall
36+
import io.ktor.server.routing.RoutingRequest
3637
import io.ktor.server.routing.get
3738
import io.ktor.server.routing.options
3839
import io.ktor.server.routing.post
@@ -160,8 +161,10 @@ class Application(
160161
throw BadRequest(e.message)
161162
}
162163

164+
val token = call.request.getToken()
165+
163166
val response: IQ = try {
164-
conferenceIqHandler.handleConferenceIq(request.toConferenceIq())
167+
conferenceIqHandler.handleConferenceIq(request.toConferenceIq(token))
165168
} catch (e: XmppStringprepException) {
166169
throw BadRequest("Invalid room name: ${e.message}")
167170
} catch (e: Exception) {
@@ -351,3 +354,13 @@ private fun translateException(block: () -> MoveResult): MoveResult {
351354
}
352355
}
353356
}
357+
358+
private fun RoutingRequest.getToken(): String? {
359+
return this.headers["Authorization"]?.let {
360+
if (it.startsWith("Bearer ")) {
361+
it.substring("Bearer ".length)
362+
} else {
363+
it
364+
}
365+
}
366+
}

jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/ConferenceIqHandler.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jitsi.jicofo.auth.AuthenticationAuthority
2323
import org.jitsi.jicofo.auth.ErrorFactory
2424
import org.jitsi.jicofo.metrics.JicofoMetricsContainer
2525
import org.jitsi.jicofo.visitors.VisitorsConfig
26+
import org.jitsi.jwt.JitsiToken
2627
import org.jitsi.utils.OrderedJsonObject
2728
import org.jitsi.utils.logging2.createLogger
2829
import org.jitsi.xmpp.extensions.jitsimeet.ConferenceIq
@@ -85,7 +86,7 @@ class ConferenceIqHandler(
8586
focusJid = focusAuthJid
8687
}
8788

88-
logger.info("Conference request for room $room, from ${query.from}")
89+
logger.info("Conference request for room $room, from ${query.from}, token=${query.token != null}")
8990
conferenceRequestCounter.inc()
9091
val conference = focusManager.getConference(room)
9192
val roomExists = conference != null
@@ -110,7 +111,7 @@ class ConferenceIqHandler(
110111
return response
111112
}
112113
val vnode = if (visitorSupported && visitorsManager.enabled) {
113-
conference?.redirectVisitor(visitorRequested)
114+
conference?.redirectVisitor(visitorRequested, query.token.readUserId())
114115
} else {
115116
null
116117
}
@@ -236,3 +237,17 @@ class ConferenceIqHandler(
236237
)
237238
}
238239
}
240+
241+
/**
242+
* Read context.user.id from an unparsed token. Note that no validation is performed on the token, this is intentional.
243+
* Validation will be performed when the user attempts to login to XMPP.
244+
*/
245+
private fun String?.readUserId(): String? = if (this.isNullOrEmpty()) {
246+
null
247+
} else {
248+
try {
249+
JitsiToken.parseWithoutValidation(this).context?.user?.id
250+
} catch (e: Throwable) {
251+
null
252+
}
253+
}

pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
<ktor.version>3.0.0</ktor.version>
4343
<kotest.version>5.7.2</kotest.version>
4444
<slf4j.version>1.7.32</slf4j.version>
45+
<jackson.version>2.19.0</jackson.version>
4546
<jitsi.utils.version>1.0-127-g6c65524</jitsi.utils.version>
46-
<jicoco.version>1.1-159-gf9c2712</jicoco.version>
47+
<jicoco.version>1.1-160-g4ad2288</jicoco.version>
4748
<ktlint-maven-plugin.version>3.0.0</ktlint-maven-plugin.version>
4849
<spotbugs.version>4.8.6</spotbugs.version>
4950
<spotbugs-maven-plugin.version>4.8.6.6</spotbugs-maven-plugin.version>
@@ -152,6 +153,11 @@
152153
<artifactId>jicoco-health-checker</artifactId>
153154
<version>${jicoco.version}</version>
154155
</dependency>
156+
<dependency>
157+
<groupId>${project.groupId}</groupId>
158+
<artifactId>jicoco-jwt</artifactId>
159+
<version>${jicoco.version}</version>
160+
</dependency>
155161
<dependency>
156162
<groupId>${project.groupId}</groupId>
157163
<artifactId>jicoco-metrics</artifactId>
@@ -170,7 +176,7 @@
170176
<dependency>
171177
<groupId>${project.groupId}</groupId>
172178
<artifactId>jitsi-xmpp-extensions</artifactId>
173-
<version>1.0-95-ge113e35</version>
179+
<version>1.0-96-gb0509fc</version>
174180
</dependency>
175181
<dependency>
176182
<groupId>org.slf4j</groupId>
@@ -185,7 +191,7 @@
185191
<dependency>
186192
<groupId>com.fasterxml.jackson.module</groupId>
187193
<artifactId>jackson-module-kotlin</artifactId>
188-
<version>2.14.1</version>
194+
<version>${jackson.version}</version>
189195
</dependency>
190196
<!-- https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations -->
191197
<dependency>

0 commit comments

Comments
 (0)