From ecb9599b25fde0e3569b46e667ca1990294f8665 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Tue, 16 Dec 2025 10:26:21 +0800
Subject: [PATCH] 修复【在线用户强制退出正在使用的账号】bug

---
 ard-sample/src/main/java/com/ard/sample/component/websocket/handler/DockWebSocketHandler.java |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/DockWebSocketHandler.java b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/DockWebSocketHandler.java
index c9af46c..36ab8cc 100644
--- a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/DockWebSocketHandler.java
+++ b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/DockWebSocketHandler.java
@@ -153,6 +153,13 @@
             // 3. 处理订阅/取消订阅逻辑
             handleSubscription(userId, messageType, payload);
 
+            // 直播类型订阅:触发开启直播
+            if (MessageType.LIVESTREAM.getType().equals(messageType) && payload.isSubscribe()) {
+                String sn = payload.getSn();
+                _liveStreamService.StartLiveStreaming(sn,userId);
+                log.info("设备[{}]直播流已开启(用户[{}]订阅触发)", sn, userId);
+            }
+
         } catch (Exception e) {
             log.error("用户[{}]消息处理异常", userId, e);
             sendMessage(session, "消息格式错误或处理失败:" + e.getMessage());
@@ -187,11 +194,11 @@
             subscriptions.computeIfAbsent(subscriptionKey, k -> ConcurrentHashMap.newKeySet()).add(userId);
 //            log.info("用户[{}]订阅设备[{}]的[{}]类型消息", userId, sn, type);
 
-            // 直播类型订阅:触发开启直播
-            if (MessageType.LIVESTREAM.getType().equals(type)) {
-                _liveStreamService.StartLiveStreaming(sn);
-                log.info("设备[{}]直播流已开启(用户[{}]订阅触发)", sn, userId);
-            }
+//            // 直播类型订阅:触发开启直播
+//            if (MessageType.LIVESTREAM.getType().equals(type)) {
+//                _liveStreamService.StartLiveStreaming(sn);
+//                log.info("设备[{}]直播流已开启(用户[{}]订阅触发)", sn, userId);
+//            }
         } else {
             // 取消订阅操作
             if (subscriptions.containsKey(subscriptionKey)) {
@@ -257,7 +264,7 @@
      * @param type    消息类型(对应MessageType)
      * @param content 消息内容(JSON字符串)
      */
-    public void sendMessageToSubscribers(String sn, String type, String content) {
+    public void sendMessageToSubscribers(String sn, String type, String content, String uId) {
         String subscriptionKey = getSubscriptionKey(sn, type);
         Set<String> subscriberIds = subscriptions.getOrDefault(subscriptionKey, Collections.emptySet());
 
@@ -280,6 +287,12 @@
 
             // 线程安全发送消息
             try {
+                if(MessageType.LIVESTREAM.getType().equals(type)) {
+                    WebSocketSession liveSession = userSessions.get(uId);
+                    sendMessage(liveSession, content);
+                    log.info("单独向用户[{}]推送设备[{}]的[{}]类型消息:{}", uId, sn, type, content);
+                    return;
+                }
                 sendMessage(session, content);
                 log.debug("向用户[{}]推送设备[{}]的[{}]类型消息:{}", userId, sn, type, content);
             } catch (IOException e) {

--
Gitblit v1.9.3