From f5e6133809c553cfd9fb28ee61019927c547c374 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 08 Dec 2021 15:58:33 +0800 Subject: [PATCH] 20211208 fish --- src/main/java/com/xcong/excoin/configurations/WebSocketConfig.java | 26 ++++++++++++++++++++++++-- 1 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xcong/excoin/configurations/WebSocketConfig.java b/src/main/java/com/xcong/excoin/configurations/WebSocketConfig.java index 51711c3..3ba5508 100644 --- a/src/main/java/com/xcong/excoin/configurations/WebSocketConfig.java +++ b/src/main/java/com/xcong/excoin/configurations/WebSocketConfig.java @@ -1,11 +1,26 @@ package com.xcong.excoin.configurations; +import com.xcong.excoin.websocket.handler.FishHitWebSocketHandler; +import com.xcong.excoin.websocket.handler.FishHitWebSocketHandshakeInterceptor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +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 org.springframework.web.socket.server.standard.ServerEndpointExporter; -//@Configuration -public class WebSocketConfig { +@Slf4j +@Configuration +public class WebSocketConfig implements WebSocketConfigurer { + + @Autowired + private FishHitWebSocketHandler fishHitWebSocketHandler; + @Autowired + private FishHitWebSocketHandshakeInterceptor fishHitWebSocketHandshakeInterceptor; + /** * 注入一个ServerEndpointExporter,该Bean会自动注册使用@ServerEndpoint注解申明的websocket endpoint */ @@ -13,4 +28,11 @@ public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(fishHitWebSocketHandler, "websocket/fish/hit") + .setAllowedOrigins("*") + .addInterceptors(fishHitWebSocketHandshakeInterceptor); + } } -- Gitblit v1.9.1