From 4017fe347792c7e28695c455a40874f0c647cc9b Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 26 Nov 2021 16:46:45 +0800 Subject: [PATCH] add fish hit websocket --- 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