Browse Source

Merge pull request #14 from lawrencehj/wvp-28181-2.0

修正上级注册的代码
pull/15/head
648540858 4 years ago
committed by GitHub
parent
commit
bc2e5e7a37
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
  2. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
  3. 16
      src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
  4. 142
      web_src/src/components/platformEdit.vue

12
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java

@ -173,7 +173,7 @@ public class SIPRequestHeaderProvider {
} }
public Request createRegisterRequest(@NotNull ParentPlatform platform, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException { public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null; Request request = null;
String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort(); String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort();
//请求行 //请求行
@ -206,7 +206,7 @@ public class SIPRequestHeaderProvider {
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
//ceq //ceq
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.REGISTER); CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(CSeq, Request.REGISTER);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader, request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader,
cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
@ -214,12 +214,15 @@ public class SIPRequestHeaderProvider {
.createSipURI(platform.getDeviceGBId(), sipAddress)); .createSipURI(platform.getDeviceGBId(), sipAddress));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(3600);
request.addHeader(expires);
return request; return request;
} }
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag, public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException { String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException {
Request registerRequest = createRegisterRequest(parentPlatform, fromTag, viaTag); Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME); CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
callIdHeader.setCallId(callId); callIdHeader.setCallId(callId);
@ -233,8 +236,7 @@ public class SIPRequestHeaderProvider {
String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes()); String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes());
String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\"" String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\""
+ realm + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\", nonce=\"" + realm + "\", nonce=\"" + nonce + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\"" + ", algorithm=MD5";
+ nonce + "\"";
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent); AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent);
registerRequest.addHeader(authorizationHeader); registerRequest.addHeader(authorizationHeader);

2
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java

@ -52,7 +52,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
try { try {
Request request = null; Request request = null;
if (realm == null || nonce == null) { if (realm == null || nonce == null) {
request = headerProvider.createRegisterRequest(parentPlatform, null, null); request = headerProvider.createRegisterRequest(parentPlatform, 1L, null, null);
}else { }else {
request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme); request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme);
} }

