From 99647c423596c86a314cb43edb5a6fb70817cca6 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Wed, 01 Apr 2026 11:17:57 +0800
Subject: [PATCH] 优化

---
 ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java                   |   23 +++++++++++++++++++++++
 ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java |   21 +++++++++++++++++++++
 ard-admin/src/main/resources/application-prod.yml                                     |   16 ++++++----------
 3 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/ard-admin/src/main/resources/application-prod.yml b/ard-admin/src/main/resources/application-prod.yml
index e69d8c0..c383b44 100644
--- a/ard-admin/src/main/resources/application-prod.yml
+++ b/ard-admin/src/main/resources/application-prod.yml
@@ -62,6 +62,12 @@
   rtspPort: 8554
   webrtcPort: 8889
 
+#六合流媒体映射
+mediamtx-sixhe:
+    enable: true
+    playHost: 112.98.104.134
+    webrtcPort: 38889
+
 # mqtt配置
 mqtt:
   protocol: tcp
@@ -84,16 +90,6 @@
   region: us-east-1
   object-dir-prefix: wayline
 
-dock:
-  enable: true
-  provider: minio
-  endpoint: http://111.40.46.199:9011
-  access-key: admin
-  secret-key: ard12345
-  bucket: dockfile
-  expire: 3600
-  region: us-east-1
-  object-dir-prefix: wayline
 
 pointCloud:
   url : https://192.168.1.3:3001/tileset/
diff --git a/ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java b/ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java
new file mode 100644
index 0000000..1303420
--- /dev/null
+++ b/ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java
@@ -0,0 +1,23 @@
+package com.ard.vtdu.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * MediamtxConfig
+ *
+ * @author liusuyi
+ * @date 2024年11月09日16:18
+ **/
+@Configuration
+@Data
+@ConfigurationProperties(prefix = "mediamtx-sixhe")
+public class MediamtxSixHeConfig {
+    //是否启动映射转换
+    private Boolean enable;
+    //播放ip地址
+    private String playHost;
+    //webrtc端口
+    private Integer webrtcPort;
+}
diff --git a/ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java b/ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java
index 40b795b..0cc0861 100644
--- a/ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java
+++ b/ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson2.JSON;
 
+import com.ard.vtdu.config.MediamtxSixHeConfig;
 import com.ard.vtdu.domain.ArdVtdu;
 import com.ard.work.component.websocket.utils.WebSocketUtil;
 import com.ard.work.domain.message.BaseMessage;
@@ -27,6 +28,8 @@
 
     @Resource
     private ITyService tyService;
+    @Resource
+    private MediamtxSixHeConfig mediamtxSixHeConfig;
 
     // 盒子拉流地址缓存 key:boxSn value: webrtcUrl
     public static final ConcurrentMap<String, String> BOX_STREAM_PULL_MAP = new ConcurrentHashMap<>();
@@ -123,6 +126,24 @@
         if (boxLiveUrl == null) {
             throw new RuntimeException("未获取到盒子直播地址:" + boxSn);
         }
+        // 2. 获取原始 URL 字符串
+        String originalUrl = boxLiveUrl.getRtc();
+        if (mediamtxSixHeConfig.getEnable() && originalUrl != null && !originalUrl.isEmpty()) {
+            // --- 开始替换逻辑 ---
+            // 配置你的外网地址
+            String targetHost = mediamtxSixHeConfig.getPlayHost() + ":" + mediamtxSixHeConfig.getWebrtcPort();
+            // 正则解释:
+            // (^https?://)  -> 捕获组1:匹配 http:// 或 https://
+            // ([^/:]+)     -> 捕获组2:匹配 IP 地址或域名 (非 / 和 : 的字符)
+            // (:\d+)?      -> 捕获组3:匹配 :端口号 (可选)
+            // (/.*)        -> 捕获组4:匹配后面的路径参数
+            String regex = "(^https?://)([^/:]+)(:\\d+)?(/.*)";
+            // 替换为:协议 + 外网IP:端口 + 路径
+            // $1 代表协议, $4 代表路径
+            String newUrl = originalUrl.replaceAll(regex, "$1" + targetHost + "$4");
+            // 将新 URL 设置回去
+            boxLiveUrl.setRtc(newUrl);
+        }
         boxLiveUrl.setBoxSn(boxSn);
         return boxLiveUrl;
     }

--
Gitblit v1.9.3