package com.zksy.web.websocket;

import org.springframework.beans.factory.annotation.Autowired;
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>
 * 注册 WebSocket 处理器，供可视化等前端调用。
 * 后续新增接口只需在此注册新的 handler 即可。
 *
 * @author zksy
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private DeviceStatusWebSocketHandler deviceStatusWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 设备状态查询 WebSocket 端点
        registry.addHandler(deviceStatusWebSocketHandler, "/ws/deviceStatus")
                .setAllowedOrigins("*");
    }
}