liusuyi
2026-05-12 9f327c33730ba10cb2d89aff99b727502232e968
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.ard.work.websocket.config;
 
import com.ard.work.websocket.handler.JKWebSocketHandler;
import com.ard.work.websocket.handler.PTZWebSocketHandler;
import com.ard.work.websocket.interceptor.PTZHandshakeInterceptor;
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;
 
import jakarta.annotation.Resource;
 
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
 
    @Resource
    private PTZWebSocketHandler ptzWebSocketHandler;
 
    @Resource
    private JKWebSocketHandler jkWebSocketHandler;
 
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //添加myWebSocketHandler消息处理对象以及websocket连接地址
        registry.addHandler(ptzWebSocketHandler, "/ws/ptz/**")
                //设置允许跨域访问
                .setAllowedOrigins("*")
                //添加拦截器可实现用户链接前进行权限校验等操作
                .addInterceptors(new PTZHandshakeInterceptor());
 
        registry.addHandler(jkWebSocketHandler, "/ws/jankang/**")
                //设置允许跨域访问
                .setAllowedOrigins("*")
                //添加拦截器可实现用户链接前进行权限校验等操作
                .addInterceptors(new PTZHandshakeInterceptor());
    }
}