优化国标级联的目录订阅
This commit is contained in:
parent
1da1dd68e5
commit
78bad59518
@ -105,6 +105,10 @@ https://gitee.com/pan648540858/wvp-GB28181-pro.git
|
||||
- [X] WEB端支持播放H264与H265,音频支持G.711A/G.711U/AAC,覆盖国标常用编码格式。
|
||||
|
||||
# docker快速体验
|
||||
目前作者的docker-compose因为时间有限维护不及时,这里提供第三方提供的供大家使用,维护不易,大家记得给这位小伙伴点个star。
|
||||
https://github.com/SaltFish001/wvp_pro_compose
|
||||
[https://github.com/SaltFish001/wvp_pro_compose](https://github.com/SaltFish001/wvp_pro_compose)
|
||||
这是作者维护的一个镜像,可能存在不及时的问题。
|
||||
```shell
|
||||
docker pull 648540858/wvp_pro
|
||||
|
||||
|
@ -14,7 +14,7 @@ import springfox.documentation.spring.web.plugins.Docket;
|
||||
@Configuration
|
||||
public class Swagger3Config {
|
||||
|
||||
@Value("${swagger-ui.enabled}")
|
||||
@Value("${swagger-ui.enabled: true}")
|
||||
private boolean enable;
|
||||
|
||||
@Bean
|
||||
|
@ -21,6 +21,8 @@ public class SubscribeInfo {
|
||||
EventHeader eventHeader = (EventHeader)request.getHeader(EventHeader.NAME);
|
||||
this.eventId = eventHeader.getEventId();
|
||||
this.eventType = eventHeader.getEventType();
|
||||
ViaHeader viaHeader = (ViaHeader)request.getHeader(ViaHeader.NAME);
|
||||
this.branch = viaHeader.getBranch();
|
||||
}
|
||||
|
||||
private String id;
|
||||
@ -30,6 +32,7 @@ public class SubscribeInfo {
|
||||
private String eventType;
|
||||
private String fromTag;
|
||||
private String toTag;
|
||||
private String branch;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@ -86,4 +89,12 @@ public class SubscribeInfo {
|
||||
public void setEventType(String eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public String getBranch() {
|
||||
return branch;
|
||||
}
|
||||
|
||||
public void setBranch(String branch) {
|
||||
this.branch = branch;
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
}
|
||||
if (deviceChannelList.size() > 0) {
|
||||
logger.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size());
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), parentPlatform, deviceChannelList, subscribe);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), parentPlatform, deviceChannelList, subscribe, null);
|
||||
}
|
||||
}else if (parentPlatformMap.keySet().size() > 0) {
|
||||
for (String gbId : parentPlatformMap.keySet()) {
|
||||
@ -121,7 +121,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(gbId);
|
||||
deviceChannelList.add(deviceChannel);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,7 +163,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
||||
GbStream gbStream = storager.queryStreamInParentPlatform(platform.getServerGBId(), gbId);
|
||||
DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), platform.getDeviceGBId());
|
||||
deviceChannelList.add(deviceChannelByStream);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo);
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,6 @@ public interface ISIPCommanderForPlatform {
|
||||
* @param parentPlatform
|
||||
* @param deviceChannels
|
||||
*/
|
||||
boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo);
|
||||
boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index);
|
||||
|
||||
}
|
||||
|
@ -236,19 +236,18 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()),
|
||||
parentPlatform.getTransport(), viaTag);
|
||||
parentPlatform.getTransport(), subscribeInfo.getBranch());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
|
||||
parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, "fromtag" + tm);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, subscribeInfo.getToTag());
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getToTag());
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getFromTag());
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
@ -265,7 +264,10 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
request.addHeader(userAgentHeader);
|
||||
|
||||
EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
|
||||
event.setEventId(subscribeInfo.getEventId());
|
||||
if (subscribeInfo.getEventId() != null) {
|
||||
event.setEventId(subscribeInfo.getEventId());
|
||||
}
|
||||
|
||||
request.addHeader(event);
|
||||
|
||||
SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active");
|
||||
|
@ -371,10 +371,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
|
||||
try {
|
||||
if (index == deviceChannels.size() - 1) {
|
||||
if (index > deviceChannels.size() - 1) {
|
||||
return true;
|
||||
}
|
||||
Request request = getCatalogNotifyRequest(parentPlatform, deviceChannels.get(index), deviceChannels.size(), type, subscribeInfo);
|
||||
Request request = getCatalogNotifyRequestForCatalogAddOrUpdate(parentPlatform, deviceChannels.get(index), deviceChannels.size(), type, subscribeInfo);
|
||||
index += 1;
|
||||
Integer finalIndex = index;
|
||||
transmitRequest(parentPlatform, request, null, (eventResult -> {
|
||||
@ -387,10 +387,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Request getCatalogNotifyRequest(ParentPlatform parentPlatform, DeviceChannel channel, int size, String type,
|
||||
private Request getCatalogNotifyRequestForCatalogAddOrUpdate(ParentPlatform parentPlatform, DeviceChannel channel, int size, String type,
|
||||
SubscribeInfo subscribeInfo) throws ParseException, InvalidArgumentException,
|
||||
PeerUnavailableException {
|
||||
String catalogXmlContent = getCatalogXmlContent(parentPlatform, channel, size, type);
|
||||
String catalogXmlContent = getCatalogXmlContentForCatalogAddOrUpdate(parentPlatform, channel, size, type, subscribeInfo);
|
||||
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
@ -400,14 +400,17 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return request;
|
||||
}
|
||||
|
||||
private String getCatalogXmlContent(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type) {
|
||||
private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, DeviceChannel channel, int sumNum, String type, SubscribeInfo subscribeInfo) {
|
||||
StringBuffer catalogXml = new StringBuffer(600);
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
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("<SumNum>1</SumNum>\r\n");
|
||||
catalogXml.append("<DeviceList Num=\"1\">\r\n");
|
||||
catalogXml.append("<Item>\r\n");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
@ -418,11 +421,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
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");
|
||||
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");
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
if (!"presence".equals(subscribeInfo.getEventType())) {
|
||||
catalogXml.append("<Event>" + type + "</Event>\r\n");
|
||||
}
|
||||
catalogXml.append("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
@ -430,7 +437,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo) {
|
||||
public boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index) {
|
||||
if (parentPlatform == null
|
||||
|| deviceChannels == null
|
||||
|| deviceChannels.size() == 0
|
||||
@ -438,42 +445,55 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
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("<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");
|
||||
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("<Event>" + type + "</Event>\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()
|
||||
if (index > deviceChannels.size() - 1) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
String catalogXml = getCatalogXmlContentForCatalogOther(deviceChannels.get(index), type, parentPlatform);
|
||||
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(),
|
||||
Request request = headerProviderPlarformProvider.createNotifyRequest(parentPlatform, catalogXml,
|
||||
callIdHeader,
|
||||
"z9hG4bK-" + UUID.randomUUID().toString().replace("-", ""), subscribeInfo);
|
||||
transmitRequest(parentPlatform, request);
|
||||
Thread.sleep(200);
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
index += 1;
|
||||
Integer finalIndex = index;
|
||||
transmitRequest(parentPlatform, request, null, eventResult -> {
|
||||
sendNotifyForCatalogOther(type, parentPlatform, deviceChannels, subscribeInfo, finalIndex);
|
||||
});
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getCatalogXmlContentForCatalogOther(DeviceChannel channel, String type, ParentPlatform parentPlatform) {
|
||||
if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
|
||||
channel.setParentId(parentPlatform.getDeviceGBId());
|
||||
}
|
||||
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>1</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("</Item>\r\n");
|
||||
catalogXml.append("</DeviceList>\r\n");
|
||||
catalogXml.append("</Notify>\r\n");
|
||||
return catalogXml.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class XmlUtil {
|
||||
String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : "";
|
||||
deviceChannel.setChannelId(channelId);
|
||||
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
|
||||
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) {
|
||||
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
|
||||
deviceChannel.setStatus(1);
|
||||
}
|
||||
if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
|
||||
@ -255,9 +255,14 @@ public class XmlUtil {
|
||||
} else {
|
||||
deviceChannel.setLatitude(0.00);
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "PTZType") == null
|
||||
|| XmlUtil.getText(itemDevice, "PTZType") == "") {
|
||||
deviceChannel.setPTZType(0);
|
||||
if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) {
|
||||
//兼容INFO中的信息
|
||||
Element info = itemDevice.element("Info");
|
||||
if(XmlUtil.getText(info, "PTZType") == null || "".equals(XmlUtil.getText(info, "PTZType"))){
|
||||
deviceChannel.setPTZType(0);
|
||||
}else{
|
||||
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(info, "PTZType")));
|
||||
}
|
||||
} else {
|
||||
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public interface GbStreamMapper {
|
||||
List<GbStream> selectByGBId(String gbId);
|
||||
|
||||
@Select("SELECT gs.*, pgs.platformId as platformId, pgs.catalogId as catalogId FROM gb_stream gs " +
|
||||
"LEFT JOIN platform_gb_stream pgs ON gs.gbStreamId = pgs.catalogId " +
|
||||
"LEFT JOIN platform_gb_stream pgs ON gs.gbStreamId = pgs.gbStreamId " +
|
||||
"WHERE gs.gbId = '${gbId}' AND pgs.platformId = '${platformId}'")
|
||||
GbStream queryStreamInPlatform(String platformId, String gbId);
|
||||
|
||||
|
@ -57,9 +57,9 @@ public interface PlatformChannelMapper {
|
||||
@Select("SELECT dc.* FROM platform_gb_channel pgc left join device_channel dc on dc.id = pgc.deviceChannelId WHERE dc.channelId='${channelId}' and pgc.platformId='${platformId}'")
|
||||
DeviceChannel queryChannelInParentPlatform(String platformId, String channelId);
|
||||
|
||||
@Select("select dc.channelId as id, dc.name as name, pgc.platformId as platformId, pgc.catalogId as parentId, 0 as childrenCount, 1 as type " +
|
||||
"from device_channel dc left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId" +
|
||||
"where pgc.platformId=#{platformId} and pgc.catalogId=#{catalogId}")
|
||||
@Select(" select dc.channelId as id, dc.name as name, pgc.platformId as platformId, pgc.catalogId as parentId, 0 as childrenCount, 1 as type " +
|
||||
" from device_channel dc left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId " +
|
||||
" where pgc.platformId=#{platformId} and pgc.catalogId=#{catalogId}")
|
||||
List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId);
|
||||
|
||||
@Select("select d.*\n" +
|
||||
|
@ -211,26 +211,21 @@ public class PlatformController {
|
||||
if (updateResult) {
|
||||
// 保存时启用就发送注册
|
||||
if (parentPlatform.isEnable()) {
|
||||
// 保存时启用就发送注册
|
||||
if (parentPlatform.isEnable()) {
|
||||
if (parentPlatformOld.isStatus()) {
|
||||
commanderForPlatform.unregister(parentPlatformOld, null, null);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 只要保存就发送注册
|
||||
commanderForPlatform.register(parentPlatform, null, null);
|
||||
}else {
|
||||
// 只要保存就发送注册
|
||||
commanderForPlatform.register(parentPlatform, null, null);
|
||||
}
|
||||
} else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
|
||||
if (parentPlatformOld.isStatus()) {
|
||||
commanderForPlatform.unregister(parentPlatformOld, null, null);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 只要保存就发送注册
|
||||
commanderForPlatform.register(parentPlatform, null, null);
|
||||
}else {
|
||||
// 只要保存就发送注册
|
||||
commanderForPlatform.register(parentPlatform, null, null);
|
||||
}
|
||||
} else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
|
||||
commanderForPlatform.unregister(parentPlatform, null, null);
|
||||
commanderForPlatform.unregister(parentPlatformOld, null, null);
|
||||
}
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
|
Loading…
Reference in New Issue
Block a user