package com.ltgk.boat.config.websocket;

import com.ltgk.boat.handler.IndexAlarmInfoWebsocketHandler;
import com.ltgk.boat.handler.ThreeNoBoatWebsocketHandler;
import com.ltgk.boat.handler.TrackWebsocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
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: wan kun
 * @Description: WebSocketConfig
 * @Date: 2024/11/29 10:18
 * @Version: 1.0
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Lazy
    private final IndexAlarmInfoWebsocketHandler indexAlarmInfoWebsocketHandler;
    @Lazy
    private final ThreeNoBoatWebsocketHandler threeNoBoatWebsocketHandler;
    @Lazy
    private final TrackWebsocketHandler trackWebsocketHandler;

    public WebSocketConfig(IndexAlarmInfoWebsocketHandler indexAlarmInfoWebsocketHandler,
                           ThreeNoBoatWebsocketHandler threeNoBoatWebsocketHandler, TrackWebsocketHandler trackWebsocketHandler) {
        this.indexAlarmInfoWebsocketHandler = indexAlarmInfoWebsocketHandler;
        this.threeNoBoatWebsocketHandler = threeNoBoatWebsocketHandler;
        this.trackWebsocketHandler = trackWebsocketHandler;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(indexAlarmInfoWebsocketHandler, "/indexAlarmInfoWs").setAllowedOrigins("*");
        registry.addHandler(threeNoBoatWebsocketHandler, "/threeNoBoat").setAllowedOrigins("*");
        registry.addHandler(trackWebsocketHandler, "/track").setAllowedOrigins("*");
    }

}
