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 | 43 +++++++++++++++++++++++++++++++++----------
1 files changed, 33 insertions(+), 10 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 6468eaf..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);
@@ -53,17 +59,19 @@
rlive.setType(MessageType.LIVESTREAM.getType());
resultLive = _objectMapper.writeValueAsString(rlive);
RedisOpsUtils.set(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn, resultLive);
+ LiveDTO live = (LiveDTO) rlive.getData();
+ Boolean isWeb = _deviceService.updateWebrtcUrl(sn,live.getWebrtcUrl());
+ if (isWeb) {
+ log.info("SN: {}-更新webrtc地址成功!", sn);
+ }
}
}
+ _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive, userId);
+ log.info("SN: {}-直播地址:{}", sn, resultLive);
} catch (Exception e) {
log.info("SN: {}-开启直播失败!原因:{}", sn, e.getMessage());
- String jsonString = getResult(sn, "开启直播失败!原因:" + e.getMessage());
- _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), jsonString);
e.printStackTrace();
}
-
- _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive);
- log.info("SN: {}-直播地址:{}", sn, resultLive);
}
public void StopLiveStreaming(String sn) {
@@ -78,10 +86,12 @@
// rlive.setType(MessageType.LIVESTREAM.getType());
// resultLive = _objectMapper.writeValueAsString(rlive);
RedisOpsUtils.del(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn);
+ log.info("SN: {}-停止直播,并删除redis直播信息!", sn);
} catch (Exception e) {
+ log.info("SN: {}-停止直播时发生异常,原因:{}", sn,e.getMessage());
e.printStackTrace();
}
- //_dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive);
+ // 停止直播不返回数据,直接删除redis中的直播地址标记即可;并且方法在websocket连接断开后执行。
}
public String getResult(String sn, String msg) {
@@ -117,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)) {
@@ -126,9 +137,21 @@
}
List<CapacityCameraDTO> camerasList = device.getCamerasList();
for (CapacityCameraDTO camera : camerasList) {
- if (camera.getName() == null || camera.getName().isEmpty()) {
- continue;
+ // 机场3中飞行器,没有name,需要其他条件确定主摄像头参数
+ for(CapacityVideoDTO video : camera.getVideosList())
+ {
+ if(video.getSwitchVideoTypes().size() == 1 && camera.getName() == null)
+ {
+ continue;
+ }
}
+// camera.getVideosList().get(0).getSwitchVideoTypes().add("main");
+// if(camera.getVideosList().size() == 1 && camera.getName() == null) {
+// continue;
+// }
+// if (camera.getName() == null || camera.getName().isEmpty()) {
+// continue;
+// }
String videoid = device.getSn() + "/" + camera.getIndex();
List<CapacityVideoDTO> videosList = camera.getVideosList();
for (CapacityVideoDTO video : videosList) {
--
Gitblit v1.9.3