|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean catalogQuery(DeviceChannel channel, ParentPlatform parentPlatform, String sn, String fromTag, int size) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (channel == null  || parentPlatform ==null) { | 
|---|
|  |  |  | if ( parentPlatform ==null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 
|---|
|  |  |  | catalogXml.append("<SumNum>" + size + "</SumNum>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<DeviceList Num=\"1\">\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Item>\r\n"); | 
|---|
|  |  |  | if (channel != null) { | 
|---|
|  |  |  | catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");// TODO 当前不能添加分组, 所以暂时没有父节点 | 
|---|
|  |  |  | catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); // TODO 当前不能添加分组, 所以暂时没有父节点 | 
|---|
|  |  |  | catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Info></Info>\r\n"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");// TODO 当前不能添加分组, 所以暂时没有父节点 | 
|---|
|  |  |  | catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); // TODO 当前不能添加分组, 所以暂时没有父节点 | 
|---|
|  |  |  | catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n"); | 
|---|
|  |  |  | catalogXml.append("<Info></Info>\r\n"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | catalogXml.append("</Item>\r\n"); | 
|---|
|  |  |  | catalogXml.append("</DeviceList>\r\n"); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceInfoXml.append("<CmdType>DeviceInfo</CmdType>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<SN>" +sn + "</SN>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<DeviceName>GB28181 Video Platform</DeviceName>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Manufacturer>Manufacturer</Manufacturer>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Model>wvp-28181</Model>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<DeviceName>WVP-GB28181</DeviceName>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Manufacturer>WVP</Manufacturer>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Model>wvp-28181-2.0</Model>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Firmware>2.0.202103</Firmware>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("<Result>OK</Result>\r\n"); | 
|---|
|  |  |  | deviceInfoXml.append("</Response>\r\n"); | 
|---|