From 7beea5916728a84617d4791775d0aac70ab32eee Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Fri, 12 Dec 2025 10:40:43 +0800
Subject: [PATCH] 2025-12-12 zwy 优化,订阅视频时,谁订阅发给谁直播地址,其他订阅不变
---
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