Skip to content

Commit

Permalink
feat: Handles demote request.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 15, 2024
1 parent cce0fe2 commit 2593583
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ private ExtensionElement addSupportedFeatures(
*/
private final RoomMetadataListener roomMetadataListener = new RoomMetadataListener();

/**
* Listens for messages from visitors component.
*/
private final VisitorsMessagesListener visitorsMessagesListener = new VisitorsMessagesListener();

/**
* The features for the current xmpp provider we will use later adding to the room presence we send.
*/
Expand Down Expand Up @@ -848,6 +853,18 @@ private void discoverComponentAddresses()
MessageTypeFilter.NORMAL,
FromMatchesFilter.create(JidCreate.domainBareFrom(roomMetadataIdentity.getName()))));
}

DiscoverInfo.Identity visitorsIdentity = info.getIdentities().stream().
filter(di -> di.getCategory().equals("component") && di.getType().equals("visitors"))
.findFirst().orElse(null);

if (visitorsIdentity != null && !this.isTranscriber)
{
getConnection().addAsyncStanzaListener(visitorsMessagesListener,
new AndFilter(
MessageTypeFilter.CHAT,
FromMatchesFilter.create(JidCreate.domainBareFrom(visitorsIdentity.getName()))));
}
}
catch(Exception e)
{
Expand Down Expand Up @@ -1274,6 +1291,7 @@ private void leaveConferenceRoom()
{
connection.removeAsyncStanzaListener(roomConfigurationListener);
connection.removeAsyncStanzaListener(roomMetadataListener);
connection.removeAsyncStanzaListener(visitorsMessagesListener);
}

// remove listener needs to be after leave,
Expand Down Expand Up @@ -2243,6 +2261,44 @@ private void processRoomMetadataJson(String json)
}
}

/**
* Process received demote request. Leaves the current room and keeps the connection
* as we will send the invite to jicofo with the request to be visitor.
* After the response the visitor's logic will kick in with disconnecting and connecting to the visitor's node.
* @param json The received json.
*/
private void processVisitorsJson(String json)
{
try
{
Object o = new JSONParser().parse(json);

if (o instanceof JSONObject)
{
JSONObject data = (JSONObject) o;

if (data.get("type").equals("visitors")
&& data.get("action").equals("demote-request")
&& data.get("id").equals(this.mucRoom.getUserNickname()))
{
logger.info(callContext + " Received demote request to become visitor from: "
+ data.get("actor"));

this.leaveConferenceRoom();

this.callContext.setRequestVisitor(true);

logger.info(callContext + " Will join requesting to be visitor.");
this.joinConferenceRoom();
}
}
}
catch(Exception e)
{
logger.error(callContext + " Error parsing", e);
}
}

/**
* Threads handles the timeout for stopping the conference.
* For waiting for conference call invite sent by the focus or for waiting
Expand Down Expand Up @@ -2626,4 +2682,23 @@ private void dropCall()
stop();
}
}
}

/**
* Listening for visitor's messages.
*/
private class VisitorsMessagesListener
implements StanzaListener
{
@Override
public void processStanza(Stanza stanza)
{
JsonMessageExtension jsonMsg = stanza.getExtension(JsonMessageExtension.class);

if (jsonMsg == null)
{
return;
}

processVisitorsJson(jsonMsg.getJson());
}
}}

0 comments on commit 2593583

Please sign in to comment.