Commit 118e42884e677a99dbdd20349eaad85c96bafeb4

Authored by panlinlin
1 parent 6289438e

优化拉流代理

src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
@@ -43,7 +43,9 @@ public class ZLMRESTfulUtils { @@ -43,7 +43,9 @@ public class ZLMRESTfulUtils {
43 builder.add("secret",mediaSecret); 43 builder.add("secret",mediaSecret);
44 if (param != null && param.keySet().size() > 0) { 44 if (param != null && param.keySet().size() > 0) {
45 for (String key : param.keySet()){ 45 for (String key : param.keySet()){
46 - builder.add(key, param.get(key).toString()); 46 + if (param.get(key) != null) {
  47 + builder.add(key, param.get(key).toString());
  48 + }
47 } 49 }
48 } 50 }
49 51
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
@@ -170,7 +170,12 @@ public class ZLMRunner implements CommandLineRunner { @@ -170,7 +170,12 @@ public class ZLMRunner implements CommandLineRunner {
170 List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true); 170 List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true);
171 for (StreamProxyItem streamProxyDto : streamProxyListForEnable) { 171 for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
172 logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); 172 logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
173 - streamProxyService.addStreamProxyToZlm(streamProxyDto); 173 + JSONObject jsonObject = streamProxyService.addStreamProxyToZlm(streamProxyDto);
  174 + if (jsonObject == null) {
  175 + // 设置为未启用
  176 + logger.info("恢复流代理失败,请检查流地址后重新启用" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
  177 + streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream());
  178 + }
174 } 179 }
175 } 180 }
176 } 181 }
src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java
@@ -10,7 +10,7 @@ public interface IStreamProxyService { @@ -10,7 +10,7 @@ public interface IStreamProxyService {
10 * 保存视频代理 10 * 保存视频代理
11 * @param param 11 * @param param
12 */ 12 */
13 - void save(StreamProxyItem param); 13 + String save(StreamProxyItem param);
14 14
15 /** 15 /**
16 * 添加视频代理到zlm 16 * 添加视频代理到zlm
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -40,23 +40,40 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -40,23 +40,40 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
40 40
41 41
42 @Override 42 @Override
43 - public void save(StreamProxyItem param) { 43 + public String save(StreamProxyItem param) {
44 MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); 44 MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
45 String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), 45 String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
46 param.getStream() ); 46 param.getStream() );
47 param.setDst_url(dstUrl); 47 param.setDst_url(dstUrl);
  48 + StringBuffer result = new StringBuffer();
48 // 更新 49 // 更新
49 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { 50 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) {
50 - boolean result = videoManagerStorager.updateStreamProxy(param);  
51 - if (result && param.isEnable()) {  
52 - addStreamProxyToZlm(param); 51 + if (videoManagerStorager.updateStreamProxy(param)) {
  52 + result.append("保存成功");
  53 + if (param.isEnable()){
  54 + JSONObject jsonObject = addStreamProxyToZlm(param);
  55 + if (jsonObject == null) {
  56 + result.append(", 但是启用失败,请检查流地址是否可用");
  57 + param.setEnable(false);
  58 + videoManagerStorager.updateStreamProxy(param);
  59 + }
  60 + }
53 } 61 }
54 }else { // 新增 62 }else { // 新增
55 - boolean result = videoManagerStorager.addStreamProxy(param);  
56 - if (result && param.isEnable()) {  
57 - addStreamProxyToZlm(param); 63 + if (videoManagerStorager.addStreamProxy(param)){
  64 + result.append("保存成功");
  65 + if (param.isEnable()) {
  66 + JSONObject jsonObject = addStreamProxyToZlm(param);
  67 + if (jsonObject == null) {
  68 + result.append(", 但是启用失败,请检查流地址是否可用");
  69 + param.setEnable(false);
  70 + videoManagerStorager.updateStreamProxy(param);
  71 + }
  72 + }
58 } 73 }
  74 +
59 } 75 }
  76 + return result.toString();
60 } 77 }
61 78
62 @Override 79 @Override
@@ -105,6 +122,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -105,6 +122,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
105 StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); 122 StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
106 if (!streamProxy.isEnable() && streamProxy != null) { 123 if (!streamProxy.isEnable() && streamProxy != null) {
107 JSONObject jsonObject = addStreamProxyToZlm(streamProxy); 124 JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
  125 + if (jsonObject == null) return false;
108 if (jsonObject.getInteger("code") == 0) { 126 if (jsonObject.getInteger("code") == 0) {
109 result = true; 127 result = true;
110 streamProxy.setEnable(true); 128 streamProxy.setEnable(true);
src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.bean;
  2 +
  3 +public class WVPResult<T> {
  4 +
  5 + private int code;
  6 + private String msg;
  7 + private T data;
  8 +
  9 + public int getCode() {
  10 + return code;
  11 + }
  12 +
  13 + public void setCode(int code) {
  14 + this.code = code;
  15 + }
  16 +
  17 + public String getMsg() {
  18 + return msg;
  19 + }
  20 +
  21 + public void setMsg(String msg) {
  22 + this.msg = msg;
  23 + }
  24 +
  25 + public T getData() {
  26 + return data;
  27 + }
  28 +
  29 + public void setData(T data) {
  30 + this.data = data;
  31 + }
  32 +}
src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; 4 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
5 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 5 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
6 import com.genersoft.iot.vmp.service.IStreamProxyService; 6 import com.genersoft.iot.vmp.service.IStreamProxyService;
  7 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
7 import com.github.pagehelper.PageInfo; 8 import com.github.pagehelper.PageInfo;
8 import io.swagger.annotations.Api; 9 import io.swagger.annotations.Api;
9 import io.swagger.annotations.ApiImplicitParam; 10 import io.swagger.annotations.ApiImplicitParam;
@@ -56,10 +57,13 @@ public class StreamProxyController { @@ -56,10 +57,13 @@ public class StreamProxyController {
56 }) 57 })
57 @PostMapping(value = "/save") 58 @PostMapping(value = "/save")
58 @ResponseBody 59 @ResponseBody
59 - public Object save(@RequestBody StreamProxyItem param){ 60 + public WVPResult save(@RequestBody StreamProxyItem param){
60 logger.info("添加代理: " + JSONObject.toJSONString(param)); 61 logger.info("添加代理: " + JSONObject.toJSONString(param));
61 - streamProxyService.save(param);  
62 - return "success"; 62 + String msg = streamProxyService.save(param);
  63 + WVPResult<Object> result = new WVPResult<>();
  64 + result.setCode(0);
  65 + result.setMsg(msg);
  66 + return result;
63 } 67 }
64 68
65 @ApiOperation("移除代理") 69 @ApiOperation("移除代理")
@@ -69,10 +73,13 @@ public class StreamProxyController { @@ -69,10 +73,13 @@ public class StreamProxyController {
69 }) 73 })
70 @DeleteMapping(value = "/del") 74 @DeleteMapping(value = "/del")
71 @ResponseBody 75 @ResponseBody
72 - public Object del(String app, String stream){ 76 + public WVPResult del(String app, String stream){
73 logger.info("移除代理: " + app + "/" + stream); 77 logger.info("移除代理: " + app + "/" + stream);
74 streamProxyService.del(app, stream); 78 streamProxyService.del(app, stream);
75 - return "success"; 79 + WVPResult<Object> result = new WVPResult<>();
  80 + result.setCode(0);
  81 + result.setMsg("success");
  82 + return result;
76 } 83 }
77 84
78 @ApiOperation("启用代理") 85 @ApiOperation("启用代理")
@@ -85,7 +92,7 @@ public class StreamProxyController { @@ -85,7 +92,7 @@ public class StreamProxyController {
85 public Object start(String app, String stream){ 92 public Object start(String app, String stream){
86 logger.info("启用代理: " + app + "/" + stream); 93 logger.info("启用代理: " + app + "/" + stream);
87 boolean result = streamProxyService.start(app, stream); 94 boolean result = streamProxyService.start(app, stream);
88 - return "success"; 95 + return result?"success":"fail";
89 } 96 }
90 97
91 @ApiOperation("停用代理") 98 @ApiOperation("停用代理")
web_src/src/components/StreamProxyList.vue
@@ -19,13 +19,13 @@ @@ -19,13 +19,13 @@
19 <el-table-column label="流地址" width="400" align="center" show-overflow-tooltip > 19 <el-table-column label="流地址" width="400" align="center" show-overflow-tooltip >
20 <template slot-scope="scope"> 20 <template slot-scope="scope">
21 <div slot="reference" class="name-wrapper"> 21 <div slot="reference" class="name-wrapper">
22 - 22 +
23 <el-tag size="medium" v-if="scope.row.type == 'default'"> 23 <el-tag size="medium" v-if="scope.row.type == 'default'">
24 - <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i> 24 + <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
25 {{scope.row.url}} 25 {{scope.row.url}}
26 </el-tag> 26 </el-tag>
27 <el-tag size="medium" v-if="scope.row.type != 'default'"> 27 <el-tag size="medium" v-if="scope.row.type != 'default'">
28 - <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.src_url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i> 28 + <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.src_url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
29 {{scope.row.src_url}} 29 {{scope.row.src_url}}
30 </el-tag> 30 </el-tag>
31 </div> 31 </div>
@@ -97,7 +97,7 @@ @@ -97,7 +97,7 @@
97 }, 97 },
98 data() { 98 data() {
99 return { 99 return {
100 - streamProxyList: [], 100 + streamProxyList: [],
101 currentPusher: {}, //当前操作设备对象 101 currentPusher: {}, //当前操作设备对象
102 updateLooper: 0, //数据刷新轮训标志 102 updateLooper: 0, //数据刷新轮训标志
103 currentDeviceChannelsLenth:0, 103 currentDeviceChannelsLenth:0,
@@ -177,22 +177,21 @@ @@ -177,22 +177,21 @@
177 console.log(error); 177 console.log(error);
178 that.getListLoading = false; 178 that.getListLoading = false;
179 }); 179 });
180 - 180 +
181 }, 181 },
182 deleteStreamProxy: function(row){ 182 deleteStreamProxy: function(row){
183 - console.log(1111)  
184 let that = this; 183 let that = this;
185 this.getListLoading = true; 184 this.getListLoading = true;
186 that.$axios({ 185 that.$axios({
187 method:"delete", 186 method:"delete",
188 url:"/api/proxy/del", 187 url:"/api/proxy/del",
189 params:{ 188 params:{
190 - app: row.app,  
191 - stream: row.stream  
192 - } 189 + app: row.app,
  190 + stream: row.stream
  191 + }
193 }).then((res)=>{ 192 }).then((res)=>{
194 that.getListLoading = false; 193 that.getListLoading = false;
195 - that.initData() 194 + that.initData()
196 }).catch(function (error) { 195 }).catch(function (error) {
197 console.log(error); 196 console.log(error);
198 that.getListLoading = false; 197 that.getListLoading = false;
@@ -210,9 +209,18 @@ @@ -210,9 +209,18 @@
210 stream: row.stream 209 stream: row.stream
211 } 210 }
212 }).then(function (res) { 211 }).then(function (res) {
213 - that.getListLoading = false;  
214 - that.startBtnLaoding = false;  
215 - that.initData() 212 + that.getListLoading = false;
  213 + that.startBtnLaoding = false;
  214 + if (res.data == "success"){
  215 + that.initData()
  216 + }else {
  217 + that.$message({
  218 + showClose: true,
  219 + message: "保存失败,请检查地址是否可用!",
  220 + type: "error",
  221 + });
  222 + }
  223 +
216 }).catch(function (error) { 224 }).catch(function (error) {
217 console.log(error); 225 console.log(error);
218 that.getListLoading = false; 226 that.getListLoading = false;
web_src/src/components/dialog/StreamProxyEdit.vue
@@ -151,22 +151,20 @@ export default { @@ -151,22 +151,20 @@ export default {
151 url:`/api/proxy/save`, 151 url:`/api/proxy/save`,
152 data: that.proxyParam 152 data: that.proxyParam
153 }).then(function (res) { 153 }).then(function (res) {
154 - console.log(res);  
155 - console.log(res.data == "success");  
156 - if (res.data == "success") {  
157 - that.$message({  
158 - showClose: true,  
159 - message: "保存成功",  
160 - type: "success",  
161 - });  
162 - that.showDialog = false;  
163 - if (that.listChangeCallback != null) {  
164 - that.listChangeCallback();  
165 - } 154 + if (typeof (res.data.code) != "undefined" && res.data.code === 0) {
  155 + that.$message({
  156 + showClose: true,
  157 + message: res.data.msg,
  158 + type: "success",
  159 + });
  160 + that.showDialog = false;
  161 + if (that.listChangeCallback != null) {
  162 + that.listChangeCallback();
166 } 163 }
167 - }).catch(function (error) {  
168 - console.log(error);  
169 - }); 164 + }
  165 + }).catch(function (error) {
  166 + console.log(error);
  167 + });
170 }, 168 },
171 close: function () { 169 close: function () {
172 console.log("关闭添加视频平台"); 170 console.log("关闭添加视频平台");