package com.onekeycall.videotablet.config; import com.onekeycall.videotablet.handler.CustomWebSocketHandler; import com.onekeycall.videotablet.interceptor.AuthHandshakeInterceptor; import com.onekeycall.videotablet.utils.JwtUtil; 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; @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer { @Autowired private JwtUtil jwtUtil; private final CustomWebSocketHandler webSocketHandler; public WebSocketConfig(CustomWebSocketHandler webSocketHandler) { this.webSocketHandler = webSocketHandler; } @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(webSocketHandler, "/ws") // 客户端连接端点 .setAllowedOrigins("*") // 允许跨域 .addInterceptors(new AuthHandshakeInterceptor(jwtUtil)); // 握手拦截器(如JWT校验) } }