package com.nbport.zgwl.seal.config;

import com.nbport.zgwl.seal.handler.SealWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * WebSocket配置类
 *
 * 配置签章平台回调的WebSocket连接端点
 * 前端通过 ws://localhost:8080/seal/ws/callback 建立连接
 *
 * 注意：
 * 1. setAllowedOrigins("*") 允许所有来源，生产环境应限制为具体域名
 * 2. WebSocket不走Spring Security的HTTP认证，需要额外考虑安全性
 *
 * @author xiaofengzhou
 */
@Configuration
@EnableWebSocket
public class SealWebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SealWebSocketHandler sealWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(sealWebSocketHandler, "/seal/ws/callback")
                .setAllowedOrigins("*");
    }
}
