|  |  | 
 |  |  | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; | 
 |  |  |  | 
 |  |  | //import com.genersoft.iot.vmp.conf.SipConfig; | 
 |  |  | //import com.genersoft.iot.vmp.gb28181.bean.Device; | 
 |  |  | 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.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.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; | 
 |  |  | // import org.springframework.context.annotation.ComponentScan; | 
 |  |  | import org.springframework.context.annotation.DependsOn; | 
 |  |  | import org.springframework.context.annotation.Lazy; | 
 |  |  | import org.springframework.lang.Nullable; | 
 |  |  | 
 |  |  | @Component | 
 |  |  | @DependsOn("sipLayer") | 
 |  |  | public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | 
 |  |  |  | 
 |  |  |     private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class); | 
 |  |  |  | 
 |  |  |     // @Autowired | 
 |  |  |     // private SipConfig sipConfig; | 
 |  |  | 
 |  |  |     @Qualifier(value="udpSipProvider") | 
 |  |  |     private SipProvider udpSipProvider; | 
 |  |  |  | 
 |  |  |     @Value("${media.rtp.enable}") | 
 |  |  |     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 | 
 |  |  | 
 |  |  |     public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) { | 
 |  |  |         try { | 
 |  |  |             Request request = null; | 
 |  |  |  | 
 |  |  |             String tm = Long.toString(System.currentTimeMillis()); | 
 |  |  |             if (www == null ) { | 
 |  |  |                 //      //callid | 
 |  |  |                 CallIdHeader callIdHeader = null; | 
 |  |  | 
 |  |  |                 if(parentPlatform.getTransport().equals("UDP")) { | 
 |  |  |                     callIdHeader = udpSipProvider.getNewCallId(); | 
 |  |  |                 } | 
 |  |  |                 request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null, callIdHeader); | 
 |  |  |  | 
 |  |  |                 request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, "FromRegister" + tm, null, callIdHeader); | 
 |  |  |                 // 将 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(); | 
 |  |  |  | 
 |  |  |                 request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www, callIdHeader); | 
 |  |  |                 request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, "FromRegister" + tm, null, callId, www, callIdHeader); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             transmitRequest(parentPlatform, request, null, okEvent); |