package org.dromara.talk.config;

import org.dromara.talk.handler.TtsWebSocketHandler;
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 WebSocketConfig implements WebSocketConfigurer {

    private final TtsWebSocketHandler ttsHandler;

    public WebSocketConfig(TtsWebSocketHandler ttsHandler) {
        this.ttsHandler = ttsHandler;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(ttsHandler, "/tts")
                .setAllowedOrigins("*");
    }
}
