|
11 | 11 | import org.springframework.web.bind.annotation.*; |
12 | 12 | import org.slf4j.Logger; |
13 | 13 | import org.slf4j.LoggerFactory; |
14 | | - |
| 14 | +import com.fasterxml.jackson.databind.JsonNode; |
| 15 | +import java.util.ArrayList; |
15 | 16 | import java.util.List; |
16 | 17 | import java.util.Map; |
17 | 18 | import java.util.UUID; |
@@ -54,25 +55,34 @@ public ResponseEntity<?> createVoiceRoom( |
54 | 55 |
|
55 | 56 | @PostMapping("/join") |
56 | 57 | public ResponseEntity<?> joinVoiceRoom( |
57 | | - @RequestParam int janusRoomId, |
58 | | - @RequestParam String displayName) { |
| 58 | + @RequestParam int janusRoomId, |
| 59 | + @RequestParam String displayName) { |
59 | 60 |
|
60 | 61 | try { |
61 | 62 | String sessionId = janusService.createSession(); |
62 | 63 | String handleId = janusService.attachAudioBridgePlugin(sessionId); |
63 | | - janusService.joinAudioRoom(sessionId, handleId, janusRoomId, displayName); |
64 | 64 |
|
65 | | - return ResponseEntity.ok(Map.of( |
66 | | - "message", "Joined voice room successfully", |
67 | | - "janusRoomId", janusRoomId, |
68 | | - "sessionId", sessionId, |
69 | | - "handleId", handleId |
70 | | - )); |
71 | | - } |
72 | | - catch (Exception e) { |
| 65 | + JsonNode janusResponse = janusService.joinAudioRoom(sessionId, handleId, janusRoomId, displayName); |
| 66 | + |
| 67 | + JsonNode participantsNode = janusResponse.path("plugindata").path("data").path("participants"); |
| 68 | + |
| 69 | + Map<String, Object> responseData = new java.util.HashMap<>(); |
| 70 | + responseData.put("message", "Joined voice room successfully"); |
| 71 | + responseData.put("janusRoomId", janusRoomId); |
| 72 | + responseData.put("sessionId", sessionId); |
| 73 | + responseData.put("handleId", handleId); |
| 74 | + if (participantsNode.isArray()) { |
| 75 | + responseData.put("participants", participantsNode); |
| 76 | + } else { |
| 77 | + responseData.put("participants", new ArrayList<>()); |
| 78 | + } |
| 79 | + |
| 80 | + return ResponseEntity.ok(responseData); |
| 81 | + |
| 82 | + } catch (Exception e) { |
73 | 83 | logger.error("Error joining voice room: {}", e.getMessage(), e); |
74 | 84 | return ResponseEntity.status(500) |
75 | | - .body(Map.of("error", "Failed to join voice room", "message", e.getMessage())); |
| 85 | + .body(Map.of("error", "Failed to join room", "message", e.getMessage())); |
76 | 86 | } |
77 | 87 | } |
78 | 88 |
|
|
0 commit comments