Skip to content

Commit

Permalink
REST endpoint for /colibri/muc-client/ids to get list of added muc cl…
Browse files Browse the repository at this point in the history
…ient ids
  • Loading branch information
shawnchin committed May 27, 2021
1 parent abde4c3 commit a42b631
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Expand Up @@ -74,4 +74,12 @@ public Response removeMucClient(String requestBody) throws ParseException
}
return Response.status(HttpServletResponse.SC_BAD_REQUEST).build();
}

@Path("/ids")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getIds()
{
return xmppConnection.getMucClientIds();
}
}
12 changes: 12 additions & 0 deletions jvb/src/main/kotlin/org/jitsi/videobridge/xmpp/XmppConnection.kt
Expand Up @@ -33,6 +33,7 @@ import org.jivesoftware.smack.packet.ExtensionElement
import org.jivesoftware.smack.packet.IQ
import org.jivesoftware.smack.packet.XMPPError
import org.jivesoftware.smackx.iqversion.packet.Version
import org.json.simple.JSONArray
import org.json.simple.JSONObject
import java.util.concurrent.atomic.AtomicBoolean

Expand Down Expand Up @@ -129,6 +130,17 @@ class XmppConnection : IQListener {
return true
}

/**
* Returns ids of [MucClient] that have been added.
* @return JSON string of the list of ids
*/
fun getMucClientIds(): String {
val jsonArray = JSONArray()
mucClientManager.getMucClientIds().forEach { id -> jsonArray.add(id) }

return jsonArray.toJSONString()
}

/**
* Removes a {@link MucClient} with an ID described in JSON.
* @param jsonObject the JSON which contains the ID of the client to remove.
Expand Down
Expand Up @@ -26,6 +26,7 @@ import org.glassfish.jersey.test.JerseyTest
import org.glassfish.jersey.test.TestProperties
import org.jitsi.videobridge.rest.MockBinder
import org.jitsi.videobridge.xmpp.XmppConnection
import org.json.simple.JSONArray
import org.json.simple.JSONObject
import org.junit.Test
import javax.ws.rs.client.Entity
Expand Down Expand Up @@ -91,25 +92,37 @@ class MucClientTest : JerseyTest() {
fun testRemoveMuc() {
val jsonConfigSlot = slot<JSONObject>()

every { xmppConnection.addMucClient(capture(jsonConfigSlot)) } returns true
every { xmppConnection.removeMucClient(capture(jsonConfigSlot)) } returns true

val json = JSONObject().apply {
put("id", "id")
}

val resp = target("$baseUrl/add").request().post(Entity.json(json.toJSONString()))
val resp = target("$baseUrl/remove").request().post(Entity.json(json.toJSONString()))
resp.status shouldBe HttpStatus.OK_200
jsonConfigSlot.captured shouldBe json
}

@Test
fun testRemoveMucFailure() {
every { xmppConnection.addMucClient(any()) } returns false
every { xmppConnection.removeMucClient(any()) } returns false

val json = JSONObject().apply {
put("id", "id")
}
val resp = target("$baseUrl/add").request().post(Entity.json(json.toJSONString()))
val resp = target("$baseUrl/remove").request().post(Entity.json(json.toJSONString()))
resp.status shouldBe HttpStatus.BAD_REQUEST_400
}

@Test
fun testGetIds() {
val fakeIds = JSONArray().apply {
add("id1")
}
every { xmppConnection.getMucClientIds() } returns fakeIds.toJSONString()

val resp = target("$baseUrl/ids").request().get()
resp.readEntity(String::class.java) shouldBe "[\"id1\"]"
}

}

0 comments on commit a42b631

Please sign in to comment.