| | |
| | | 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.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.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.gb28181.transmit.cmd.SIPRequestHeaderProvider; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | //import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.header.WWWAuthenticateHeader; |
| | | import javax.sip.message.Request; |
| | | import java.nio.channels.Channel; |
| | | import java.text.ParseException; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Component |
| | | public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| | | |
| | | @Autowired |
| | | private SipConfig sipConfig; |
| | | // @Autowired |
| | | // private SipConfig sipConfig; |
| | | |
| | | @Autowired |
| | | private SIPRequestHeaderProvider headerProvider; |
| | | // @Autowired |
| | | // private SIPRequestHeaderProvider headerProvider; |
| | | |
| | | @Autowired |
| | | private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider; |
| | | |
| | | @Autowired |
| | | private VideoStreamSessionManager streamSession; |
| | | // @Autowired |
| | | // private VideoStreamSessionManager streamSession; |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorager storager; |
| | | // @Autowired |
| | | // private IVideoManagerStorager storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | |
| | | @Override |
| | | public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) { |
| | | parentPlatform.setExpires("0"); |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId()); |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); |
| | | if (parentPlatformCatch != null) { |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | |
| | | |
| | | if (www == null ) { |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null); |
| | | // 将 callid 写入缓存, 等注册成功可以更新状态 |
| | | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
| | | redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId()); |
| | | |
| | | sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{ |
| | | redisCatchStorage.delPlatformRegisterInfo(callIdHeader.getCallId()); |
| | | if (errorEvent != null) { |
| | | errorEvent.response(event); |
| | | } |
| | | }); |
| | | }else { |
| | | request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www); |
| | | } |
| | | |
| | | transmitRequest(parentPlatform, request, errorEvent, okEvent); |
| | | transmitRequest(parentPlatform, request, null, okEvent); |
| | | return true; |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | |
| | | try { |
| | | |
| | | StringBuffer keepaliveXml = new StringBuffer(200); |
| | | keepaliveXml.append("<?xml version=\"1.0\" encoding=\"GB2312\" ?>\r\n"); |
| | | keepaliveXml.append("<?xml version=\"1.0\"?>\r\n"); |
| | | keepaliveXml.append("<Notify>\r\n"); |
| | | keepaliveXml.append("<CmdType>Keepalive</CmdType>\r\n"); |
| | | keepaliveXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); |
| | | keepaliveXml.append("<DeviceID>" + parentPlatform.getServerGBId() + "</DeviceID>\r\n"); |
| | | keepaliveXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n"); |
| | | keepaliveXml.append("<Status>OK</Status>\r\n"); |
| | | keepaliveXml.append("</Notify>\r\n"); |
| | | |
| | | Request request = headerProviderPlarformProvider.createKeetpaliveMessageRequest( |
| | | parentPlatform, |
| | | keepaliveXml.toString(), |
| | | UUID.randomUUID().toString().replace("-", ""), |
| | | "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), |
| | | UUID.randomUUID().toString().replace("-", ""), |
| | | null); |
| | | transmitRequest(parentPlatform, request); |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 向上级回复DeviceInfo查询信息 |
| | | * @param parentPlatform 平台信息 |
| | | * @param sn |
| | | * @param fromTag |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deviceInfoResponse(ParentPlatform parentPlatform, String sn, String fromTag) { |
| | | if (parentPlatform == null) { |
| | | return false; |
| | | } |
| | | try { |
| | | StringBuffer deviceInfoXml = new StringBuffer(600); |
| | | deviceInfoXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); |
| | | deviceInfoXml.append("<Response>\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("<Firmware>2.0.202103</Firmware>\r\n"); |
| | | deviceInfoXml.append("<Result>OK</Result>\r\n"); |
| | | deviceInfoXml.append("</Response>\r\n"); |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 向上级回复DeviceStatus查询信息 |
| | | * @param parentPlatform 平台信息 |
| | | * @param sn |
| | | * @param fromTag |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deviceStatusResponse(ParentPlatform parentPlatform, String sn, String fromTag) { |
| | | if (parentPlatform == null) { |
| | | return false; |
| | | } |
| | | try { |
| | | StringBuffer deviceStatusXml = new StringBuffer(600); |
| | | deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); |
| | | deviceStatusXml.append("<Response>\r\n"); |
| | | deviceStatusXml.append("<CmdType>DeviceStatus</CmdType>\r\n"); |
| | | deviceStatusXml.append("<SN>" +sn + "</SN>\r\n"); |
| | | deviceStatusXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n"); |
| | | deviceStatusXml.append("<Result>OK</Result>\r\n"); |
| | | deviceStatusXml.append("<Online>ONLINE</Online>\r\n"); |
| | | deviceStatusXml.append("<Status>OK</Status>\r\n"); |
| | | deviceStatusXml.append("</Response>\r\n"); |
| | | Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag); |
| | | transmitRequest(parentPlatform, request); |
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | } |