|
2 | 2 |
|
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import org.springframework.context.annotation.Configuration; |
5 | | -import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
6 | | -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
7 | | -import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
8 | | -import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
| 5 | +import org.springframework.web.socket.config.annotation.EnableWebSocket; |
| 6 | +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
| 7 | +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
9 | 8 |
|
10 | 9 | @Configuration |
11 | 10 | @RequiredArgsConstructor |
12 | | -@EnableWebSocketMessageBroker // STOMP를 사용하기 위해 변경 |
13 | | -public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { |
| 11 | +@EnableWebSocket |
| 12 | +public class WebSocketConfig implements WebSocketConfigurer { |
14 | 13 |
|
15 | | - @Override |
16 | | - public void registerStompEndpoints(StompEndpointRegistry registry) { |
17 | | - // 클라이언트가 연결할 WebSocket 엔드포인트 |
18 | | - registry.addEndpoint("/ws-stomp") |
19 | | - .setAllowedOriginPatterns("*") // setAllowedOriginPatterns 사용 |
20 | | - // SockJS 사용 (WebSocket 미지원 브라우저 대응) |
21 | | - .withSockJS(); |
22 | | - |
23 | | - registry.addEndpoint("/ws") |
24 | | - .setAllowedOriginPatterns("*") // setAllowedOriginPatterns 사용 |
25 | | - .withSockJS(); |
26 | | - } |
| 14 | + private final ChatWebSocketHandler chatWebSocketHandler; |
27 | 15 |
|
28 | 16 | @Override |
29 | | - public void configureMessageBroker(MessageBrokerRegistry registry) { |
30 | | - // 클라이언트가 메시지를 보낼 때 사용할 경로(prefix) |
31 | | - registry.setApplicationDestinationPrefixes("/app"); |
32 | | - |
33 | | - // 메시지를 구독하는 경로(prefix) |
34 | | - registry.enableSimpleBroker("/sub", "/topic", "/queue"); |
| 17 | + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
| 18 | + registry.addHandler(chatWebSocketHandler, "/chat").setAllowedOrigins("*"); |
35 | 19 | } |
36 | 20 | } |
0 commit comments