package com.changhu.support.ws;

import com.changhu.support.ws.interceptor.WsAuthenticationInterceptor;
import com.changhu.support.ws.server.ManagementWebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * author: luozhun
 * desc: WebSocketConfig
 * createTime: 2023/8/28 9:12
 */
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private WsAuthenticationInterceptor webSocketInterceptor;

    @Autowired
    private ManagementWebSocketServer managementWebSocketServer;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(managementWebSocketServer, "/ws/connect/management")
                .setAllowedOrigins("*")
                .addInterceptors(webSocketInterceptor);
    }
}
