From bf8fb0c51f4e7894a62636dede6c69a2a85d8458 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Tue, 27 Apr 2021 15:35:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BA=A7=E8=81=94=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C=E6=97=B6=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E8=87=AA=E5=8A=A8=E9=87=8D=E6=96=B0=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlatformNotRegisterEventLister.java | 21 +++++++++++++++---- .../cmd/ISIPCommanderForPlatform.java | 2 +- .../cmd/impl/SIPCommanderFroPlatform.java | 20 +++++++++++++----- .../gb28181/platform/PlatformController.java | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java index a53583b6..7e59910c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; @@ -12,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @Description: 平台未注册事件,来源有二: @@ -77,6 +76,20 @@ public class PlatformNotRegisterEventLister implements ApplicationListener{ + timer.cancel(); + }; + logger.info("向平台注册,平台国标ID:" + event.getPlatformGbID()); + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); + // 设置注册失败则每隔15秒发起一次注册 + timer.schedule(new TimerTask() { + @Override + public void run() { + logger.info("再次向平台注册,平台国标ID:" + event.getPlatformGbID()); + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); + } + }, 15000, 15000);//十五秒后再次发起注册 } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java index 1751ede0..fe302938 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java @@ -13,7 +13,7 @@ public interface ISIPCommanderForPlatform { * @param parentPlatform * @return */ - boolean register(ParentPlatform parentPlatform); + boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent); boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent); /** diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 0f462da0..cb99c3cf 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -7,6 +7,8 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -20,12 +22,16 @@ import javax.sip.header.CallIdHeader; import javax.sip.header.WWWAuthenticateHeader; import javax.sip.message.Request; import java.text.ParseException; +import java.util.Timer; +import java.util.TimerTask; import java.util.UUID; @Component @DependsOn("sipLayer") public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { + private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class); + // @Autowired // private SipConfig sipConfig; @@ -61,8 +67,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { private boolean rtpEnable; @Override - public boolean register(ParentPlatform parentPlatform) { - return register(parentPlatform, null, null, null, null); + public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) { + return register(parentPlatform, null, null, errorEvent, okEvent); } @Override @@ -95,13 +101,17 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { // 将 callid 写入缓存, 等注册成功可以更新状态 redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId()); - CallIdHeader finalCallIdHeader = callIdHeader; sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{ - redisCatchStorage.delPlatformRegisterInfo(finalCallIdHeader.getCallId()); - if (errorEvent != null) { + if (event != null) { + logger.info("向上级平台 [ {} ] 注册发上错误: {} ", + parentPlatform.getServerGBId(), + event.getResponse().getReasonPhrase()); + } + if (errorEvent != null ) { errorEvent.response(event); } }); + }else { CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() : udpSipProvider.getNewCallId(); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java index c692af49..84431ddf 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java @@ -119,7 +119,7 @@ public class PlatformController { // 保存时启用就发送注册 if (parentPlatform.isEnable()) { // 只要保存就发送注册 - commanderForPlatform.register(parentPlatform); + commanderForPlatform.register(parentPlatform, null, null); } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 commanderForPlatform.unregister(parentPlatform, null, null); }