src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
@@ -2,6 +2,7 @@ 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.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 @@ zlmrtpServerFactory.stopSendRtpStream(param); } sipCommanderFroPlatform.register(parentPlatform); Timer timer = new Timer(); SipSubscribe.Event okEvent = (responseEvent)->{ 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);//十五秒后再次发起注册 } } src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
@@ -13,7 +13,7 @@ * @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); /** src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
@@ -7,6 +7,8 @@ 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,11 +22,15 @@ 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 @@ 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 @@ // 将 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(); src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -119,7 +119,7 @@ // 保存时启用就发送注册 if (parentPlatform.isEnable()) { // 只要保存就发送注册 commanderForPlatform.register(parentPlatform); commanderForPlatform.register(parentPlatform, null, null); } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 commanderForPlatform.unregister(parentPlatform, null, null); }