| | |
| | | package com.ard.tianyu.websocket.config; |
| | | |
| | | import com.ard.tianyu.websocket.handler.TyMessageHandler; |
| | | import com.ard.tianyu.websocket.handler.TyStreamHandler; |
| | | import com.ard.tianyu.websocket.interceptor.TyHandshakeInterceptor; |
| | | 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 javax.annotation.Resource; |
| | | |
| | | @Configuration |
| | |
| | | |
| | | @Resource |
| | | private TyMessageHandler tyMessageHandler; |
| | | @Resource |
| | | private TyStreamHandler tyStreamHandler; |
| | | |
| | | |
| | | @Override |
| | | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
| | | //添加myWebSocketHandler消息处理对象以及websocket连接地址 |
| | | registry.addHandler(tyMessageHandler, "/ws/state/**") |
| | | registry.addHandler(tyMessageHandler, "/ws/**") |
| | | //设置允许跨域访问 |
| | | .setAllowedOrigins("*") |
| | | //添加拦截器可实现用户链接前进行权限校验等操作 |
| | | .addInterceptors(new TyHandshakeInterceptor()); |
| | | // 注册流媒体 WebSocket 处理器 |
| | | registry.addHandler(tyStreamHandler, "/ws/stream/**") |
| | | .setAllowedOrigins("*") |
| | | .addInterceptors(new TyHandshakeInterceptor()); // 可选的拦截器 |
| | | } |
| | | } |