完成向上级联->删除的时候注销
This commit is contained in:
parent
627a14f37e
commit
54d7953179
@ -10,6 +10,8 @@ public class ParentPlatformCatch {
|
|||||||
// 注册未回复次数
|
// 注册未回复次数
|
||||||
private int registerAliveReply;
|
private int registerAliveReply;
|
||||||
|
|
||||||
|
private ParentPlatform parentPlatform;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -33,4 +35,12 @@ public class ParentPlatformCatch {
|
|||||||
public void setRegisterAliveReply(int registerAliveReply) {
|
public void setRegisterAliveReply(int registerAliveReply) {
|
||||||
this.registerAliveReply = registerAliveReply;
|
this.registerAliveReply = registerAliveReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ParentPlatform getParentPlatform() {
|
||||||
|
return parentPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentPlatform(ParentPlatform parentPlatform) {
|
||||||
|
this.parentPlatform = parentPlatform;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener<P
|
|||||||
}
|
}
|
||||||
ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID());
|
ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID());
|
||||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID());
|
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID());
|
||||||
|
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||||
if (parentPlatform == null) {
|
if (parentPlatform == null) {
|
||||||
logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
|
logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||||
|
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||||
|
|
||||||
|
import javax.sip.header.WWWAuthenticateHeader;
|
||||||
|
|
||||||
public interface ISIPCommanderForPlatform {
|
public interface ISIPCommanderForPlatform {
|
||||||
|
|
||||||
@ -11,7 +14,14 @@ public interface ISIPCommanderForPlatform {
|
|||||||
*/
|
*/
|
||||||
boolean register(ParentPlatform parentPlatform);
|
boolean register(ParentPlatform parentPlatform);
|
||||||
|
|
||||||
boolean register(ParentPlatform parentPlatform, String callId, String realm, String nonce, String scheme);
|
/**
|
||||||
|
* 向上级平台注销
|
||||||
|
* @param parentPlatform
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
|
||||||
|
|
||||||
|
boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向上级平发送心跳信息
|
* 向上级平发送心跳信息
|
||||||
|
@ -20,10 +20,11 @@ import javax.sip.message.Request;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:摄像头命令request创造器 TODO 冗余代码太多待优化
|
* @Description: 平台命令request创造器 TODO 冗余代码太多待优化
|
||||||
* @author: swwheihei
|
* @author: panll
|
||||||
* @date: 2020年5月6日 上午9:29:02
|
* @date: 2020年5月6日 上午9:29:02
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@ -79,7 +80,7 @@ public class SIPRequestHeaderPlarformProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
//请求行
|
//请求行
|
||||||
@ -112,7 +113,7 @@ public class SIPRequestHeaderPlarformProvider {
|
|||||||
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);
|
||||||
|
|
||||||
@ -120,28 +121,73 @@ public class SIPRequestHeaderPlarformProvider {
|
|||||||
.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(Integer.parseInt(platform.getExpires()));
|
||||||
|
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, WWWAuthenticateHeader www ) throws ParseException, PeerUnavailableException, InvalidArgumentException {
|
||||||
Request registerRequest = createRegisterRequest(parentPlatform, fromTag, viaTag);
|
Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
|
||||||
|
|
||||||
|
String realm = www.getRealm();
|
||||||
|
String nonce = www.getNonce();
|
||||||
|
String scheme = www.getScheme();
|
||||||
|
|
||||||
|
// 参考 https://blog.csdn.net/y673533511/article/details/88388138
|
||||||
|
// qop 保护质量 包含auth(默认的)和auth-int(增加了报文完整性检测)两种策略
|
||||||
|
String qop = www.getQop();
|
||||||
|
|
||||||
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
|
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
|
||||||
callIdHeader.setCallId(callId);
|
callIdHeader.setCallId(callId);
|
||||||
|
|
||||||
String uri = "sip:" + parentPlatform.getServerGBId() +
|
|
||||||
"@" + parentPlatform.getServerIP() +
|
|
||||||
":" + parentPlatform.getServerPort();
|
|
||||||
|
|
||||||
|
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
|
||||||
|
String cNonce = null;
|
||||||
|
String nc = "00000001";
|
||||||
|
if (qop != null) {
|
||||||
|
if ("auth".equals(qop)) {
|
||||||
|
// 客户端随机数,这是一个不透明的字符串值,由客户端提供,并且客户端和服务器都会使用,以避免用明文文本。
|
||||||
|
// 这使得双方都可以查验对方的身份,并对消息的完整性提供一些保护
|
||||||
|
cNonce = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
}else if ("auth-int".equals(qop)){
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes());
|
String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes());
|
||||||
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes());
|
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + requestURI.toString()).getBytes());
|
||||||
String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes());
|
|
||||||
|
|
||||||
String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\""
|
StringBuffer reStr = new StringBuffer(200);
|
||||||
+ realm + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\", nonce=\""
|
reStr.append(HA1);
|
||||||
+ nonce + "\"";
|
reStr.append(":");
|
||||||
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent);
|
reStr.append(nonce);
|
||||||
|
reStr.append(":");
|
||||||
|
if (qop != null) {
|
||||||
|
reStr.append(nc);
|
||||||
|
reStr.append(":");
|
||||||
|
reStr.append(cNonce);
|
||||||
|
reStr.append(":");
|
||||||
|
reStr.append(qop);
|
||||||
|
reStr.append(":");
|
||||||
|
}
|
||||||
|
reStr.append(HA2);
|
||||||
|
|
||||||
|
String RESPONSE = DigestUtils.md5DigestAsHex(reStr.toString().getBytes());
|
||||||
|
|
||||||
|
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(scheme);
|
||||||
|
authorizationHeader.setUsername(parentPlatform.getDeviceGBId());
|
||||||
|
authorizationHeader.setRealm(realm);
|
||||||
|
authorizationHeader.setNonce(nonce);
|
||||||
|
authorizationHeader.setURI(requestURI);
|
||||||
|
authorizationHeader.setResponse(RESPONSE);
|
||||||
|
authorizationHeader.setAlgorithm("MD5");
|
||||||
|
if (qop != null) {
|
||||||
|
authorizationHeader.setQop(qop);
|
||||||
|
authorizationHeader.setCNonce(cNonce);
|
||||||
|
authorizationHeader.setNonceCount(1);
|
||||||
|
}
|
||||||
registerRequest.addHeader(authorizationHeader);
|
registerRequest.addHeader(authorizationHeader);
|
||||||
|
|
||||||
return registerRequest;
|
return registerRequest;
|
||||||
|
@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.sip.InvalidArgumentException;
|
import javax.sip.InvalidArgumentException;
|
||||||
import javax.sip.PeerUnavailableException;
|
import javax.sip.PeerUnavailableException;
|
||||||
@ -167,109 +168,4 @@ public class SIPRequestHeaderProvider {
|
|||||||
request.setContent(content, contentTypeHeader);
|
request.setContent(content, contentTypeHeader);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
|
||||||
Request request = null;
|
|
||||||
String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort();
|
|
||||||
//请求行
|
|
||||||
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),
|
|
||||||
platform.getServerIP() + ":" + platform.getServerPort());
|
|
||||||
//via
|
|
||||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
|
||||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(platform.getServerIP(), platform.getServerPort(), platform.getTransport(), viaTag);
|
|
||||||
viaHeader.setRPort();
|
|
||||||
viaHeaders.add(viaHeader);
|
|
||||||
//from
|
|
||||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress);
|
|
||||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
|
||||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
|
||||||
//to
|
|
||||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress);
|
|
||||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
|
||||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
|
|
||||||
|
|
||||||
//callid
|
|
||||||
CallIdHeader callIdHeader = null;
|
|
||||||
if(platform.getTransport().equals("TCP")) {
|
|
||||||
callIdHeader = tcpSipProvider.getNewCallId();
|
|
||||||
}
|
|
||||||
if(platform.getTransport().equals("UDP")) {
|
|
||||||
callIdHeader = udpSipProvider.getNewCallId();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Forwards
|
|
||||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
|
||||||
|
|
||||||
//ceq
|
|
||||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(CSeq, Request.REGISTER);
|
|
||||||
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader,
|
|
||||||
cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
|
|
||||||
|
|
||||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
|
||||||
.createSipURI(platform.getDeviceGBId(), sipAddress));
|
|
||||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
|
||||||
|
|
||||||
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
|
|
||||||
request.addHeader(expires);
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
|
|
||||||
String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException {
|
|
||||||
Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
|
|
||||||
|
|
||||||
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
|
|
||||||
callIdHeader.setCallId(callId);
|
|
||||||
|
|
||||||
String uri = "sip:" + parentPlatform.getServerGBId() +
|
|
||||||
"@" + parentPlatform.getServerIP() +
|
|
||||||
":" + parentPlatform.getServerPort();
|
|
||||||
|
|
||||||
String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes());
|
|
||||||
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes());
|
|
||||||
String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes());
|
|
||||||
|
|
||||||
String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\""
|
|
||||||
+ realm + "\", nonce=\"" + nonce + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\"" + ", algorithm=MD5";
|
|
||||||
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent);
|
|
||||||
registerRequest.addHeader(authorizationHeader);
|
|
||||||
|
|
||||||
return registerRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public Request createKeetpaliveMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String toTag, Object o) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
|
||||||
// Request request = null;
|
|
||||||
// // sipuri
|
|
||||||
// SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
|
|
||||||
// // via
|
|
||||||
// ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
|
||||||
// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(),
|
|
||||||
// parentPlatform.getTransport(), null);
|
|
||||||
// viaHeader.setRPort();
|
|
||||||
// viaHeaders.add(viaHeader);
|
|
||||||
// // from
|
|
||||||
// SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(),
|
|
||||||
// sipConfig.getSipIp() + ":" + sipConfig.getSipPort());
|
|
||||||
// Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
|
||||||
// FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
|
||||||
// // to
|
|
||||||
// SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
|
|
||||||
// Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
|
||||||
// ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
|
||||||
// // callid
|
|
||||||
// CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
|
||||||
// : udpSipProvider.getNewCallId();
|
|
||||||
// // Forwards
|
|
||||||
// MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
|
||||||
// // ceq
|
|
||||||
// CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.MESSAGE);
|
|
||||||
//
|
|
||||||
// request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
|
|
||||||
// toHeader, viaHeaders, maxForwards);
|
|
||||||
// ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
|
||||||
// request.setContent(content, contentTypeHeader);
|
|
||||||
// return request;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
|||||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||||
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;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
|
||||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
|
||||||
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
@ -16,6 +19,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import javax.sip.*;
|
import javax.sip.*;
|
||||||
import javax.sip.header.CallIdHeader;
|
import javax.sip.header.CallIdHeader;
|
||||||
|
import javax.sip.header.WWWAuthenticateHeader;
|
||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -38,6 +42,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IVideoManagerStorager storager;
|
private IVideoManagerStorager storager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IRedisCatchStorage redisCatchStorage;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SipSubscribe sipSubscribe;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier(value="tcpSipProvider")
|
@Qualifier(value="tcpSipProvider")
|
||||||
private SipProvider tcpSipProvider;
|
private SipProvider tcpSipProvider;
|
||||||
@ -55,16 +65,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable String realm, @Nullable String nonce, @Nullable String scheme ) {
|
public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||||
try {
|
parentPlatform.setExpires("0");
|
||||||
Request request = null;
|
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
|
||||||
if (realm == null || nonce == null) {
|
if (parentPlatformCatch != null) {
|
||||||
request = headerProvider.createRegisterRequest(parentPlatform, 1L, null, null);
|
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||||
}else {
|
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||||
request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transmitRequest(parentPlatform, request);
|
return register(parentPlatform, null, null, errorEvent, okEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||||
|
try {
|
||||||
|
Request request = null;
|
||||||
|
|
||||||
|
if (www == null ) {
|
||||||
|
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null);
|
||||||
|
}else {
|
||||||
|
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www);
|
||||||
|
}
|
||||||
|
|
||||||
|
transmitRequest(parentPlatform, request, errorEvent, okEvent);
|
||||||
return true;
|
return true;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -108,10 +131,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException {
|
private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException {
|
||||||
|
transmitRequest(parentPlatform, request, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent) throws SipException {
|
||||||
|
transmitRequest(parentPlatform, request, errorEvent, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException {
|
||||||
if("TCP".equals(parentPlatform.getTransport())) {
|
if("TCP".equals(parentPlatform.getTransport())) {
|
||||||
tcpSipProvider.sendRequest(request);
|
tcpSipProvider.sendRequest(request);
|
||||||
} else if("UDP".equals(parentPlatform.getTransport())) {
|
} else if("UDP".equals(parentPlatform.getTransport())) {
|
||||||
udpSipProvider.sendRequest(request);
|
udpSipProvider.sendRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
|
||||||
|
// 添加错误订阅
|
||||||
|
if (errorEvent != null) {
|
||||||
|
sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent);
|
||||||
|
}
|
||||||
|
// 添加订阅
|
||||||
|
if (okEvent != null) {
|
||||||
|
sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ import javax.sip.ResponseEvent;
|
|||||||
import javax.sip.address.Address;
|
import javax.sip.address.Address;
|
||||||
import javax.sip.address.URI;
|
import javax.sip.address.URI;
|
||||||
import javax.sip.header.CallIdHeader;
|
import javax.sip.header.CallIdHeader;
|
||||||
|
import javax.sip.header.ExpiresHeader;
|
||||||
import javax.sip.header.ToHeader;
|
import javax.sip.header.ToHeader;
|
||||||
import javax.sip.header.WWWAuthenticateHeader;
|
import javax.sip.header.WWWAuthenticateHeader;
|
||||||
import javax.sip.message.Response;
|
import javax.sip.message.Response;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:Register响应处理器
|
* @Description:Register响应处理器
|
||||||
@ -62,24 +64,28 @@ public class RegisterResponseProcessor implements ISIPResponseProcessor {
|
|||||||
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
|
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
|
||||||
SipUri uri = (SipUri)toHeader.getAddress().getURI();
|
SipUri uri = (SipUri)toHeader.getAddress().getURI();
|
||||||
String platformGBId = uri.getAuthority().getUser();
|
String platformGBId = uri.getAuthority().getUser();
|
||||||
logger.info(String.format("收到 %s 的注册%S请求", platformGBId, response.getStatusCode() ));
|
|
||||||
|
|
||||||
ParentPlatform parentPlatform = storager.queryParentPlatById(platformGBId);
|
logger.info(String.format("收到 %s 的注册/注销%S响应", platformGBId, response.getStatusCode() ));
|
||||||
|
|
||||||
|
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformGBId);
|
||||||
|
if (parentPlatformCatch == null) {
|
||||||
|
logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台缓存信息未查询到!!!", platformGBId, response.getStatusCode()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParentPlatform parentPlatform = parentPlatformCatch.getParentPlatform();
|
||||||
if (parentPlatform == null) {
|
if (parentPlatform == null) {
|
||||||
logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode()));
|
logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.getStatusCode() == 401) {
|
if (response.getStatusCode() == 401) {
|
||||||
|
|
||||||
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME);
|
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME);
|
||||||
String realm = www.getRealm();
|
|
||||||
String nonce = www.getNonce();
|
|
||||||
String scheme = www.getScheme();
|
|
||||||
|
|
||||||
CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME);
|
CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME);
|
||||||
String callId = callIdHeader.getCallId();
|
String callId = callIdHeader.getCallId();
|
||||||
sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme);
|
|
||||||
|
sipCommanderForPlatform.register(parentPlatform, callId, www, null, null);
|
||||||
}else if (response.getStatusCode() == 200){
|
}else if (response.getStatusCode() == 200){
|
||||||
// 注册成功
|
// 注册成功
|
||||||
logger.info(String.format("%s 注册成功", platformGBId ));
|
logger.info(String.format("%s 注册成功", platformGBId ));
|
||||||
@ -90,11 +96,8 @@ public class RegisterResponseProcessor implements ISIPResponseProcessor {
|
|||||||
|
|
||||||
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
|
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
|
||||||
|
|
||||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
|
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||||
if (parentPlatformCatch == null) {
|
|
||||||
parentPlatformCatch = new ParentPlatformCatch();
|
|
||||||
parentPlatformCatch.setId(parentPlatform.getDeviceGBId());
|
|
||||||
}
|
|
||||||
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,14 @@ public interface IRedisCatchStorage {
|
|||||||
|
|
||||||
ParentPlatformCatch queryPlatformCatchInfo(String platformGbId);
|
ParentPlatformCatch queryPlatformCatchInfo(String platformGbId);
|
||||||
|
|
||||||
|
void delPlatformCatchInfo(String platformGbId);
|
||||||
|
|
||||||
void updatePlatformKeepalive(ParentPlatform parentPlatform);
|
void updatePlatformKeepalive(ParentPlatform parentPlatform);
|
||||||
|
|
||||||
|
void delPlatformKeepalive(String platformGbId);
|
||||||
|
|
||||||
void updatePlatformRegister(ParentPlatform parentPlatform);
|
void updatePlatformRegister(ParentPlatform parentPlatform);
|
||||||
|
|
||||||
|
void delPlatformRegister(String platformGbId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -189,4 +189,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
|||||||
public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
|
public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
|
||||||
return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
|
return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delPlatformCatchInfo(String platformGbId) {
|
||||||
|
redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delPlatformKeepalive(String platformGbId) {
|
||||||
|
redis.del(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + platformGbId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delPlatformRegister(String platformGbId) {
|
||||||
|
redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import java.util.*;
|
|||||||
|
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||||
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
||||||
import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
|
import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
|
||||||
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
|
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
|
||||||
@ -31,6 +33,10 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ParentPlatformMapper platformMapper;
|
private ParentPlatformMapper platformMapper;
|
||||||
|
@Autowired
|
||||||
|
private IRedisCatchStorage redisCatchStorage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,11 +216,21 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateParentPlatform(ParentPlatform parentPlatform) {
|
public boolean updateParentPlatform(ParentPlatform parentPlatform) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
|
||||||
if ( platformMapper.getParentPlatById(parentPlatform.getDeviceGBId()) == null) {
|
if ( platformMapper.getParentPlatById(parentPlatform.getDeviceGBId()) == null) {
|
||||||
result = platformMapper.addParentPlatform(parentPlatform);
|
result = platformMapper.addParentPlatform(parentPlatform);
|
||||||
|
|
||||||
|
if (parentPlatformCatch == null) {
|
||||||
|
parentPlatformCatch = new ParentPlatformCatch();
|
||||||
|
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||||
|
parentPlatformCatch.setId(parentPlatform.getDeviceGBId());
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
result = platformMapper.updateParentPlatform(parentPlatform);
|
result = platformMapper.updateParentPlatform(parentPlatform);
|
||||||
}
|
}
|
||||||
|
// 更新缓存
|
||||||
|
parentPlatformCatch.setParentPlatform(parentPlatform);
|
||||||
|
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
|
||||||
return result > 0;
|
return result > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.platform;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||||
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -24,6 +25,8 @@ public class PlatformController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IVideoManagerStorager storager;
|
private IVideoManagerStorager storager;
|
||||||
|
@Autowired
|
||||||
|
private IRedisCatchStorage redisCatchStorage;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISIPCommanderForPlatform commanderForPlatform;
|
private ISIPCommanderForPlatform commanderForPlatform;
|
||||||
@ -75,7 +78,7 @@ public class PlatformController {
|
|||||||
boolean updateResult = storager.updateParentPlatform(parentPlatform);
|
boolean updateResult = storager.updateParentPlatform(parentPlatform);
|
||||||
|
|
||||||
if (updateResult) {
|
if (updateResult) {
|
||||||
commanderForPlatform.register(parentPlatform, null, null, null, null);
|
commanderForPlatform.register(parentPlatform);
|
||||||
|
|
||||||
return new ResponseEntity<>("success", HttpStatus.OK);
|
return new ResponseEntity<>("success", HttpStatus.OK);
|
||||||
}else {
|
}else {
|
||||||
@ -94,7 +97,23 @@ public class PlatformController {
|
|||||||
){
|
){
|
||||||
return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送离线消息,
|
||||||
|
commanderForPlatform.unregister(parentPlatform, (event -> {
|
||||||
|
// 清空redis缓存
|
||||||
|
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
|
||||||
|
redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
|
||||||
|
redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
|
||||||
|
}), (event -> {
|
||||||
|
// 清空redis缓存
|
||||||
|
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
|
||||||
|
redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
|
||||||
|
redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
|
||||||
|
}));
|
||||||
|
|
||||||
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
|
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
|
||||||
|
|
||||||
|
|
||||||
if (deleteResult) {
|
if (deleteResult) {
|
||||||
return new ResponseEntity<>("success", HttpStatus.OK);
|
return new ResponseEntity<>("success", HttpStatus.OK);
|
||||||
}else {
|
}else {
|
||||||
|
Loading…
Reference in New Issue
Block a user