package com.dcs.hnyz.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * WebSocketConfig
 * websocket配置
 * @author: hmy
 * @date: 2025/5/30 15:45
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    //定义客户端连接 WebSocket 的入口
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws/configurationPage")
                .setAllowedOriginPatterns("*")
                .withSockJS();
    }

    @Override
    //配置消息代理规则
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic"); // 推送路径
        registry.setApplicationDestinationPrefixes("/app"); // 接收路径前缀
    }
}
