package cn.iocoder.yudao.module.member.websocket;

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;

/**
 * @Author:qjq
 * @Date:2024/6/13 上午11:24
 */
@Configuration
@EnableWebSocket
public class WebSocketConfiguration implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(defaultWebSocketHandler(), "member/ws")
                .addInterceptors(webSocketInterceptor())
                .setAllowedOrigins("*");
    }
    @Bean
    public WebSocketInterceptor webSocketInterceptor() {
        return new WebSocketInterceptor();
    }
    @Bean
    public DefaultWebSocketHandler defaultWebSocketHandler(){
        return new DefaultWebSocketHandler();
    }
}
