package com.tsi.sig.server.websocket;

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;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    private final AllTopicCvimHandler allTopicCvimHandler;
    private final OneTopicCvimHandler oneTopicCvimHandler;

    public WebSocketConfig(AllTopicCvimHandler allTopicCvimHandler, OneTopicCvimHandler oneTopicCvimHandler) {
        this.allTopicCvimHandler = allTopicCvimHandler;
        this.oneTopicCvimHandler = oneTopicCvimHandler;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {

        webSocketHandlerRegistry.addHandler(this.allTopicCvimHandler, "/allTopic.do")
                .setAllowedOrigins("*")
                .withSockJS();
        webSocketHandlerRegistry.addHandler(this.oneTopicCvimHandler, "/oneTopic.do")
                .setAllowedOrigins("*")
                .withSockJS();
    }

}

