Files
OneKeyCallVideoTablet/src/main/java/com/onekeycall/videotablet/config/WebSocketConfig.java
2025-08-08 20:12:46 +08:00

31 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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校验
}
}