From 057080d0cac20fc833dddf9f8a465b6b4ddec5f1 Mon Sep 17 00:00:00 2001 From: LminWoo99 Date: Fri, 5 Jul 2024 12:23:52 +0900 Subject: [PATCH] refactor --- .../VideoChatting/config/RedisConfig.java | 9 -- .../VideoChatting/config/SslConfig.java | 46 --------- .../VideoChatting/config/WebRtcConfig.java | 96 +++++++++---------- .../controller/ChatController.java | 3 - .../VideoChatting/dto/ChatRoomMap.java | 1 - .../VideoChatting/dto/KurentoRoomDto.java | 2 - .../repository/ChatRoomRepository.java | 10 -- .../repository/ChatUserRepository.java | 3 - .../service/chat/ChatService.java | 2 + .../service/rtc/KurentoService.java | 1 - 10 files changed, 50 insertions(+), 123 deletions(-) delete mode 100644 src/main/java/com/example/VideoChatting/config/SslConfig.java diff --git a/src/main/java/com/example/VideoChatting/config/RedisConfig.java b/src/main/java/com/example/VideoChatting/config/RedisConfig.java index 1efe2a4..af3529d 100644 --- a/src/main/java/com/example/VideoChatting/config/RedisConfig.java +++ b/src/main/java/com/example/VideoChatting/config/RedisConfig.java @@ -58,15 +58,6 @@ public RedisTemplate redisTemplate(RedisConnectionFactory connec return redisTemplate; } @Bean - public CacheManager testCacheManager(RedisConnectionFactory cf) { - RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() - .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) - .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) - .entryTtl(Duration.ofMinutes(3L)); - - return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(cf).cacheDefaults(redisCacheConfiguration).build(); - } - @Bean public RedisTemplate redisTemplateForChatDto(RedisConnectionFactory connectionFactory) { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(connectionFactory); diff --git a/src/main/java/com/example/VideoChatting/config/SslConfig.java b/src/main/java/com/example/VideoChatting/config/SslConfig.java deleted file mode 100644 index 4e8a6da..0000000 --- a/src/main/java/com/example/VideoChatting/config/SslConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -//package com.example.VideoChatting.config; -// -//import org.apache.catalina.Context; -//import org.apache.catalina.connector.Connector; -//import org.apache.tomcat.util.descriptor.web.SecurityCollection; -//import org.apache.tomcat.util.descriptor.web.SecurityConstraint; -//import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -//import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -//@Configuration -//public class SslConfig { -// -// @Bean -// public ServletWebServerFactory servletContainer() { -// CustomTomcatServletWebServerFactory tomcat = new CustomTomcatServletWebServerFactory(); -// -// // Add HTTP to HTTPS redirect : http 로 요청이 들어오면 https 로 리다이렉트 -// tomcat.addAdditionalTomcatConnectors(httpToHttpsRedirectConnector()); -// -// return tomcat; -// } -// -// static class CustomTomcatServletWebServerFactory extends TomcatServletWebServerFactory { -// @Override -// protected void postProcessContext(Context context) { -// SecurityConstraint securityConstraint = new SecurityConstraint(); -// securityConstraint.setUserConstraint("CONFIDENTIAL"); -// SecurityCollection collection = new SecurityCollection(); -// collection.addPattern("/*"); -// securityConstraint.addCollection(collection); -// context.addConstraint(securityConstraint); -// } -// } -// -// private Connector httpToHttpsRedirectConnector() { -// Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL); -// connector.setScheme("http"); -// connector.setPort(8080); -// connector.setSecure(false); -// connector.setRedirectPort(8443); -// return connector; -// } -// -//} \ No newline at end of file diff --git a/src/main/java/com/example/VideoChatting/config/WebRtcConfig.java b/src/main/java/com/example/VideoChatting/config/WebRtcConfig.java index 575ea92..e0af626 100644 --- a/src/main/java/com/example/VideoChatting/config/WebRtcConfig.java +++ b/src/main/java/com/example/VideoChatting/config/WebRtcConfig.java @@ -1,48 +1,48 @@ -//package com.example.VideoChatting.config; -// -//import com.example.VideoChatting.service.rtc.KurentoHandler; -//import lombok.RequiredArgsConstructor; -//import org.kurento.client.KurentoClient; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.web.socket.config.annotation.EnableWebSocket; -//import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -//import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -//import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; -// -// -//@Configuration -//@EnableWebSocket // 웹 소켓에 대해 자동 설정 -//@RequiredArgsConstructor -//public class WebRtcConfig implements WebSocketConfigurer { -// /* TODO WebRTC 관련 */ -// -// -// @Bean -// public KurentoHandler kurentoHandler(){ -// return new KurentoHandler(); -// } -// @Bean -// public KurentoClient kurentoClient() { -// String kurentoUrl = "ws://52.78.190.79:8888/kurento"; -// return KurentoClient.create(kurentoUrl); -// } -// -// -// // signal 로 요청이 왔을 때 아래의 WebSockerHandler 가 동작하도록 registry 에 설정 -// // 요청은 클라이언트 접속, close, 메시지 발송 등에 대해 특정 메서드를 호출한다 -// @Override -// public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { -// registry.addHandler(kurentoHandler(), "/signal") -// .setAllowedOrigins("*"); -// } -// -// // 웹 소켓에서 rtc 통신을 위한 최대 텍스트 버퍼와 바이너리 버퍼 사이즈를 설정한다 -// @Bean -// public ServletServerContainerFactoryBean createWebSocketContainer() { -// ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); -// container.setMaxTextMessageBufferSize(32768); -// container.setMaxBinaryMessageBufferSize(32768); -// return container; -// } -//} \ No newline at end of file +package com.example.VideoChatting.config; + +import com.example.VideoChatting.service.rtc.KurentoHandler; +import lombok.RequiredArgsConstructor; +import org.kurento.client.KurentoClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; +import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; + + +@Configuration +@EnableWebSocket // 웹 소켓에 대해 자동 설정 +@RequiredArgsConstructor +public class WebRtcConfig implements WebSocketConfigurer { + /* TODO WebRTC 관련 */ + + + @Bean + public KurentoHandler kurentoHandler(){ + return new KurentoHandler(); + } + @Bean + public KurentoClient kurentoClient() { + String kurentoUrl = "ws://52.78.190.79:8888/kurento"; + return KurentoClient.create(kurentoUrl); + } + + + // signal 로 요청이 왔을 때 아래의 WebSockerHandler 가 동작하도록 registry 에 설정 + // 요청은 클라이언트 접속, close, 메시지 발송 등에 대해 특정 메서드를 호출한다 + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(kurentoHandler(), "/signal") + .setAllowedOrigins("*"); + } + + // 웹 소켓에서 rtc 통신을 위한 최대 텍스트 버퍼와 바이너리 버퍼 사이즈를 설정한다 + @Bean + public ServletServerContainerFactoryBean createWebSocketContainer() { + ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); + container.setMaxTextMessageBufferSize(32768); + container.setMaxBinaryMessageBufferSize(32768); + return container; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/VideoChatting/controller/ChatController.java b/src/main/java/com/example/VideoChatting/controller/ChatController.java index 93e45ae..04d3c93 100644 --- a/src/main/java/com/example/VideoChatting/controller/ChatController.java +++ b/src/main/java/com/example/VideoChatting/controller/ChatController.java @@ -77,9 +77,6 @@ public void sendMessage(@Payload ChatDto chat) { // Websocket에 발행된 메시지를 redis로 발행(publish) redisPublisher.publish(chatRoomService.getTopic(chat.getRoomId()), message1); chatService.saveMessage(chat); -// notificationService.notifyMessage(chatRoom.getRoomId(), chat.getSender()); - -// template.convertAndSend("/sub/chat/room/" + chat.getRoomId(), chat); } // 대화 내역 조회 diff --git a/src/main/java/com/example/VideoChatting/dto/ChatRoomMap.java b/src/main/java/com/example/VideoChatting/dto/ChatRoomMap.java index c25403d..611dc46 100644 --- a/src/main/java/com/example/VideoChatting/dto/ChatRoomMap.java +++ b/src/main/java/com/example/VideoChatting/dto/ChatRoomMap.java @@ -15,7 +15,6 @@ @Setter public class ChatRoomMap { private static ChatRoomMap chatRoomMap = new ChatRoomMap(); -// private Map chatRooms = new LinkedHashMap<>(); private ConcurrentMap chatRooms = new ConcurrentHashMap<>(); private ChatRoomMap(){} diff --git a/src/main/java/com/example/VideoChatting/dto/KurentoRoomDto.java b/src/main/java/com/example/VideoChatting/dto/KurentoRoomDto.java index 48eac47..32100ac 100644 --- a/src/main/java/com/example/VideoChatting/dto/KurentoRoomDto.java +++ b/src/main/java/com/example/VideoChatting/dto/KurentoRoomDto.java @@ -147,8 +147,6 @@ private Collection joinRoom(KurentoUserSession newParticipant) throws IO // participants 를 list 형태로 변환 => 이때 list 는 한명의 유저가 새로 들어올 때마다 // 즉 joinRoom 이 실행될 때마다 새로 생성 && return 됨 final List participantsList = new ArrayList<>(participants.values().size()); -// log.debug("ROOM {}: notifying other participants of new participant {}", name, -// newParticipant.getName()); log.debug("ROOM {}: 다른 참여자들에게 새로운 참여자가 들어왔음을 알림 {}", roomId, newParticipant.getName()); diff --git a/src/main/java/com/example/VideoChatting/repository/ChatRoomRepository.java b/src/main/java/com/example/VideoChatting/repository/ChatRoomRepository.java index 2c996ba..c0ec7f4 100644 --- a/src/main/java/com/example/VideoChatting/repository/ChatRoomRepository.java +++ b/src/main/java/com/example/VideoChatting/repository/ChatRoomRepository.java @@ -31,14 +31,4 @@ public interface ChatRoomRepository extends JpaRepository { @Query("update ChatRoom t set t.secretCheck = :secretCheck where t.roomId = :roomId") void updateRoomSecretCheck(@Param("roomId")String roomId, @Param("secretCheck")Boolean secretCheck); -//// @Override -//// @EntityGraph(attributePaths = {"chatMessageList"}) -//// List findAll(); -// @Override -// @Query("SELECT b FROM ChatRoom b order by b.id desc") -// @EntityGraph(attributePaths = {"chatMessageList"}) -// Page findAll(Pageable pageable); -// @Query("SELECT b FROM ChatRoom b order by b.id desc") -//// @EntityGraph(attributePaths = {"chatMessageList"}) -// Slice findAllChatRooms(Pageable pageable); } diff --git a/src/main/java/com/example/VideoChatting/repository/ChatUserRepository.java b/src/main/java/com/example/VideoChatting/repository/ChatUserRepository.java index 8115707..a077d86 100644 --- a/src/main/java/com/example/VideoChatting/repository/ChatUserRepository.java +++ b/src/main/java/com/example/VideoChatting/repository/ChatUserRepository.java @@ -10,7 +10,4 @@ public interface ChatUserRepository extends JpaRepository { Optional findByEmail(String email); - - - Optional findByNickname(String nickname); } diff --git a/src/main/java/com/example/VideoChatting/service/chat/ChatService.java b/src/main/java/com/example/VideoChatting/service/chat/ChatService.java index a686ede..5d45ecc 100644 --- a/src/main/java/com/example/VideoChatting/service/chat/ChatService.java +++ b/src/main/java/com/example/VideoChatting/service/chat/ChatService.java @@ -37,6 +37,8 @@ public void saveMessage(ChatDto chatDto) { chatDto.getMessage(), chatDto.getS3DataUrl(), room, chatDto.getRoomId(), chatDto.getFileName(), chatDto.getFileDir()); chatMessageRepository.save(chatMessage); + String cacheKey = "chat:" + chatDto.getRoomId(); + redisTemplate.delete(cacheKey); } // 대화 조회 - Redis & DB public List loadMessage(String roomId) { diff --git a/src/main/java/com/example/VideoChatting/service/rtc/KurentoService.java b/src/main/java/com/example/VideoChatting/service/rtc/KurentoService.java index f336b42..6912cdf 100644 --- a/src/main/java/com/example/VideoChatting/service/rtc/KurentoService.java +++ b/src/main/java/com/example/VideoChatting/service/rtc/KurentoService.java @@ -25,7 +25,6 @@ public class KurentoService { /** * @desc room 정보를 담은 map * */ -// private final ConcurrentMap rooms = new ConcurrentHashMap<>(); private final ConcurrentMap rooms = ChatRoomMap.getInstance().getChatRooms(); /**