package com.sikey.wa04.api.websocket.client.interceptor;

import com.sikey.wa04.api.websocket.client.handler.WebSocketHandler;
import com.sikey.wa04.business.infrastructure.configuration.WebSocketConfig;
import org.springframework.context.annotation.Bean;
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;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

@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, "/api/v2/gatewayctx/connect/websocket")
                .setAllowedOriginPatterns("*");
    }

    /*@Bean
    public ServletServerContainerFactoryBean webSocketContainer() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        // 设置空闲超时（单位：毫秒）
        container.setMaxSessionIdleTimeout(300000L); // 5分钟
        // 设置异步发送超时（单位：毫秒）
        container.setAsyncSendTimeout(10000L); // 10秒
        return container;
    }*/

}
