diff --git a/src/main/java/com/api/farmingsoon/common/interceptor/StompInterceptor.java b/src/main/java/com/api/farmingsoon/common/interceptor/StompInterceptor.java index dd056c2..4d71590 100644 --- a/src/main/java/com/api/farmingsoon/common/interceptor/StompInterceptor.java +++ b/src/main/java/com/api/farmingsoon/common/interceptor/StompInterceptor.java @@ -45,7 +45,6 @@ public Message preSend(Message message, MessageChannel channel) { ); else if (StompCommand.DISCONNECT.equals(command)) { eventPublisher.publishEvent(ChatRoomDisConnectEvent.builder() - .chatRoomId(Long.valueOf(accessor.getFirstNativeHeader("chatRoomId"))) .sessionId(accessor.getSessionId()) .build()); } diff --git a/src/main/java/com/api/farmingsoon/common/redis/RedisService.java b/src/main/java/com/api/farmingsoon/common/redis/RedisService.java index 2de2fd0..ef86fd5 100644 --- a/src/main/java/com/api/farmingsoon/common/redis/RedisService.java +++ b/src/main/java/com/api/farmingsoon/common/redis/RedisService.java @@ -25,6 +25,9 @@ public void initialize() { public void setData(String key, Object value, Long time,TimeUnit timeUnit) { redisTemplate.opsForValue().set(key, value.toString(), time, timeUnit); } + public void setData(String key, Object value) { + redisTemplate.opsForValue().set(key, value.toString()); + } public Object getData(String key) { return redisTemplate.opsForValue().get(key); diff --git a/src/main/java/com/api/farmingsoon/domain/chatroom/listener/ChatRoomEventListener.java b/src/main/java/com/api/farmingsoon/domain/chatroom/listener/ChatRoomEventListener.java index c3ee8ff..2c1e21b 100644 --- a/src/main/java/com/api/farmingsoon/domain/chatroom/listener/ChatRoomEventListener.java +++ b/src/main/java/com/api/farmingsoon/domain/chatroom/listener/ChatRoomEventListener.java @@ -35,7 +35,7 @@ public void readAllChatAndSaveConnectMember(ChatRoomConnectEvent event){ @EventListener public void deleteConnectMember(ChatRoomDisConnectEvent event){ - chatRoomRedisService.disConnectChatRoom(event.getChatRoomId(), event.getSessionId()); + chatRoomRedisService.disConnectChatRoom(event.getSessionId()); } } diff --git a/src/main/java/com/api/farmingsoon/domain/chatroom/service/ChatRoomRedisService.java b/src/main/java/com/api/farmingsoon/domain/chatroom/service/ChatRoomRedisService.java index 940a139..b756420 100644 --- a/src/main/java/com/api/farmingsoon/domain/chatroom/service/ChatRoomRedisService.java +++ b/src/main/java/com/api/farmingsoon/domain/chatroom/service/ChatRoomRedisService.java @@ -14,16 +14,20 @@ public class ChatRoomRedisService { public void connectChatRoom(Long chatRoomId, String sessionId) { log.info("Chatroom Connect : chatRoomId = " + chatRoomId + " sessionId = " + sessionId); redisService.addToSet("chatRoom_" + chatRoomId, sessionId); + redisService.setData(sessionId, chatRoomId); // session에 대한 채팅방 정보 저장 } /** * 채팅방에 남은 사람이 한명이라면 나갈 때 키 삭제 */ - public void disConnectChatRoom(Long chatRoomId, String sessionId) { + public void disConnectChatRoom(String sessionId) { + Long chatRoomId = (Long) redisService.getData(sessionId); if(redisService.getSetSize("chatRoom_" + chatRoomId) == 1){ redisService.deleteData("chatRoom_" + chatRoomId); } - redisService.deleteToSet("chatRoom_" + chatRoomId, sessionId); + else { + redisService.deleteToSet("chatRoom_" + chatRoomId, sessionId); + } log.info("Chatroom DisConnect : chatRoomId = " + chatRoomId + " sessionId = " + sessionId); } public Long getConnectMemberSize(String key){