Skip to content

Commit 4a035ea

Browse files
committed
[FIX] 스터디룸 인원수 로직 수정
1 parent f17d1c2 commit 4a035ea

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/main/java/com/example/be/web/controller/OpenviduController.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") Str
5656
try {
5757
WebhookEvent event = webhookReceiver.receive(body, authHeader);
5858
String roomName = event.getRoom().getName();
59-
int roomParticipantCount = event.getRoom().getNumParticipants();
6059
long createAt = event.getRoom().getCreationTime();
6160

6261
log.info("LiveKit Webhook Event: {}", event.getEvent());
@@ -82,28 +81,21 @@ public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") Str
8281
case "participant_joined" -> {
8382
Room room = roomRepository.findByTitle(roomName);
8483
if (room != null) {
85-
if (roomParticipantCount == 0) {
86-
room.setParticipantCount(1);
84+
room.setParticipantCount(room.getParticipantCount()+1);
8785
roomRepository.save(room);
8886
log.info("Participant joined. Current count: {}", room.getParticipantCount());
89-
}
90-
else {
91-
room.setParticipantCount(roomParticipantCount);
92-
roomRepository.save(room);
93-
log.info("Participant joined. Current count: {}", roomParticipantCount);
94-
}
9587
}
9688
}
9789
case "participant_left" -> {
9890
Room room = roomRepository.findByTitle(roomName);
9991
if (room != null) {
100-
if (roomParticipantCount == 0) {
92+
if (room.getParticipantCount() <= 1) {
10193
roomRepository.delete(room);
10294
log.info("Room deleted (LiveKit reported 0): {}", roomName);
10395
} else {
104-
room.setParticipantCount(roomParticipantCount);
96+
room.setParticipantCount(room.getParticipantCount()-1);
10597
roomRepository.save(room);
106-
log.info("Participant left. Room: {}, Current count: {}", roomName, roomParticipantCount);
98+
log.info("Participant left. Room: {}, Current count: {}", roomName, room.getParticipantCount());
10799
}
108100
}
109101
}

0 commit comments

Comments
 (0)