@@ -111,17 +111,53 @@ public void createAudioRoom(String sessionId, String handleId, int roomId) {
111111 restTemplate .postForEntity (handleUrl , request , JsonNode .class );
112112 }
113113
114- public JsonNode joinAudioRoom (String sessionId , String handleId , int roomId , String displayName ) {
115- Map <String , Object > body = Map .of (
116- "request" , "join" , "room" , roomId , "display" , displayName
117- );
118- Map <String , Object > request = Map .of (
119- "janus" , "message" , "transaction" , UUID .randomUUID ().toString (), "body" , body
120- );
114+ public void joinAudioRoom (String sessionId , String handleId , int roomId , String displayName ) {
115+ Map <String , Object > body = Map .of ("request" , "join" , "room" , roomId , "display" , displayName );
116+ Map <String , Object > request = Map .of ("janus" , "message" , "transaction" , UUID .randomUUID ().toString (), "body" , body );
121117 String handleUrl = String .format ("%s/%s/%s" , janusUrl , sessionId , handleId );
122118
123119 ResponseEntity <JsonNode > response = restTemplate .postForEntity (handleUrl , request , JsonNode .class );
124- logger .info ("Janus join response: {}" , response .getBody ());
120+ JsonNode respBody = response .getBody ();
121+ logger .info ("Janus join response: {}" , respBody );
122+
123+ JsonNode participantsNode = respBody != null
124+ ? respBody .path ("plugindata" ).path ("data" ).path ("participants" )
125+ : null ;
126+ if (participantsNode != null && !participantsNode .isMissingNode () && participantsNode .isArray ()) {
127+ return ;
128+ }
129+
130+ JsonNode listResp ;
131+ int attempts = 3 ;
132+ for (int i = 0 ; i < attempts ; i ++) {
133+ try {
134+ listResp = listParticipants (sessionId , handleId , roomId );
135+ if (listResp != null ) {
136+ JsonNode listParticipantsNode = listResp .path ("plugindata" ).path ("data" ).path ("participants" );
137+ if (listParticipantsNode != null && listParticipantsNode .isArray () && !listParticipantsNode .isEmpty ()) {
138+ logger .info ("Found participants via listparticipants on attempt {}" , i + 1 );
139+ return ;
140+ }
141+ }
142+ } catch (Exception ex ) {
143+ logger .warn ("listparticipants attempt {} failed: {}" , i + 1 , ex .getMessage ());
144+ }
145+ try {
146+ Thread .sleep (200L );
147+ } catch (InterruptedException ie ) {
148+ Thread .currentThread ().interrupt ();
149+ break ;
150+ }
151+ }
152+ logger .info ("Returning join response without participants." );
153+ }
154+
155+ public JsonNode listParticipants (String sessionId , String handleId , int roomId ) {
156+ String handleUrl = String .format ("%s/%s/%s" , janusUrl , sessionId , handleId );
157+ Map <String , Object > body = Map .of ("request" , "listparticipants" , "room" , roomId );
158+ Map <String , Object > request = Map .of ("janus" , "message" , "transaction" , UUID .randomUUID ().toString (), "body" , body );
159+ ResponseEntity <JsonNode > response = restTemplate .postForEntity (handleUrl , request , JsonNode .class );
160+ logger .info ("Janus listparticipants response: {}" , response .getBody ());
125161 return response .getBody ();
126162 }
127163
0 commit comments