Browse Source

优化拉流代理

pull/93/head
panlinlin 4 years ago
parent
commit
118e42884e
  1. 4
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
  2. 7
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
  3. 2
      src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java
  4. 32
      src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
  5. 32
      src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java
  6. 19
      src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java
  7. 34
      web_src/src/components/StreamProxyList.vue
  8. 28
      web_src/src/components/dialog/StreamProxyEdit.vue

4
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java

@ -43,7 +43,9 @@ public class ZLMRESTfulUtils {
builder.add("secret",mediaSecret); builder.add("secret",mediaSecret);
if (param != null && param.keySet().size() > 0) { if (param != null && param.keySet().size() > 0) {
for (String key : param.keySet()){ for (String key : param.keySet()){
builder.add(key, param.get(key).toString()); if (param.get(key) != null) {
builder.add(key, param.get(key).toString());
}
} }
} }

7
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java

@ -170,7 +170,12 @@ public class ZLMRunner implements CommandLineRunner {
List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true); List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true);
for (StreamProxyItem streamProxyDto : streamProxyListForEnable) { for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream()); 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());
}
} }
} }
} }

2
src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java

@ -10,7 +10,7 @@ public interface IStreamProxyService {
* 保存视频代理 * 保存视频代理
* @param param * @param param
*/ */
void save(StreamProxyItem param); String save(StreamProxyItem param);
/** /**
* 添加视频代理到zlm * 添加视频代理到zlm

32
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java

@ -40,23 +40,40 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
@Override @Override
public void save(StreamProxyItem param) { public String save(StreamProxyItem param) {
MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
param.getStream() ); param.getStream() );
param.setDst_url(dstUrl); param.setDst_url(dstUrl);
StringBuffer result = new StringBuffer();
// 更新 // 更新
if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) {
boolean result = videoManagerStorager.updateStreamProxy(param); if (videoManagerStorager.updateStreamProxy(param)) {
if (result && param.isEnable()) { result.append("保存成功");
addStreamProxyToZlm(param); if (param.isEnable()){
JSONObject jsonObject = addStreamProxyToZlm(param);
if (jsonObject == null) {
result.append(", 但是启用失败,请检查流地址是否可用");
param.setEnable(false);
videoManagerStorager.updateStreamProxy(param);
}
}
} }
}else { // 新增 }else { // 新增
boolean result = videoManagerStorager.addStreamProxy(param); if (videoManagerStorager.addStreamProxy(param)){
if (result && param.isEnable()) { result.append("保存成功");
addStreamProxyToZlm(param); if (param.isEnable()) {
JSONObject jsonObject = addStreamProxyToZlm(param);
if (jsonObject == null) {
result.append(", 但是启用失败,请检查流地址是否可用");
param.setEnable(false);
videoManagerStorager.updateStreamProxy(param);
}
}
} }
} }
return result.toString();
} }
@Override @Override
@ -105,6 +122,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
if (!streamProxy.isEnable() && streamProxy != null) { if (!streamProxy.isEnable() && streamProxy != null) {
JSONObject jsonObject = addStreamProxyToZlm(streamProxy); JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
if (jsonObject == null) return false;
if (jsonObject.getInteger("code") == 0) { if (jsonObject.getInteger("code") == 0) {
result = true; result = true;
streamProxy.setEnable(true); streamProxy.setEnable(true);

32
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<T> {
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;
}
}

19
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.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.service.IStreamProxyService; import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -56,10 +57,13 @@ public class StreamProxyController {
}) })
@PostMapping(value = "/save") @PostMapping(value = "/save")
@ResponseBody @ResponseBody
public Object save(@RequestBody StreamProxyItem param){ public WVPResult save(@RequestBody StreamProxyItem param){
logger.info("添加代理: " + JSONObject.toJSONString(param)); logger.info("添加代理: " + JSONObject.toJSONString(param));
streamProxyService.save(param); String msg = streamProxyService.save(param);
return "success"; WVPResult<Object> result = new WVPResult<>();
result.setCode(0);
result.setMsg(msg);
return result;
} }
@ApiOperation("移除代理") @ApiOperation("移除代理")
@ -69,10 +73,13 @@ public class StreamProxyController {
}) })
@DeleteMapping(value = "/del") @DeleteMapping(value = "/del")
@ResponseBody @ResponseBody
public Object del(String app, String stream){ public WVPResult del(String app, String stream){
logger.info("移除代理: " + app + "/" + stream); logger.info("移除代理: " + app + "/" + stream);
streamProxyService.del(app, stream); streamProxyService.del(app, stream);
return "success"; WVPResult<Object> result = new WVPResult<>();
result.setCode(0);
result.setMsg("success");
return result;
} }
@ApiOperation("启用代理") @ApiOperation("启用代理")
@ -85,7 +92,7 @@ public class StreamProxyController {
public Object start(String app, String stream){ public Object start(String app, String stream){
logger.info("启用代理: " + app + "/" + stream); logger.info("启用代理: " + app + "/" + stream);
boolean result = streamProxyService.start(app, stream); boolean result = streamProxyService.start(app, stream);
return "success"; return result?"success":"fail";
} }
@ApiOperation("停用代理") @ApiOperation("停用代理")

34
web_src/src/components/StreamProxyList.vue

@ -19,13 +19,13 @@
<el-table-column label="流地址" width="400" align="center" show-overflow-tooltip > <el-table-column label="流地址" width="400" align="center" show-overflow-tooltip >
<template slot-scope="scope"> <template slot-scope="scope">
<div slot="reference" class="name-wrapper"> <div slot="reference" class="name-wrapper">
<el-tag size="medium" v-if="scope.row.type == 'default'"> <el-tag size="medium" v-if="scope.row.type == 'default'">
<i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i> <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
{{scope.row.url}} {{scope.row.url}}
</el-tag> </el-tag>
<el-tag size="medium" v-if="scope.row.type != 'default'"> <el-tag size="medium" v-if="scope.row.type != 'default'">
<i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.src_url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i> <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.src_url" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
{{scope.row.src_url}} {{scope.row.src_url}}
</el-tag> </el-tag>
</div> </div>
@ -97,7 +97,7 @@
}, },
data() { data() {
return { return {
streamProxyList: [], streamProxyList: [],
currentPusher: {}, // currentPusher: {}, //
updateLooper: 0, // updateLooper: 0, //
currentDeviceChannelsLenth:0, currentDeviceChannelsLenth:0,
@ -177,22 +177,21 @@
console.log(error); console.log(error);
that.getListLoading = false; that.getListLoading = false;
}); });
}, },
deleteStreamProxy: function(row){ deleteStreamProxy: function(row){
console.log(1111)
let that = this; let that = this;
this.getListLoading = true; this.getListLoading = true;
that.$axios({ that.$axios({
method:"delete", method:"delete",
url:"/api/proxy/del", url:"/api/proxy/del",
params:{ params:{
app: row.app, app: row.app,
stream: row.stream stream: row.stream
} }
}).then((res)=>{ }).then((res)=>{
that.getListLoading = false; that.getListLoading = false;
that.initData() that.initData()
}).catch(function (error) { }).catch(function (error) {
console.log(error); console.log(error);
that.getListLoading = false; that.getListLoading = false;
@ -210,9 +209,18 @@
stream: row.stream stream: row.stream
} }
}).then(function (res) { }).then(function (res) {
that.getListLoading = false; that.getListLoading = false;
that.startBtnLaoding = false; that.startBtnLaoding = false;
that.initData() if (res.data == "success"){
that.initData()
}else {
that.$message({
showClose: true,
message: "保存失败,请检查地址是否可用!",
type: "error",
});
}
}).catch(function (error) { }).catch(function (error) {
console.log(error); console.log(error);
that.getListLoading = false; that.getListLoading = false;

28
web_src/src/components/dialog/StreamProxyEdit.vue

@ -151,22 +151,20 @@ export default {
url:`/api/proxy/save`, url:`/api/proxy/save`,
data: that.proxyParam data: that.proxyParam
}).then(function (res) { }).then(function (res) {
console.log(res); if (typeof (res.data.code) != "undefined" && res.data.code === 0) {
console.log(res.data == "success"); that.$message({
if (res.data == "success") { showClose: true,
that.$message({ message: res.data.msg,
showClose: true, type: "success",
message: "保存成功", });
type: "success", that.showDialog = false;
}); if (that.listChangeCallback != null) {
that.showDialog = false; that.listChangeCallback();
if (that.listChangeCallback != null) {
that.listChangeCallback();
}
} }
}).catch(function (error) { }
console.log(error); }).catch(function (error) {
}); console.log(error);
});
}, },
close: function () { close: function () {
console.log("关闭添加视频平台"); console.log("关闭添加视频平台");

Loading…
Cancel
Save