16
src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.vmanager.platform; package com.genersoft.iot.vmp.vmanager.platform;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.common.PageResult;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
@ -15,6 +16,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.genersoft.iot.vmp.conf.SipConfig;
@CrossOrigin @CrossOrigin
@RestController @RestController
@ -29,6 +32,19 @@ public class PlatformController {
@Autowired @Autowired
private ISIPCommanderForPlatform commanderForPlatform; private ISIPCommanderForPlatform commanderForPlatform;
@Autowired
private SipConfig sipConfig;
@GetMapping("/platforms/serverconfig")
public ResponseEntity<JSONObject> serverConfig() {
JSONObject result = new JSONObject();
result.put("deviceIp", sipConfig.getSipIp());
result.put("devicePort", sipConfig.getSipPort());
result.put("username", sipConfig.getSipId());
result.put("password", sipConfig.getSipPassword());
return new ResponseEntity<>(result, HttpStatus.OK);
}
@GetMapping("/platforms/{count}/{page}") @GetMapping("/platforms/{count}/{page}")
public PageResult<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count){ public PageResult<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count){

142
web_src/src/components/platformEdit.vue

@ -1,8 +1,15 @@
<template> <template>
<div id="addlatform" v-loading="isLoging"> <div id="addlatform" v-loading="isLoging">
<el-dialog title="添加平台" width="70%" top="2rem" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()"> <el-dialog
<div id="shared" style="text-align: right; margin-top: 1rem;"> title="添加平台"
width="70%"
top="2rem"
:close-on-click-modal="false"
:visible.sync="showDialog"
:destroy-on-close="true"
@close="close()"
>
<div id="shared" style="text-align: right; margin-top: 1rem">
<el-row :gutter="24"> <el-row :gutter="24">
<el-col :span="11"> <el-col :span="11">
<el-form ref="platform1" :rules="rules" :model="platform" label-width="160px"> <el-form ref="platform1" :rules="rules" :model="platform" label-width="160px">
@ -30,7 +37,6 @@
<el-form-item label="本地端口" prop="devicePort"> <el-form-item label="本地端口" prop="devicePort">
<el-input v-model="platform.devicePort" :disabled="true"></el-input> <el-input v-model="platform.devicePort" :disabled="true"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
@ -48,13 +54,21 @@
<el-input v-model="platform.keepTimeout"></el-input> <el-input v-model="platform.keepTimeout"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="信令传输" prop="transport"> <el-form-item label="信令传输" prop="transport">
<el-select v-model="platform.transport" style="width:100%" placeholder="请选择信令传输方式"> <el-select
v-model="platform.transport"
style="width: 100%"
placeholder="请选择信令传输方式"
>
<el-option label="UDP" value="UDP"></el-option> <el-option label="UDP" value="UDP"></el-option>
<el-option label="TCP" value="TCP"></el-option> <el-option label="TCP" value="TCP"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="字符集" prop="characterSet"> <el-form-item label="字符集" prop="characterSet">
<el-select v-model="platform.characterSet" style="width:100%" placeholder="请选择字符集"> <el-select
v-model="platform.characterSet"
style="width: 100%"
placeholder="请选择字符集"
>
<el-option label="GB2312" value="GB2312"></el-option> <el-option label="GB2312" value="GB2312"></el-option>
<el-option label="UTF-8" value="UTF-8"></el-option> <el-option label="UTF-8" value="UTF-8"></el-option>
</el-select> </el-select>
@ -65,7 +79,9 @@
<el-checkbox label="RTCP保活" v-model="platform.rtcp"></el-checkbox> <el-checkbox label="RTCP保活" v-model="platform.rtcp"></el-checkbox>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit">{{onSubmit_text}}</el-button> <el-button type="primary" @click="onSubmit">{{
onSubmit_text
}}</el-button>
<el-button @click="close">取消</el-button> <el-button @click="close">取消</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -78,24 +94,22 @@
<script> <script>
export default { export default {
name: 'platformEdit', name: "platformEdit",
props: {}, props: {},
computed: { computed: {},
},
created() {}, created() {},
data() { data() {
var deviceGBIdRules = async (rule, value, callback) => { var deviceGBIdRules = async (rule, value, callback) => {
console.log(value) console.log(value);
if (value === '') { if (value === "") {
callback(new Error('请输入设备国标编号')); callback(new Error("请输入设备国标编号"));
} else { } else {
var exit = await this.deviceGBIdExit(value); var exit = await this.deviceGBIdExit(value);
console.log(exit) console.log(exit);
console.log(exit == "true") console.log(exit == "true");
console.log(exit === "true") console.log(exit === "true");
if (exit) { if (exit) {
callback(new Error('设备国标编号已存在')); callback(new Error("设备国标编号已存在"));
} else { } else {
callback(); callback();
} }
@ -145,71 +159,66 @@ export default {
characterSet: "GB2312", characterSet: "GB2312",
}, },
rules: { rules: {
name: [ name: [{ required: true, message: "请输入平台名称", trigger: "blur" }],
{ required: true, message:"请输入平台名称", trigger: 'blur' }
],
serverGBId: [ serverGBId: [
{ required: true, message:"请输入SIP服务国标编码", trigger: 'blur' } { required: true, message: "请输入SIP服务国标编码", trigger: "blur" },
], ],
serverGBDomain: [ serverGBDomain: [
{ required: true, message:"请输入SIP服务国标域", trigger: 'blur' } { required: true, message: "请输入SIP服务国标域", trigger: "blur" },
],
serverIP: [
{ required: true, message:"请输入SIP服务IP", trigger: 'blur' }
],
serverPort: [
{ required: true, message:"请输入SIP服务端口", trigger: 'blur' }
],
deviceGBId: [
{validator: deviceGBIdRules, trigger: 'blur' }
], ],
username: [ serverIP: [{ required: true, message: "请输入SIP服务IP", trigger: "blur" }],
{ required: false, message:"请输入SIP认证用户名", trigger: 'blur' } serverPort: [{ required: true, message: "请输入SIP服务端口", trigger: "blur" }],
], deviceGBId: [{ validator: deviceGBIdRules, trigger: "blur" }],
password: [ username: [{ required: false, message: "请输入SIP认证用户名", trigger: "blur" }],
{ required: false, message:"请输入SIP认证密码", trigger: 'blur' } password: [{ required: false, message: "请输入SIP认证密码", trigger: "blur" }],
], expires: [{ required: true, message: "请输入注册周期", trigger: "blur" }],
expires: [ keepTimeout: [{ required: true, message: "请输入心跳周期", trigger: "blur" }],
{ required: true, message:"请输入注册周期", trigger: 'blur' } transport: [{ required: true, message: "请选择信令传输", trigger: "blur" }],
], characterSet: [{ required: true, message: "请选择编码字符集", trigger: "blur" }],
keepTimeout: [ },
{ required: true, message:"请输入心跳周期", trigger: 'blur' }
],
transport: [
{ required: true, message:"请选择信令传输", trigger: 'blur' }
],
characterSet: [
{ required: true, message:"请选择编码字符集", trigger: 'blur' }
]
}
}; };
}, },
methods: { methods: {
openDialog: function (platform, callback) { openDialog: function (platform, callback) {
var that = this;
this.$axios
.get(`/api/platforms/serverconfig`)
.then(function (res) {
console.log(res);
that.platform.deviceGBId = res.data.username;
that.platform.deviceIp = res.data.deviceIp;
that.platform.devicePort = res.data.devicePort;
that.platform.username = res.data.username;
that.platform.password = res.data.password;
})
.catch(function (error) {
console.log(error);
});
this.showDialog = true; this.showDialog = true;
this.listChangeCallback = callback; this.listChangeCallback = callback;
if (platform != null) { if (platform != null) {
this.platform = platform; this.platform = platform;
this.onSubmit_text = "保存" this.onSubmit_text = "保存";
} else {
} }
}, },
onSubmit: function () { onSubmit: function () {
console.log('onSubmit'); console.log("onSubmit");
var that = this; var that = this;
that.$axios.post(`/api/platforms/save`, that.platform) that.$axios
.post(`/api/platforms/save`, that.platform)
.then(function (res) { .then(function (res) {
console.log(res) console.log(res);
console.log(res.data == "success") console.log(res.data == "success");
if (res.data == "success") { if (res.data == "success") {
that.$message({ that.$message({
showClose: true, showClose: true,
message: '保存成功', message: "保存成功",
type: 'success' type: "success",
}); });
that.showDialog = false; that.showDialog = false;
if (that.listChangeCallback != null) { if (that.listChangeCallback != null) {
that.listChangeCallback() that.listChangeCallback();
} }
} }
}) })
@ -218,15 +227,16 @@ export default {
}); });
}, },
close: function () { close: function () {
console.log('关闭添加视频平台'); console.log("关闭添加视频平台");
this.showDialog = false; this.showDialog = false;
this.$refs.platform1.resetFields(); this.$refs.platform1.resetFields();
this.$refs.platform2.resetFields(); this.$refs.platform2.resetFields();
}, },
deviceGBIdExit: async function (deviceGbId) { deviceGBIdExit: async function (deviceGbId) {
var result = false; var result = false;
var that = this var that = this;
await that.$axios.post(`/api/platforms/exit/${deviceGbId}`) await that.$axios
.post(`/api/platforms/exit/${deviceGbId}`)
.then(function (res) { .then(function (res) {
result = res.data; result = res.data;
}) })
@ -234,10 +244,8 @@ export default {
console.log(error); console.log(error);
}); });
return result; return result;
},
} },
}
}; };
</script> </script>

Loading…
Cancel
Save