LocationWebSocketConfig.java 1.06 KB
package com.diligrp.rider.config;

import com.diligrp.rider.websocket.LocationWebSocketHandshakeInterceptor;
import com.diligrp.rider.websocket.LocationWebSocketHandler;
import lombok.RequiredArgsConstructor;
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
@RequiredArgsConstructor
public class LocationWebSocketConfig implements WebSocketConfigurer {

    private final LocationWebSocketHandler locationWebSocketHandler;
    private final LocationWebSocketHandshakeInterceptor locationWebSocketHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(locationWebSocketHandler, "/ws/location")
                .addInterceptors(locationWebSocketHandshakeInterceptor)
                .setAllowedOriginPatterns("*");
    }
}