From b1ea8a05f56f92c66dc478af5100bc1b1cb764d3 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Thu, 18 Dec 2025 09:55:38 +0800
Subject: [PATCH] 2025-12-16 zwy 优化开启直播时判断直播参数是否为空;
---
ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
index 2a0014e..8d79eba 100644
--- a/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
+++ b/ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
@@ -31,16 +31,22 @@
/**
* 开启直播
*/
- public void StartLiveStreaming(String sn) {
+ public void StartLiveStreaming(String sn ,String userId) {
//调用开始直播
ResponseResult rlive = null;
String resultLive = "";
try {
// 获取直播参数
LiveTypeDTO param = getLiveParam(sn);
+ // 判断param是否为空,不为空则返回正确的直播参数,为null则未获取直播参数,不为空则继续操作
+ if (param == null) {
+ log.info("SN: {}-未获取到直播参数param为null,无法开启直播!", sn);
+ return;
+ }
// 如果存在直播则读取直播地址返回
if (RedisOpsUtils.checkExist(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn)) {
resultLive = String.valueOf(RedisOpsUtils.get(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn));
+ log.info("SN: {}-redis中存在相机的播放地址信息,直接返回地址!", sn);
} else {
log.info("SN: {}-redis中未找到相机的播放地址信息!停止直播后再开启直播", sn);
StopLiveStreaming(sn);
@@ -60,7 +66,7 @@
}
}
}
- _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive);
+ _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive, userId);
log.info("SN: {}-直播地址:{}", sn, resultLive);
} catch (Exception e) {
log.info("SN: {}-开启直播失败!原因:{}", sn, e.getMessage());
@@ -121,8 +127,9 @@
List<CapacityDeviceDTO> devicesList = _liveStreamService.getLiveCapacity();
if (devicesList == null || devicesList.isEmpty()) {
log.info("SN: {}-未获得设备直播能力!", sn);
+ return null;
// 抛弃出异常,给调用者处理
- throw new Exception("未获得设备直播能力!");
+ // throw new Exception("未获得设备直播能力!");
}
for (CapacityDeviceDTO device : devicesList) {
if (!device.getSn().equals(sn)) {
--
Gitblit v1.9.3