package cn.sikey.websocket.client.interceptor;

import cn.sikey.websocket.client.handler.WebSocketHandler;
import cn.sikey.websocket.config.WebSocketConfig;
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 WebSocketInterceptor implements WebSocketConfigurer {
    private final WebSocketHandler webSocketHandler;

    private final WebSocketConfig webSocketConfig;

    public WebSocketInterceptor(WebSocketHandler webSocketHandler, WebSocketConfig webSocketConfig) {
        this.webSocketHandler = webSocketHandler;
        this.webSocketConfig = webSocketConfig;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketHandler, "/websocket/app/connect/websocket")
                .setAllowedOriginPatterns("*");
    }

}
