Commit 118e42884e677a99dbdd20349eaad85c96bafeb4
1 parent
6289438e
优化拉流代理
Showing
8 changed files
with
114 additions
and
44 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
| ... | ... | @@ -43,7 +43,9 @@ public class ZLMRESTfulUtils { |
| 43 | 43 | builder.add("secret",mediaSecret); |
| 44 | 44 | if (param != null && param.keySet().size() > 0) { |
| 45 | 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 | 170 | List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true); |
| 171 | 171 | for (StreamProxyItem streamProxyDto : streamProxyListForEnable) { |
| 172 | 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
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
| ... | ... | @@ -40,23 +40,40 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | @Override |
| 43 | - public void save(StreamProxyItem param) { | |
| 43 | + public String save(StreamProxyItem param) { | |
| 44 | 44 | MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); |
| 45 | 45 | String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), |
| 46 | 46 | param.getStream() ); |
| 47 | 47 | param.setDst_url(dstUrl); |
| 48 | + StringBuffer result = new StringBuffer(); | |
| 48 | 49 | // 更新 |
| 49 | 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 | 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 | 79 | @Override |
| ... | ... | @@ -105,6 +122,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 105 | 122 | StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); |
| 106 | 123 | if (!streamProxy.isEnable() && streamProxy != null) { |
| 107 | 124 | JSONObject jsonObject = addStreamProxyToZlm(streamProxy); |
| 125 | + if (jsonObject == null) return false; | |
| 108 | 126 | if (jsonObject.getInteger("code") == 0) { |
| 109 | 127 | result = true; |
| 110 | 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 | 4 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 5 | 5 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 6 | 6 | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| 7 | +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | |
| 7 | 8 | import com.github.pagehelper.PageInfo; |
| 8 | 9 | import io.swagger.annotations.Api; |
| 9 | 10 | import io.swagger.annotations.ApiImplicitParam; |
| ... | ... | @@ -56,10 +57,13 @@ public class StreamProxyController { |
| 56 | 57 | }) |
| 57 | 58 | @PostMapping(value = "/save") |
| 58 | 59 | @ResponseBody |
| 59 | - public Object save(@RequestBody StreamProxyItem param){ | |
| 60 | + public WVPResult save(@RequestBody StreamProxyItem param){ | |
| 60 | 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 | 69 | @ApiOperation("移除代理") |
| ... | ... | @@ -69,10 +73,13 @@ public class StreamProxyController { |
| 69 | 73 | }) |
| 70 | 74 | @DeleteMapping(value = "/del") |
| 71 | 75 | @ResponseBody |
| 72 | - public Object del(String app, String stream){ | |
| 76 | + public WVPResult del(String app, String stream){ | |
| 73 | 77 | logger.info("移除代理: " + app + "/" + stream); |
| 74 | 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 | 85 | @ApiOperation("启用代理") |
| ... | ... | @@ -85,7 +92,7 @@ public class StreamProxyController { |
| 85 | 92 | public Object start(String app, String stream){ |
| 86 | 93 | logger.info("启用代理: " + app + "/" + stream); |
| 87 | 94 | boolean result = streamProxyService.start(app, stream); |
| 88 | - return "success"; | |
| 95 | + return result?"success":"fail"; | |
| 89 | 96 | } |
| 90 | 97 | |
| 91 | 98 | @ApiOperation("停用代理") | ... | ... |
web_src/src/components/StreamProxyList.vue
| ... | ... | @@ -19,13 +19,13 @@ |
| 19 | 19 | <el-table-column label="流地址" width="400" align="center" show-overflow-tooltip > |
| 20 | 20 | <template slot-scope="scope"> |
| 21 | 21 | <div slot="reference" class="name-wrapper"> |
| 22 | - | |
| 22 | + | |
| 23 | 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 | 25 | {{scope.row.url}} |
| 26 | 26 | </el-tag> |
| 27 | 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 | 29 | {{scope.row.src_url}} |
| 30 | 30 | </el-tag> |
| 31 | 31 | </div> |
| ... | ... | @@ -97,7 +97,7 @@ |
| 97 | 97 | }, |
| 98 | 98 | data() { |
| 99 | 99 | return { |
| 100 | - streamProxyList: [], | |
| 100 | + streamProxyList: [], | |
| 101 | 101 | currentPusher: {}, //当前操作设备对象 |
| 102 | 102 | updateLooper: 0, //数据刷新轮训标志 |
| 103 | 103 | currentDeviceChannelsLenth:0, |
| ... | ... | @@ -177,22 +177,21 @@ |
| 177 | 177 | console.log(error); |
| 178 | 178 | that.getListLoading = false; |
| 179 | 179 | }); |
| 180 | - | |
| 180 | + | |
| 181 | 181 | }, |
| 182 | 182 | deleteStreamProxy: function(row){ |
| 183 | - console.log(1111) | |
| 184 | 183 | let that = this; |
| 185 | 184 | this.getListLoading = true; |
| 186 | 185 | that.$axios({ |
| 187 | 186 | method:"delete", |
| 188 | 187 | url:"/api/proxy/del", |
| 189 | 188 | params:{ |
| 190 | - app: row.app, | |
| 191 | - stream: row.stream | |
| 192 | - } | |
| 189 | + app: row.app, | |
| 190 | + stream: row.stream | |
| 191 | + } | |
| 193 | 192 | }).then((res)=>{ |
| 194 | 193 | that.getListLoading = false; |
| 195 | - that.initData() | |
| 194 | + that.initData() | |
| 196 | 195 | }).catch(function (error) { |
| 197 | 196 | console.log(error); |
| 198 | 197 | that.getListLoading = false; |
| ... | ... | @@ -210,9 +209,18 @@ |
| 210 | 209 | stream: row.stream |
| 211 | 210 | } |
| 212 | 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 | 224 | }).catch(function (error) { |
| 217 | 225 | console.log(error); |
| 218 | 226 | that.getListLoading = false; | ... | ... |
web_src/src/components/dialog/StreamProxyEdit.vue
| ... | ... | @@ -151,22 +151,20 @@ export default { |
| 151 | 151 | url:`/api/proxy/save`, |
| 152 | 152 | data: that.proxyParam |
| 153 | 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 | 169 | close: function () { |
| 172 | 170 | console.log("关闭添加视频平台"); | ... | ... |