From 118e42884e677a99dbdd20349eaad85c96bafeb4 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Thu, 22 Apr 2021 10:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8B=89=E6=B5=81=E4=BB=A3?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/media/zlm/ZLMRESTfulUtils.java | 4 ++- .../iot/vmp/media/zlm/ZLMRunner.java | 7 +++- .../iot/vmp/service/IStreamProxyService.java | 2 +- .../service/impl/StreamProxyServiceImpl.java | 32 +++++++++++++---- .../iot/vmp/vmanager/bean/WVPResult.java | 32 +++++++++++++++++ .../streamProxy/StreamProxyController.java | 19 +++++++---- web_src/src/components/StreamProxyList.vue | 34 ++++++++++++------- .../src/components/dialog/StreamProxyEdit.vue | 28 +++++++-------- 8 files changed, 114 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java index d701c83d..42ad8236 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java @@ -43,7 +43,9 @@ public class ZLMRESTfulUtils { builder.add("secret",mediaSecret); if (param != null && param.keySet().size() > 0) { for (String key : param.keySet()){ - builder.add(key, param.get(key).toString()); + if (param.get(key) != null) { + builder.add(key, param.get(key).toString()); + } } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index 2ef4cf6a..308fa6b1 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -170,7 +170,12 @@ public class ZLMRunner implements CommandLineRunner { List streamProxyListForEnable = storager.getStreamProxyListForEnable(true); for (StreamProxyItem streamProxyDto : streamProxyListForEnable) { logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); - streamProxyService.addStreamProxyToZlm(streamProxyDto); + JSONObject jsonObject = streamProxyService.addStreamProxyToZlm(streamProxyDto); + if (jsonObject == null) { + // 设置为未启用 + logger.info("恢复流代理失败,请检查流地址后重新启用" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); + streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream()); + } } } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java index 023c0757..cddc21c7 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java @@ -10,7 +10,7 @@ public interface IStreamProxyService { * 保存视频代理 * @param param */ - void save(StreamProxyItem param); + String save(StreamProxyItem param); /** * 添加视频代理到zlm diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index e31f0e84..c6286c59 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -40,23 +40,40 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Override - public void save(StreamProxyItem param) { + public String save(StreamProxyItem param) { MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), param.getStream() ); param.setDst_url(dstUrl); + StringBuffer result = new StringBuffer(); // 更新 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { - boolean result = videoManagerStorager.updateStreamProxy(param); - if (result && param.isEnable()) { - addStreamProxyToZlm(param); + if (videoManagerStorager.updateStreamProxy(param)) { + result.append("保存成功"); + if (param.isEnable()){ + JSONObject jsonObject = addStreamProxyToZlm(param); + if (jsonObject == null) { + result.append(", 但是启用失败,请检查流地址是否可用"); + param.setEnable(false); + videoManagerStorager.updateStreamProxy(param); + } + } } }else { // 新增 - boolean result = videoManagerStorager.addStreamProxy(param); - if (result && param.isEnable()) { - addStreamProxyToZlm(param); + if (videoManagerStorager.addStreamProxy(param)){ + result.append("保存成功"); + if (param.isEnable()) { + JSONObject jsonObject = addStreamProxyToZlm(param); + if (jsonObject == null) { + result.append(", 但是启用失败,请检查流地址是否可用"); + param.setEnable(false); + videoManagerStorager.updateStreamProxy(param); + } + } } + } + return result.toString(); } @Override @@ -105,6 +122,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); if (!streamProxy.isEnable() && streamProxy != null) { JSONObject jsonObject = addStreamProxyToZlm(streamProxy); + if (jsonObject == null) return false; if (jsonObject.getInteger("code") == 0) { result = true; streamProxy.setEnable(true); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java new file mode 100644 index 00000000..f8e2c1c0 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java @@ -0,0 +1,32 @@ +package com.genersoft.iot.vmp.vmanager.bean; + +public class WVPResult { + + private int code; + private String msg; + private T data; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index 8914fc1c..62f732ec 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.service.IStreamProxyService; +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -56,10 +57,13 @@ public class StreamProxyController { }) @PostMapping(value = "/save") @ResponseBody - public Object save(@RequestBody StreamProxyItem param){ + public WVPResult save(@RequestBody StreamProxyItem param){ logger.info("添加代理: " + JSONObject.toJSONString(param)); - streamProxyService.save(param); - return "success"; + String msg = streamProxyService.save(param); + WVPResult result = new WVPResult<>(); + result.setCode(0); + result.setMsg(msg); + return result; } @ApiOperation("移除代理") @@ -69,10 +73,13 @@ public class StreamProxyController { }) @DeleteMapping(value = "/del") @ResponseBody - public Object del(String app, String stream){ + public WVPResult del(String app, String stream){ logger.info("移除代理: " + app + "/" + stream); streamProxyService.del(app, stream); - return "success"; + WVPResult result = new WVPResult<>(); + result.setCode(0); + result.setMsg("success"); + return result; } @ApiOperation("启用代理") @@ -85,7 +92,7 @@ public class StreamProxyController { public Object start(String app, String stream){ logger.info("启用代理: " + app + "/" + stream); boolean result = streamProxyService.start(app, stream); - return "success"; + return result?"success":"fail"; } @ApiOperation("停用代理") diff --git a/web_src/src/components/StreamProxyList.vue b/web_src/src/components/StreamProxyList.vue index 6d4183eb..ee3d43c3 100644 --- a/web_src/src/components/StreamProxyList.vue +++ b/web_src/src/components/StreamProxyList.vue @@ -19,13 +19,13 @@