package com.its.api.websocket;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

@Slf4j
@RequiredArgsConstructor
@Configuration
@EnableWebSocket
public class ItsWebSocketConfig implements WebSocketConfigurer {

    private final ItsWebSocketHandler itsWebsocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {

        webSocketHandlerRegistry.addHandler(this.itsWebsocketHandler, "/ws/messages.do")
                .setAllowedOriginPatterns("*")
                .withSockJS();  // sockjs

       webSocketHandlerRegistry.addHandler(this.itsWebsocketHandler, "/ws/messages.do")
                .setAllowedOriginPatterns("*"); // 그냥 websocket 지원
    }

}
