添加级联平台自动注册时失败自动重新注册
This commit is contained in:
parent
3546ef7df3
commit
2046b40acc
@ -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<Platf
|
||||
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);//十五秒后再次发起注册
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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 (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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user