From d825b986ddfeec44e9ce50a6868ea70a0375d309 Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Fri, 23 May 2025 09:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E6=B5=81=E5=88=97=E8=A1=A8=E5=92=8C?= =?UTF-8?q?=E6=8B=89=E6=B5=81=E4=BB=A3=E7=90=86=E6=94=AF=E6=8C=81=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=9D=A5=E6=BA=90ip=E8=BF=94=E5=9B=9E=E6=B5=81?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StreamProxyController.java | 16 +++++++++++++++- .../controller/StreamPushController.java | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java index be4d91b33..7d651219e 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java @@ -23,6 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Map; @SuppressWarnings("rawtypes") @@ -190,12 +193,23 @@ public class StreamProxyController { @ResponseBody @Operation(summary = "启用代理", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "id", description = "代理Id", required = true) - public StreamContent start(int id){ + public StreamContent start(HttpServletRequest request, int id){ log.info("播放代理: {}", id); StreamInfo streamInfo = streamProxyPlayService.start(id, null, null); if (streamInfo == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg()); }else { + if (userSetting.getUseSourceIpAsStreamIp()) { + streamInfo=streamInfo.clone();//深拷贝 + String host; + try { + URL url=new URL(request.getRequestURL().toString()); + host=url.getHost(); + } catch (MalformedURLException e) { + host=request.getLocalAddr(); + } + streamInfo.changeStreamIp(host); + } return new StreamContent(streamInfo); } } diff --git a/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java b/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java index 67fb1cfa1..d29e1a128 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java +++ b/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java @@ -35,8 +35,11 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -245,7 +248,7 @@ public class StreamPushController { @GetMapping(value = "/start") @ResponseBody @Operation(summary = "开始播放", security = @SecurityRequirement(name = JwtUtils.HEADER)) - public DeferredResult> start(Integer id){ + public DeferredResult> start(HttpServletRequest request, Integer id){ Assert.notNull(id, "推流ID不可为NULL"); DeferredResult> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); result.onTimeout(()->{ @@ -254,6 +257,17 @@ public class StreamPushController { }); streamPushPlayService.start(id, (code, msg, streamInfo) -> { if (code == 0 && streamInfo != null) { + if (userSetting.getUseSourceIpAsStreamIp()) { + streamInfo=streamInfo.clone();//深拷贝 + String host; + try { + URL url=new URL(request.getRequestURL().toString()); + host=url.getHost(); + } catch (MalformedURLException e) { + host=request.getLocalAddr(); + } + streamInfo.changeStreamIp(host); + } WVPResult success = WVPResult.success(new StreamContent(streamInfo)); result.setResult(success); }