| ard-admin/src/main/resources/application-prod.yml | ●●●●● patch | view | raw | blame | history | |
| ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java | ●●●●● patch | view | raw | blame | history | |
| ard-work/src/main/java/com/ard/work/component/websocket/handler/UavStreamManager.java | ●●●●● patch | view | raw | blame | history |
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/ ard-vtdu/src/main/java/com/ard/vtdu/config/MediamtxSixHeConfig.java
New file @@ -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; } 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; }