package com.market.websocket;

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 服务端配置
 *
 * <p>前端连接地址：{@code ws://host:10022/ws/market}
 */
@Configuration
@EnableWebSocket
public class FrontendWebSocketConfig implements WebSocketConfigurer {

    private final FrontendWebSocketHandler handler;

    public FrontendWebSocketConfig(FrontendWebSocketHandler handler) {
        this.handler = handler;
    }

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