| | |
| | | // 注册未回复次数 |
| | | private int registerAliveReply; |
| | | |
| | | private ParentPlatform parentPlatform; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | |
| | | public void setRegisterAliveReply(int registerAliveReply) { |
| | | this.registerAliveReply = registerAliveReply; |
| | | } |
| | | |
| | | public ParentPlatform getParentPlatform() { |
| | | return parentPlatform; |
| | | } |
| | | |
| | | public void setParentPlatform(ParentPlatform parentPlatform) { |
| | | this.parentPlatform = parentPlatform; |
| | | } |
| | | } |
| | |
| | | } |
| | | ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID()); |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID()); |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | if (parentPlatform == null) { |
| | | logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); |
| | | return; |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.cmd; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| | | |
| | | import javax.sip.header.WWWAuthenticateHeader; |
| | | |
| | | public interface ISIPCommanderForPlatform { |
| | | |
| | |
| | | */ |
| | | 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); |
| | | |
| | | /** |
| | | * 向上级平发送心跳信息 |
| | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @Description:摄像头命令request创造器 TODO 冗余代码太多待优化 |
| | | * @author: swwheihei |
| | | * @Description: 平台命令request创造器 TODO 冗余代码太多待优化 |
| | | * @author: panll |
| | | * @date: 2020年5月6日 上午9:29:02 |
| | | */ |
| | | @Component |
| | |
| | | } |
| | | |
| | | |
| | | 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; |
| | | String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort(); |
| | | //请求行 |
| | |
| | | MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70); |
| | | |
| | | //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, |
| | | cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); |
| | | |
| | |
| | | .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, fromTag, viaTag); |
| | | String callId, WWWAuthenticateHeader www ) throws ParseException, PeerUnavailableException, InvalidArgumentException { |
| | | 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.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 HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes()); |
| | | String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes()); |
| | | String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + requestURI.toString()).getBytes()); |
| | | |
| | | String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\"" |
| | | + realm + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\", nonce=\"" |
| | | + nonce + "\""; |
| | | AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent); |
| | | StringBuffer reStr = new StringBuffer(200); |
| | | reStr.append(HA1); |
| | | reStr.append(":"); |
| | | 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); |
| | | |
| | | return registerRequest; |
| | |
| | |
|
| | | import java.text.ParseException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.PeerUnavailableException;
|
| | |
| | | request.setContent(content, contentTypeHeader);
|
| | | 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;
|
| | | // }
|
| | | }
|
| | |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | 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.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | |
| | | |
| | | import javax.sip.*; |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.header.WWWAuthenticateHeader; |
| | | import javax.sip.message.Request; |
| | | import java.text.ParseException; |
| | | import java.util.UUID; |
| | |
| | | private IVideoManagerStorager storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private SipSubscribe sipSubscribe; |
| | | |
| | | @Autowired |
| | | @Qualifier(value="tcpSipProvider") |
| | | private SipProvider tcpSipProvider; |
| | | |
| | |
| | | } |
| | | |
| | | @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) { |
| | | parentPlatform.setExpires("0"); |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId()); |
| | | if (parentPlatformCatch != null) { |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | } |
| | | |
| | | 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 (realm == null || nonce == null) { |
| | | request = headerProvider.createRegisterRequest(parentPlatform, 1L, null, null); |
| | | |
| | | if (www == null ) { |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null); |
| | | }else { |
| | | request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme); |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www); |
| | | } |
| | | |
| | | transmitRequest(parentPlatform, request); |
| | | transmitRequest(parentPlatform, request, errorEvent, okEvent); |
| | | return true; |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | |
| | | 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())) { |
| | | tcpSipProvider.sendRequest(request); |
| | | } else if("UDP".equals(parentPlatform.getTransport())) { |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | import javax.sip.address.Address; |
| | | import javax.sip.address.URI; |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.header.ExpiresHeader; |
| | | import javax.sip.header.ToHeader; |
| | | import javax.sip.header.WWWAuthenticateHeader; |
| | | import javax.sip.message.Response; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @Description:Register响应处理器 |
| | |
| | | ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); |
| | | SipUri uri = (SipUri)toHeader.getAddress().getURI(); |
| | | 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) { |
| | | logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode())); |
| | | logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode())); |
| | | return; |
| | | } |
| | | |
| | | if (response.getStatusCode() == 401) { |
| | | |
| | | 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); |
| | | String callId = callIdHeader.getCallId(); |
| | | sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme); |
| | | |
| | | sipCommanderForPlatform.register(parentPlatform, callId, www, null, null); |
| | | }else if (response.getStatusCode() == 200){ |
| | | // 注册成功 |
| | | logger.info(String.format("%s 注册成功", platformGBId )); |
| | |
| | | |
| | | redisCatchStorage.updatePlatformKeepalive(parentPlatform); |
| | | |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId()); |
| | | if (parentPlatformCatch == null) { |
| | | parentPlatformCatch = new ParentPlatformCatch(); |
| | | parentPlatformCatch.setId(parentPlatform.getDeviceGBId()); |
| | | } |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | } |
| | | } |
| | |
| | | |
| | | ParentPlatformCatch queryPlatformCatchInfo(String platformGbId); |
| | | |
| | | void delPlatformCatchInfo(String platformGbId); |
| | | |
| | | void updatePlatformKeepalive(ParentPlatform parentPlatform); |
| | | |
| | | void delPlatformKeepalive(String platformGbId); |
| | | |
| | | void updatePlatformRegister(ParentPlatform parentPlatform); |
| | | |
| | | void delPlatformRegister(String platformGbId); |
| | | |
| | | } |
| | |
| | | public ParentPlatformCatch queryPlatformCatchInfo(String 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); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | 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.DeviceMapper; |
| | | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; |
| | |
| | | |
| | | @Autowired |
| | | private ParentPlatformMapper platformMapper; |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean updateParentPlatform(ParentPlatform parentPlatform) { |
| | | int result = 0; |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId()); |
| | | if ( platformMapper.getParentPlatById(parentPlatform.getDeviceGBId()) == null) { |
| | | result = platformMapper.addParentPlatform(parentPlatform); |
| | | |
| | | if (parentPlatformCatch == null) { |
| | | parentPlatformCatch = new ParentPlatformCatch(); |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | parentPlatformCatch.setId(parentPlatform.getDeviceGBId()); |
| | | } |
| | | }else { |
| | | result = platformMapper.updateParentPlatform(parentPlatform); |
| | | } |
| | | // 更新缓存 |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | return result > 0; |
| | | } |
| | | |
| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | 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.github.pagehelper.PageInfo; |
| | | import org.slf4j.Logger; |
| | |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorager storager; |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private ISIPCommanderForPlatform commanderForPlatform; |
| | |
| | | boolean updateResult = storager.updateParentPlatform(parentPlatform); |
| | | |
| | | if (updateResult) { |
| | | commanderForPlatform.register(parentPlatform, null, null, null, null); |
| | | commanderForPlatform.register(parentPlatform); |
| | | |
| | | return new ResponseEntity<>("success", HttpStatus.OK); |
| | | }else { |
| | |
| | | ){ |
| | | 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); |
| | | |
| | | |
| | | if (deleteResult) { |
| | | return new ResponseEntity<>("success", HttpStatus.OK); |
| | | }else { |