增加websocket

This commit is contained in:
2025-08-08 20:12:46 +08:00
parent 411b7d69d3
commit 503b44d92d
17 changed files with 391 additions and 55 deletions

View File

@@ -0,0 +1,30 @@
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校验
}
}