From cb52962cea658ceac36dcb72beaed6713a17638b Mon Sep 17 00:00:00 2001 From: Hamm Date: Tue, 28 May 2024 00:17:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(BUG):=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hamm --- .../airpower/websocket/WebSocketHandler.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/airpower-core/src/main/java/cn/hamm/airpower/websocket/WebSocketHandler.java b/airpower-core/src/main/java/cn/hamm/airpower/websocket/WebSocketHandler.java index 0075636..cbeef79 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/websocket/WebSocketHandler.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/websocket/WebSocketHandler.java @@ -32,21 +32,19 @@ import java.util.Objects; @Component @Slf4j public class WebSocketHandler extends TextWebSocketHandler implements MessageListener { - /** - *

Redis连接工厂

- */ - @Autowired - private RedisConnectionFactory redisConnectionFactory; - /** *

订阅全频道

*/ public static String CHANNEL_ALL = "WEBSOCKET_ALL"; - /** *

订阅用户频道前缀

*/ public static String CHANNEL_USER_PREFIX = "WEBSOCKET_USER_"; + /** + *

Redis连接工厂

+ */ + @Autowired + private RedisConnectionFactory redisConnectionFactory; /** *

收到Websocket消息时

@@ -67,7 +65,7 @@ public class WebSocketHandler extends TextWebSocketHandler implements MessageLis } try { WebSocketPayload webSocketPayload = Json.parse(message, WebSocketPayload.class); - onWebSocketPayload(webSocketPayload); + onWebSocketPayload(webSocketPayload, session); } catch (Exception exception) { log.error("解析Websocket事件负载失败: {}", exception.getMessage()); } @@ -78,7 +76,7 @@ public class WebSocketHandler extends TextWebSocketHandler implements MessageLis * * @param webSocketPayload 负载对象 */ - public void onWebSocketPayload(@NotNull WebSocketPayload webSocketPayload) { + public void onWebSocketPayload(@NotNull WebSocketPayload webSocketPayload, @NotNull WebSocketSession session) { log.info("负载类型: {}, 负载内容: {}", webSocketPayload.getType(), webSocketPayload.getData()); } @@ -128,7 +126,7 @@ public class WebSocketHandler extends TextWebSocketHandler implements MessageLis /** *

开始监听Redis消息

* - * @param session 连接 + * @param session WebSocket会话 * @param userId 用户ID */ private void startRedisListener(@NotNull WebSocketSession session, long userId) { -- Gitee