Skip to content

Commit e637034

Browse files
committed
feat: Handles demote request.
1 parent cce0fe2 commit e637034

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

src/main/java/org/jitsi/jigasi/JvbConference.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ private ExtensionElement addSupportedFeatures(
414414
*/
415415
private final RoomMetadataListener roomMetadataListener = new RoomMetadataListener();
416416

417+
/**
418+
* Listens for messages from visitors component.
419+
*/
420+
private final VisitorsMessagesListener visitorsMessagesListener = new VisitorsMessagesListener();
421+
417422
/**
418423
* The features for the current xmpp provider we will use later adding to the room presence we send.
419424
*/
@@ -848,6 +853,18 @@ private void discoverComponentAddresses()
848853
MessageTypeFilter.NORMAL,
849854
FromMatchesFilter.create(JidCreate.domainBareFrom(roomMetadataIdentity.getName()))));
850855
}
856+
857+
DiscoverInfo.Identity visitorsIdentity = info.getIdentities().stream().
858+
filter(di -> di.getCategory().equals("component") && di.getType().equals("visitors"))
859+
.findFirst().orElse(null);
860+
861+
if (visitorsIdentity != null && !this.isTranscriber)
862+
{
863+
getConnection().addAsyncStanzaListener(visitorsMessagesListener,
864+
new AndFilter(
865+
MessageTypeFilter.CHAT,
866+
FromMatchesFilter.create(JidCreate.domainBareFrom(visitorsIdentity.getName()))));
867+
}
851868
}
852869
catch(Exception e)
853870
{
@@ -1274,6 +1291,7 @@ private void leaveConferenceRoom()
12741291
{
12751292
connection.removeAsyncStanzaListener(roomConfigurationListener);
12761293
connection.removeAsyncStanzaListener(roomMetadataListener);
1294+
connection.removeAsyncStanzaListener(visitorsMessagesListener);
12771295
}
12781296

12791297
// remove listener needs to be after leave,
@@ -2243,6 +2261,44 @@ private void processRoomMetadataJson(String json)
22432261
}
22442262
}
22452263

2264+
/**
2265+
* Process received demote request. Leaves the current room and keeps the connection
2266+
* as we will send the invite to jicofo with the request to be visitor.
2267+
* After the response the visitor's logic will kick in with disconnecting and connecting to the visitor's node.
2268+
* @param json The received json.
2269+
*/
2270+
private void processVisitorsJson(String json)
2271+
{
2272+
try
2273+
{
2274+
Object o = new JSONParser().parse(json);
2275+
2276+
if (o instanceof JSONObject)
2277+
{
2278+
JSONObject data = (JSONObject) o;
2279+
2280+
if (data.get("type").equals("visitors")
2281+
&& data.get("action").equals("demote-request")
2282+
&& data.get("id").equals(this.mucRoom.getUserNickname()))
2283+
{
2284+
logger.info(callContext + " Received demote request to become visitor from: "
2285+
+ data.get("actor"));
2286+
2287+
this.leaveConferenceRoom();
2288+
2289+
this.callContext.setRequestVisitor(true);
2290+
2291+
logger.info(callContext + " Will join requesting to be visitor.");
2292+
this.joinConferenceRoom();
2293+
}
2294+
}
2295+
}
2296+
catch(Exception e)
2297+
{
2298+
logger.error(callContext + " Error parsing", e);
2299+
}
2300+
}
2301+
22462302
/**
22472303
* Threads handles the timeout for stopping the conference.
22482304
* For waiting for conference call invite sent by the focus or for waiting
@@ -2626,4 +2682,23 @@ private void dropCall()
26262682
stop();
26272683
}
26282684
}
2629-
}
2685+
2686+
/**
2687+
* Listening for visitor's messages.
2688+
*/
2689+
private class VisitorsMessagesListener
2690+
implements StanzaListener
2691+
{
2692+
@Override
2693+
public void processStanza(Stanza stanza)
2694+
{
2695+
JsonMessageExtension jsonMsg = stanza.getExtension(JsonMessageExtension.class);
2696+
2697+
if (jsonMsg == null)
2698+
{
2699+
return;
2700+
}
2701+
2702+
processVisitorsJson(jsonMsg.getJson());
2703+
}
2704+
}}

0 commit comments

Comments
 (0)