package com.kingtom.shengtai.app.message.ws;

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;

/**
 * 应用模块名称</p>
 * 代码描述</p>
 * Copyright: Copyright (C) 2023 , Inc. All rights reserved. <p>
 * Company: 成都诚唐科技有限责任公司</p>
 *
 * @author wany
 * @since 2023/12/26
 */
@EnableWebSocket
@Configuration
public class WebSocketConfig implements WebSocketConfigurer{

    @Bean
    public WsHandler handler(){
        return new WsHandler();
    }

    @Bean
    public WsHandshakeInterceptor interceptor(){
        return new WsHandshakeInterceptor();
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry){
        registry.addHandler(handler(), "/ws").setAllowedOrigins("*").addInterceptors(interceptor());
    }

}
