Merge branch 'wvp-28181-2.0' into wvp-pro-record
# Conflicts: # src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java # web_src/src/components/control.vue
This commit is contained in:
@@ -18,13 +18,16 @@ public class SubscribeInfo {
|
||||
this.fromTag = fromHeader.getTag();
|
||||
ExpiresHeader expiresHeader = (ExpiresHeader)request.getHeader(ExpiresHeader.NAME);
|
||||
this.expires = expiresHeader.getExpires();
|
||||
this.event = ((EventHeader)request.getHeader(EventHeader.NAME)).getName();
|
||||
EventHeader eventHeader = (EventHeader)request.getHeader(EventHeader.NAME);
|
||||
this.eventId = eventHeader.getEventId();
|
||||
this.eventType = eventHeader.getEventType();
|
||||
}
|
||||
|
||||
private String id;
|
||||
private int expires;
|
||||
private String callId;
|
||||
private String event;
|
||||
private String eventId;
|
||||
private String eventType;
|
||||
private String fromTag;
|
||||
private String toTag;
|
||||
|
||||
@@ -68,11 +71,19 @@ public class SubscribeInfo {
|
||||
this.fromTag = fromTag;
|
||||
}
|
||||
|
||||
public String getEvent() {
|
||||
return event;
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
public void setEvent(String event) {
|
||||
this.event = event;
|
||||
public void setEventId(String eventId) {
|
||||
this.eventId = eventId;
|
||||
}
|
||||
|
||||
public String getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public void setEventType(String eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,14 +99,14 @@ public class EventPublisher {
|
||||
applicationEventPublisher.publishEvent(outEvent);
|
||||
}
|
||||
|
||||
@Async
|
||||
|
||||
public void catalogEventPublish(String platformId, DeviceChannel deviceChannel, String type) {
|
||||
List<DeviceChannel> deviceChannelList = new ArrayList<>();
|
||||
deviceChannelList.add(deviceChannel);
|
||||
catalogEventPublish(platformId, deviceChannelList, type);
|
||||
}
|
||||
|
||||
@Async
|
||||
|
||||
public void catalogEventPublish(String platformId, List<DeviceChannel> deviceChannels, String type) {
|
||||
CatalogEvent outEvent = new CatalogEvent(this);
|
||||
List<DeviceChannel> channels = new ArrayList<>();
|
||||
@@ -128,8 +128,8 @@ public class EventPublisher {
|
||||
applicationEventPublisher.publishEvent(outEvent);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void catalogEventPublishForStream(String platformId, GbStream[] gbStreams, String type) {
|
||||
|
||||
public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) {
|
||||
CatalogEvent outEvent = new CatalogEvent(this);
|
||||
outEvent.setGbStreams(gbStreams);
|
||||
outEvent.setType(type);
|
||||
@@ -137,10 +137,11 @@ public class EventPublisher {
|
||||
applicationEventPublisher.publishEvent(outEvent);
|
||||
}
|
||||
|
||||
@Async
|
||||
|
||||
public void catalogEventPublishForStream(String platformId, GbStream gbStream, String type) {
|
||||
GbStream[] gbStreams = {gbStream};
|
||||
catalogEventPublishForStream(platformId, gbStreams, type);
|
||||
List<GbStream> gbStreamList = new ArrayList<>();
|
||||
gbStreamList.add(gbStream);
|
||||
catalogEventPublishForStream(platformId, gbStreamList, type);
|
||||
}
|
||||
|
||||
public void recordEndEventPush(RecordInfo recordInfo) {
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CatalogEvent extends ApplicationEvent {
|
||||
public static final String UPDATE = "UPDATE"; // 更新
|
||||
|
||||
private List<DeviceChannel> deviceChannels;
|
||||
private GbStream[] gbStreams;
|
||||
private List<GbStream> gbStreams;
|
||||
private String type;
|
||||
private String platformId;
|
||||
|
||||
@@ -48,11 +48,11 @@ public class CatalogEvent extends ApplicationEvent {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
public GbStream[] getGbStreams() {
|
||||
public List<GbStream> getGbStreams() {
|
||||
return gbStreams;
|
||||
}
|
||||
|
||||
public void setGbStreams(GbStream[] gbStreams) {
|
||||
public void setGbStreams(List<GbStream> gbStreams) {
|
||||
this.gbStreams = gbStreams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,11 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
if (parentPlatform != null && !parentPlatform.isStatus())return;
|
||||
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_" + event.getPlatformId();
|
||||
subscribe = redisCatchStorage.getSubscribe(key);
|
||||
if (subscribe == null) return;
|
||||
|
||||
if (subscribe == null) {
|
||||
logger.debug("发送订阅消息时发现订阅信息已经不存在");
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
// 获取所用订阅
|
||||
List<String> platforms = redisCatchStorage.getAllSubscribePlatform();
|
||||
@@ -94,7 +98,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
if (event.getDeviceChannels() != null) {
|
||||
deviceChannelList.addAll(event.getDeviceChannels());
|
||||
}
|
||||
if (event.getGbStreams() != null && event.getGbStreams().length > 0){
|
||||
if (event.getGbStreams() != null && event.getGbStreams().size() > 0){
|
||||
for (GbStream gbStream : event.getGbStreams()) {
|
||||
DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId());
|
||||
deviceChannelList.add(deviceChannelByStream);
|
||||
@@ -134,7 +138,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
if (event.getDeviceChannels() != null) {
|
||||
deviceChannelList.addAll(event.getDeviceChannels());
|
||||
}
|
||||
if (event.getGbStreams() != null && event.getGbStreams().length > 0){
|
||||
if (event.getGbStreams() != null && event.getGbStreams().size() > 0){
|
||||
for (GbStream gbStream : event.getGbStreams()) {
|
||||
DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId());
|
||||
deviceChannelList.add(deviceChannelByStream);
|
||||
@@ -142,7 +146,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
}
|
||||
if (deviceChannelList.size() > 0) {
|
||||
logger.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size());
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe, null);
|
||||
}
|
||||
}else if (parentPlatformMap.keySet().size() > 0) {
|
||||
for (String gbId : parentPlatformMap.keySet()) {
|
||||
|
||||
@@ -73,6 +73,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
@Override
|
||||
@Async
|
||||
public void processRequest(RequestEvent requestEvent) {
|
||||
logger.debug("\n收到请求:\n{}", requestEvent.getRequest());
|
||||
String method = requestEvent.getRequest().getMethod();
|
||||
ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);
|
||||
if (sipRequestProcessor == null) {
|
||||
@@ -90,9 +91,8 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
@Override
|
||||
@Async
|
||||
public void processResponse(ResponseEvent responseEvent) {
|
||||
logger.debug(responseEvent.getResponse().toString());
|
||||
Response response = responseEvent.getResponse();
|
||||
logger.debug(responseEvent.getResponse().toString());
|
||||
logger.debug("\n收到响应:\n{}", responseEvent.getResponse());
|
||||
int status = response.getStatusCode();
|
||||
if (((status >= 200) && (status < 300)) || status == 401) { // Success!
|
||||
CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);
|
||||
@@ -107,8 +107,8 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());
|
||||
if (subscribe != null) {
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent);
|
||||
subscribe.response(eventResult);
|
||||
sipSubscribe.removeOkSubscribe(callIdHeader.getCallId());
|
||||
subscribe.response(eventResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface ISIPCommanderForPlatform {
|
||||
* @param parentPlatform
|
||||
* @param deviceChannels
|
||||
*/
|
||||
boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo);
|
||||
boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index);
|
||||
|
||||
/**
|
||||
* 回复catalog事件-删除
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import gov.nist.javax.sip.message.MessageFactoryImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -223,30 +224,31 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
request.addHeader(userAgentHeader);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createNotifyRequest(ParentPlatform parentPlatform, String content, String fromTag, String toTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
public Request createNotifyRequest(ParentPlatform parentPlatform, String content, CallIdHeader callIdHeader, String viaTag, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()),
|
||||
parentPlatform.getTransport(), null);
|
||||
parentPlatform.getTransport(), viaTag);
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
|
||||
parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, "fromtag" + tm);
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getToTag());
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
@@ -262,7 +264,19 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
|
||||
request.addHeader(userAgentHeader);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
|
||||
event.setEventId(subscribeInfo.getEventId());
|
||||
request.addHeader(event);
|
||||
|
||||
SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active");
|
||||
request.setHeader(active);
|
||||
|
||||
String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(parentPlatform.getDeviceGBId(), sipAddress));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class SIPRequestHeaderProvider {
|
||||
|
||||
request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards);
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public class SIPRequestHeaderProvider {
|
||||
EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event);
|
||||
request.addHeader(eventHeader);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
@@ -31,21 +31,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class);
|
||||
|
||||
// @Autowired
|
||||
// private SipConfig sipConfig;
|
||||
|
||||
// @Autowired
|
||||
// private SIPRequestHeaderProvider headerProvider;
|
||||
|
||||
@Autowired
|
||||
private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider;
|
||||
|
||||
// @Autowired
|
||||
// private VideoStreamSessionManager streamSession;
|
||||
|
||||
// @Autowired
|
||||
// private IVideoManagerStorager storager;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@@ -172,6 +160,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
|
||||
private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException {
|
||||
logger.debug("\n发送消息:\n{}", request);
|
||||
if("TCP".equals(parentPlatform.getTransport())) {
|
||||
tcpSipProvider.sendRequest(request);
|
||||
|
||||
@@ -222,7 +211,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
if (channel.getParentId() != null) {
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
}
|
||||
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");
|
||||
@@ -357,7 +348,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, deviceStatusXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader);
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform,
|
||||
deviceStatusXml.toString(),callIdHeader,
|
||||
"z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@@ -368,63 +361,73 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo) {
|
||||
public boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index) {
|
||||
if (parentPlatform == null || deviceChannels == null || deviceChannels.size() == 0 || subscribeInfo == null) {
|
||||
return false;
|
||||
}
|
||||
for (DeviceChannel channel : deviceChannels) {
|
||||
try {
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
catalogXml.append("<Notify>\r\n");
|
||||
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
|
||||
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
catalogXml.append("<SumNum>" + deviceChannels.size() + "</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Event>" + type + "</Event>\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");
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
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("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n");
|
||||
catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n");
|
||||
catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
|
||||
catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
|
||||
catalogXml.append("<Info>\r\n");
|
||||
catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
|
||||
catalogXml.append("</Info>\r\n");
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
if (index == null) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
callIdHeader.setCallId(subscribeInfo.getCallId());
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
Thread.sleep(10);
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
if (index == deviceChannels.size() - 1) {
|
||||
return true;
|
||||
}
|
||||
Request request = getCatalogNotifyRequest(parentPlatform, deviceChannels.get(index), deviceChannels.size(), type, subscribeInfo);
|
||||
index += 1;
|
||||
Integer finalIndex = index;
|
||||
transmitRequest(parentPlatform, request, null, (eventResult -> {
|
||||
sendNotifyForCatalogAddOrUpdate(type, parentPlatform, deviceChannels, subscribeInfo, finalIndex);
|
||||
}));
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Request getCatalogNotifyRequest(ParentPlatform parentPlatform, DeviceChannel channel, int size, String type,
|
||||
SubscribeInfo subscribeInfo) throws ParseException, InvalidArgumentException,
|
||||
PeerUnavailableException {
|
||||
String catalogXmlContent = getCatalogXmlContent(parentPlatform, channel, size, type);
|
||||
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
callIdHeader.setCallId(subscribeInfo.getCallId());
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXmlContent,
|
||||
callIdHeader, "z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo);
|
||||
return request;
|
||||
}
|
||||
|
||||
private String getCatalogXmlContent(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type) {
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
catalogXml.append("<Notify>\r\n");
|
||||
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
|
||||
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<SumNum>" + sumNum + "</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\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>0</Owner>\r\n");
|
||||
catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n");
|
||||
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
|
||||
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
|
||||
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
|
||||
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("<Event>" + type + "</Event>\r\n");
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
return catalogXml.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo) {
|
||||
if (parentPlatform == null
|
||||
@@ -441,6 +444,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
catalogXml.append("<Notify>\r\n");
|
||||
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
|
||||
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<SumNum>" + deviceChannels.size() + "</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
@@ -456,7 +460,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(), subscribeInfo.getToTag(), subscribeInfo.getFromTag(), callIdHeader);
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml.toString(),
|
||||
callIdHeader,
|
||||
"z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo);
|
||||
transmitRequest(parentPlatform, request);
|
||||
Thread.sleep(200);
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
@@ -160,13 +161,18 @@ public abstract class SIPRequestProcessorParent {
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void responseSdpAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException {
|
||||
public void responseSdpAck(RequestEvent evt, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
||||
SipFactory sipFactory = SipFactory.getInstance();
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
|
||||
response.setContent(sdp, contentTypeHeader);
|
||||
|
||||
// 兼容国标中的使用编码@域名作为RequestURI的情况
|
||||
SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
|
||||
if (sipURI.getPort() == -1) {
|
||||
sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
}
|
||||
logger.debug("responseSdpAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort());
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(
|
||||
sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
||||
@@ -183,13 +189,18 @@ public abstract class SIPRequestProcessorParent {
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public Response responseXmlAck(RequestEvent evt, String xml) throws SipException, InvalidArgumentException, ParseException {
|
||||
public Response responseXmlAck(RequestEvent evt, String xml, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
||||
SipFactory sipFactory = SipFactory.getInstance();
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
response.setContent(xml, contentTypeHeader);
|
||||
|
||||
// 兼容国标中的使用编码@域名作为RequestURI的情况
|
||||
SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
|
||||
if (sipURI.getPort() == -1) {
|
||||
sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
}
|
||||
logger.debug("responseXmlAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort());
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(
|
||||
sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
||||
|
||||
@@ -293,7 +293,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
content.append("f=\r\n");
|
||||
|
||||
try {
|
||||
responseSdpAck(evt, content.toString());
|
||||
responseSdpAck(evt, content.toString(), platform);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@@ -369,7 +369,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
content.append("f=\r\n");
|
||||
|
||||
try {
|
||||
responseSdpAck(evt, content.toString());
|
||||
responseSdpAck(evt, content.toString(), platform);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CmdType;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.task.GPSSubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
@@ -105,9 +106,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
logger.info("processRequest serverTransactionId is null.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SipException e) {
|
||||
@@ -155,7 +153,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
|
||||
|
||||
try {
|
||||
Response response = responseXmlAck(evt, resultXml.toString());
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
||||
Response response = responseXmlAck(evt, resultXml.toString(), parentPlatform);
|
||||
ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME);
|
||||
subscribeInfo.setToTag(toHeader.getTag());
|
||||
redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
||||
@@ -196,7 +195,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
}
|
||||
|
||||
try {
|
||||
Response response = responseXmlAck(evt, resultXml.toString());
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
||||
Response response = responseXmlAck(evt, resultXml.toString(), parentPlatform);
|
||||
ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME);
|
||||
subscribeInfo.setToTag(toHeader.getTag());
|
||||
redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
||||
|
||||
@@ -72,6 +72,9 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
|
||||
List<PlatformCatalog> catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId());
|
||||
if (catalogs.size() > 0) {
|
||||
for (PlatformCatalog catalog : catalogs) {
|
||||
if (catalog.getParentId().equals(catalog.getPlatformId())) {
|
||||
catalog.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(catalog.getId());
|
||||
deviceChannel.setName(catalog.getName());
|
||||
@@ -83,29 +86,35 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
|
||||
deviceChannel.setParental(1);
|
||||
deviceChannel.setParentId(catalog.getParentId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(config.getDomain());
|
||||
deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2));
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setSecrecy("0");
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
// 回复级联的通道
|
||||
if (channelReduces.size() > 0) {
|
||||
for (ChannelReduce channelReduce : channelReduces) {
|
||||
if (channelReduce.getCatalogId().equals(parentPlatform.getServerGBId())) {
|
||||
channelReduce.setCatalogId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
|
||||
deviceChannel.setParental(0);
|
||||
deviceChannel.setParentId(channelReduce.getCatalogId());
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
// 回复直播的通道
|
||||
if (gbStreams.size() > 0) {
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) {
|
||||
gbStream.setCatalogId(null);
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(gbStream.getGbId());
|
||||
deviceChannel.setName(gbStream.getName());
|
||||
@@ -116,14 +125,14 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
|
||||
deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
||||
deviceChannel.setParentId(gbStream.getCatalogId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(config.getDomain());
|
||||
deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2));
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setParental(0);
|
||||
deviceChannel.setSecrecy("0");
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
if (size == 0) {
|
||||
|
||||
@@ -75,6 +75,9 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
int size = catalogs.size() + channelReduces.size() + gbStreams.size();
|
||||
if (catalogs.size() > 0) {
|
||||
for (PlatformCatalog catalog : catalogs) {
|
||||
if (catalog.getParentId().equals(parentPlatform.getServerGBId())) {
|
||||
catalog.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(catalog.getId());
|
||||
deviceChannel.setName(catalog.getName());
|
||||
@@ -86,30 +89,35 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
deviceChannel.setParental(1);
|
||||
deviceChannel.setParentId(catalog.getParentId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(config.getDomain());
|
||||
deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2));
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setSecrecy("0");
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
// 回复级联的通道
|
||||
if (channelReduces.size() > 0) {
|
||||
for (ChannelReduce channelReduce : channelReduces) {
|
||||
if (channelReduce.getCatalogId().equals(parentPlatform.getServerGBId())) {
|
||||
channelReduce.setCatalogId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
|
||||
// TODO 目前暂时认为这里只用通道没有目录
|
||||
deviceChannel.setParental(0);
|
||||
deviceChannel.setParentId(channelReduce.getCatalogId());
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
// 回复直播的通道
|
||||
if (gbStreams.size() > 0) {
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) {
|
||||
gbStream.setCatalogId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(gbStream.getGbId());
|
||||
deviceChannel.setName(gbStream.getName());
|
||||
@@ -120,7 +128,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
||||
deviceChannel.setParentId(gbStream.getCatalogId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(config.getDomain());
|
||||
deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2));
|
||||
deviceChannel.setModel("live");
|
||||
deviceChannel.setOwner("wvp-pro");
|
||||
deviceChannel.setParental(0);
|
||||
@@ -128,7 +136,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
|
||||
cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
|
||||
// 防止发送过快
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
if (size == 0) {
|
||||
|
||||
Reference in New Issue
Block a user