Skip to content

Commit

Permalink
feat: 방 존재하지 않을시 즉석으로 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
starwook committed Jan 25, 2024
1 parent 400217e commit 37a12fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class WebSocketMessage {
private String type; //메시지 타입
private String roomId;
private Object candidate; //상태
private Object sdp; //sdp 정보
private Object sdp; //sdp 정보( sdp란 비디오의 해상도 , 오디오 전송 또는 수신 여부 등등)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public class SignalHandler extends TextWebSocketHandler {
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
try{
String roomId = session.getUri().toString().split("/signal/")[1];
logger.debug("roomId:"+roomId);
WebSocketMessage webSocketMessage = WebSocketMessage.builder()
.fromUserId("Server") //임시
.type(MSG_TYPE_JOIN)
.roomId("1")
.roomId(roomId)
.candidate(null)
.sdp(null)
.build();
Expand Down Expand Up @@ -77,10 +79,22 @@ protected void handleTextMessage(WebSocketSession session, TextMessage textMessa
logger.debug(message.getType()+"/"+message.getFromUserId());
String userId = message.getFromUserId();
String roomId = message.getRoomId();

ChatroomDto findRoom = rooms.get(roomId);

if(findRoom==null) {
Map<String,WebSocketSession> clients = new HashMap<>();
findRoom = ChatroomDto.builder()
.roomId(roomId)
.clients(clients)
.build();
//임시적으로 방 만들기
rooms.put(roomId,findRoom);
}


switch (message.getType()){
case MSG_TYPE_OFFER:
case MSG_TYPE_ANSWER:
case MSG_TYPE_ICE: // 상대방을 찾는 상황
Object candidate = message.getCandidate();
Object sdp = message.getSdp();
Expand All @@ -106,6 +120,7 @@ protected void handleTextMessage(WebSocketSession session, TextMessage textMessa
logger.debug(userId+"가 방에 참여하였습니다"+message.getRoomId());
// room에 user 추가
rtcService.addClients(findRoom,userId,session);
break;

case MSG_TYPE_LEAVE:
Optional<String> client = rtcService.getClients(findRoom).keySet().stream()
Expand Down

0 comments on commit 37a12fc

Please sign in to comment.