package com.its.vms.api.websocket;

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

        registry.addHandler(this.itsWebsocketHandler, "/ws/messages.do")
                //.setAllowedOrigins("*")
                .setAllowedOriginPatterns("*")
                .withSockJS()
                //.setSessionCookieNeeded(false)
        ;  // sockjs

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

}
