package com.cmvr.framework.websocket.config;


import com.cmvr.framework.websocket.server.WSServer;
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;

@Configuration
@EnableWebSocket
public class WSConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(myWebSocketHandler(), "/ws") // 指定路径
                .setAllowedOrigins("*");// 允许跨域;
    }

    @Bean
    public WSServer myWebSocketHandler() {
        return new WSServer();
    }
}