Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.jootalkpia.signaling_server.model;

public record MessageToKafka() {
public record MessageToKafka(
Long channelId,
String status
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.kurento.client.IceCandidate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
@Slf4j
Expand Down Expand Up @@ -77,4 +82,16 @@ private void leaveRoom(UserSession userSession) {
huddleManager.removeHuddle(huddle);
}
}

@GetMapping("/api/v1/huddle/{channelId}")
public ResponseEntity<?> getHuddleStatus(@PathVariable("channelId") Long channelId) {
String isHuddleOn = huddleManager.getHuddleStatus(channelId) ? "on" : "off";

Map<String, Object> response = new HashMap<>();
response.put("channelId", channelId);
response.put("status", isHuddleOn);

return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jootalkpia.signaling_server.rtc;

import com.jootalkpia.signaling_server.model.MessageToKafka;
import com.jootalkpia.signaling_server.service.KafkaProducer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand All @@ -17,6 +19,7 @@ public class HuddleManager {
private final KurentoClient kurento;
private final SimpMessagingTemplate messagingTemplate;
private final ConcurrentMap<Long, Huddle> huddles = new ConcurrentHashMap<>();
private final KafkaProducer kafkaProducer;

public Huddle getHuddle(Long channelId) {
log.debug("Searching for channelId {}", channelId);
Expand All @@ -25,12 +28,23 @@ public Huddle getHuddle(Long channelId) {
if (huddle == null) {
log.debug("channelId {} not existent. Will create now!", channelId);
huddle = new Huddle(channelId, kurento.createMediaPipeline(), messagingTemplate);

MessageToKafka messageToKafka = new MessageToKafka(channelId, "on");
kafkaProducer.sendHuddleStatusMessage(messageToKafka);

huddles.put(channelId, huddle);
}
log.debug("channelId {} found!", channelId);
return huddle;
}

public boolean getHuddleStatus(Long channelId) {
if (huddles.get(channelId) != null) {
return true;
}
return false;
}

public void removeHuddle(Huddle huddle) {
this.huddles.remove(huddle.getChannelId());
huddle.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ public class KafkaProducer {
private final Gson gson = new Gson();
private final KafkaTemplate<String, String> kafkaTemplate;

public void sendHurdleStatusMessage(MessageToKafka messageToKafka) { // 미르님 원하는 DTO로 변경 필수
String jsonHurdleStatusMessage = gson.toJson(messageToKafka);
public void sendHuddleStatusMessage(MessageToKafka messageToKafka) {
String jsonHuddleStatusMessage = gson.toJson(messageToKafka);

kafkaTemplate.send("jootalkpia.huddle.prd.status", jsonHurdleStatusMessage).whenComplete((result, ex) -> {
kafkaTemplate.send("jootalkpia.huddle.prd.status", jsonHuddleStatusMessage).whenComplete((result, ex) -> {
if (ex == null) {
log.info(result.toString());
} else {
log.error(ex.getMessage(), ex); //추후 예외처리
}
});

log.info("message to kafka for channelId {} sent! ", messageToKafka.channelId(), messageToKafka.status());
}
}