Skip to content

Commit

Permalink
fix: Wait for disconnect response before leaving visitor room.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Sep 18, 2024
1 parent 1effdfd commit fb36cc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2302,8 +2302,19 @@ public void roomDestroyed(String reason)
if (chatRoomToLeave != null)
{
ChatRoom finalChatRoom = chatRoomToLeave;
final String finalVnode = vnode;

TaskPools.getIoPool().submit(() ->
{
IQ disconnectResponse
= jicofoServices.getXmppServices().getVisitorsManager().sendIqToComponentAndGetResponse(
roomName,
Collections.singletonList(new DisconnectVnodePacketExtension(finalVnode)));
if (disconnectResponse == null || !disconnectResponse.getType().equals(IQ.Type.result))
{
logger.warn("Error or no response to disconnect request: " + disconnectResponse);
}

try
{
logger.info("Removing visitor chat room");
Expand All @@ -2315,11 +2326,6 @@ public void roomDestroyed(String reason)
}
});

if (vnode != null)
{
jicofoServices.getXmppServices().getVisitorsManager().sendIqToComponent(
roomName, Collections.singletonList(new DisconnectVnodePacketExtension(vnode)));
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/VisitorsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@ class VisitorsManager(
logger.info("VisitorsComponentManager is now ${if (enabled) "en" else "dis"}abled with address $address")
}

fun sendIqToComponent(roomJid: EntityBareJid, extensions: List<ExtensionElement>) {
private fun createIq(roomJid: EntityBareJid, extensions: List<ExtensionElement>): VisitorsIq {
val address = this.address ?: throw Exception("Component not available.")
val iq = VisitorsIq.Builder(xmppProvider.xmppConnection).apply {
return VisitorsIq.Builder(xmppProvider.xmppConnection).apply {
to(address)
ofType(IQ.Type.get)
room = roomJid
addExtensions(extensions)
}.build()
}

/** Send an IQ, block for response or timeout, return the result. */
fun sendIqToComponentAndGetResponse(roomJid: EntityBareJid, extensions: List<ExtensionElement>): IQ? =
xmppProvider.xmppConnection.sendIqAndGetResponse(createIq(roomJid, extensions))

/** Send an IQ, return immediately. Log an error if there's no response. */
fun sendIqToComponent(roomJid: EntityBareJid, extensions: List<ExtensionElement>) {
TaskPools.ioPool.submit {
val response = xmppProvider.xmppConnection.sendIqAndGetResponse(iq)
val response = sendIqToComponentAndGetResponse(roomJid, extensions)
when {
response == null -> logger.warn("Timeout waiting for VisitorsIq response.")
response.type == IQ.Type.result -> {
Expand Down

0 comments on commit fb36cc4

Please sign in to comment.