From c592740efa9d907eac3ad7d8f6e720608f3e962f Mon Sep 17 00:00:00 2001
From: xiaoxie <hotcoffie@163.com>
Date: 星期日, 01 五月 2022 21:33:56 +0800
Subject: [PATCH] 升级shelljs,解决较高版本node打包时的警告
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 221 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 177 insertions(+), 44 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 25a2f25..a99ef4d 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -5,10 +5,7 @@
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo;
-import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
@@ -23,6 +20,7 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
+import gov.nist.javax.sip.message.MessageFactoryImpl;
import gov.nist.javax.sip.message.SIPRequest;
import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
@@ -35,8 +33,7 @@
import javax.sip.*;
import javax.sip.address.SipURI;
-import javax.sip.header.CallIdHeader;
-import javax.sip.header.ViaHeader;
+import javax.sip.header.*;
import javax.sip.message.Request;
import java.lang.reflect.Field;
import java.text.ParseException;
@@ -55,6 +52,9 @@
@Autowired
private SipConfig sipConfig;
+
+ @Autowired
+ private SipFactory sipFactory;
@Autowired
@Qualifier(value="tcpSipProvider")
@@ -229,7 +229,8 @@
try {
String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -271,7 +272,8 @@
String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
logger.debug("鎺у埗瀛楃涓诧細" + cmdStr);
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -303,10 +305,11 @@
* @param cmdString 鍓嶇鎺у埗鎸囦护涓�
*/
@Override
- public boolean fronEndCmd(Device device, String channelId, String cmdString) {
+ public boolean fronEndCmd(Device device, String channelId, String cmdString, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) {
try {
StringBuffer ptzXml = new StringBuffer(200);
- ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -323,7 +326,7 @@
: udpSipProvider.getNewCallId();
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
- transmitRequest(device, request);
+ transmitRequest(device, request, errorEvent, okEvent);
return true;
} catch (SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
@@ -340,7 +343,7 @@
*/
@Override
public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
- ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
+ ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
String streamId = ssrcInfo.getStream();
try {
if (device == null) return;
@@ -433,6 +436,7 @@
// 杩欓噷涓轰緥閬垮厤涓�涓�氶亾鐨勭偣鎾彧鏈変竴涓猚allID杩欎釜鍙傛暟浣跨敤涓�涓浐瀹氬��
streamSession.put(device.getDeviceId(), channelId ,"play", streamId, ssrcInfo.getSsrc(), mediaServerItem.getId(), ((ResponseEvent)e.event).getClientTransaction(), VideoStreamSessionManager.SessionType.play);
streamSession.put(device.getDeviceId(), channelId ,"play", e.dialog);
+ okEvent.response(e);
});
@@ -725,7 +729,7 @@
Request byeRequest = dialog.createRequest(Request.BYE);
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
SIPRequest request = (SIPRequest)transaction.getRequest();
- byeURI.setHost(request.getRemoteAddress().getHostName());
+ byeURI.setHost(request.getRemoteAddress().getHostAddress());
byeURI.setPort(request.getRemotePort());
ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
String protocol = viaHeader.getTransport().toUpperCase();
@@ -769,7 +773,8 @@
public boolean audioBroadcastCmd(Device device) {
try {
StringBuffer broadcastXml = new StringBuffer(200);
- broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -794,7 +799,8 @@
public void audioBroadcastCmd(Device device, SipSubscribe.Event errorEvent) {
try {
StringBuffer broadcastXml = new StringBuffer(200);
- broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -826,7 +832,8 @@
public boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -861,7 +868,8 @@
public boolean teleBootCmd(Device device) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -893,7 +901,8 @@
public boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -924,7 +933,8 @@
public boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -968,7 +978,8 @@
public boolean iFrameCmd(Device device, String channelId) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1006,7 +1017,8 @@
public boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1074,7 +1086,8 @@
String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1191,14 +1204,14 @@
* @param device 瑙嗛璁惧
*/
@Override
- public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
+ public boolean catalogQuery(Device device, int sn, SipSubscribe.Event errorEvent) {
try {
StringBuffer catalogXml = new StringBuffer(200);
String charset = device.getCharset();
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
- catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
+ catalogXml.append("<SN>" + sn + "</SN>\r\n");
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
catalogXml.append("</Query>\r\n");
@@ -1288,7 +1301,8 @@
String startTime, String endTime, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1338,7 +1352,8 @@
public boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1373,7 +1388,8 @@
public boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
- cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
@@ -1438,7 +1454,7 @@
* @param device 瑙嗛璁惧
* @return true = 鍛戒护鍙戦�佹垚鍔�
*/
- public boolean mobilePositionSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
+ public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
try {
StringBuffer subscribePostitionXml = new StringBuffer(200);
String charset = device.getCharset();
@@ -1452,12 +1468,20 @@
}
subscribePostitionXml.append("</Query>\r\n");
- String tm = Long.toString(System.currentTimeMillis());
-
- CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
- : udpSipProvider.getNewCallId();
-
- Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
+ Request request;
+ if (dialog != null) {
+ logger.info("鍙戦�佺Щ鍔ㄤ綅缃闃呮秷鎭椂 dialog鐨勭姸鎬佷负锛� {}", dialog.getState());
+ request = dialog.createRequest(Request.SUBSCRIBE);
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+ request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
+ ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
+ request.addHeader(expireHeader);
+ }else {
+ String tm = Long.toString(System.currentTimeMillis());
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+ request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
+ }
transmitRequest(device, request, errorEvent, okEvent);
return true;
@@ -1527,7 +1551,7 @@
}
@Override
- public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
+ public boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
try {
StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset();
@@ -1538,17 +1562,28 @@
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("</Query>\r\n");
- String tm = Long.toString(System.currentTimeMillis());
- CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
- : udpSipProvider.getNewCallId();
+ Request request;
+ if (dialog != null) {
+ logger.info("鍙戦�佺洰褰曡闃呮秷鎭椂 dialog鐨勭姸鎬佷负锛� {}", dialog.getState());
+ request = dialog.createRequest(Request.SUBSCRIBE);
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+ request.setContent(cmdXml.toString(), contentTypeHeader);
+ ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
+ request.addHeader(expireHeader);
+ }else {
+ String tm = Long.toString(System.currentTimeMillis());
- // 鏈夋晥鏃堕棿榛樿涓�60绉掍互涓�
- Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm,
- "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "Catalog" ,
- callIdHeader);
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+
+ // 鏈夋晥鏃堕棿榛樿涓�60绉掍互涓�
+ request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "z9hG4bK-viaPos-" + tm,
+ "fromTagPos" + tm, null, device.getSubscribeCycleForCatalog(), "Catalog" ,
+ callIdHeader);
+
+ }
transmitRequest(device, request, errorEvent, okEvent);
-
return true;
} catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
@@ -1561,7 +1596,8 @@
public boolean dragZoomCmd(Device device, String channelId, String cmdString) {
try {
StringBuffer dragXml = new StringBuffer(200);
- dragXml.append("<?xml version=\"1.0\" ?>\r\n");
+ String charset = device.getCharset();
+ dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
dragXml.append("<Control>\r\n");
dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
@@ -1737,4 +1773,101 @@
e.printStackTrace();
}
}
+
+ @Override
+ public boolean sendAlarmMessage(Device device, DeviceAlarm deviceAlarm) {
+ if (device == null) {
+ return false;
+ }
+ logger.info("[鍙戦�� 鎶ヨ閫氱煡] {}/{}->{},{}", device.getDeviceId(), deviceAlarm.getChannelId(),
+ deviceAlarm.getLongitude(), deviceAlarm.getLatitude());
+ try {
+ String characterSet = device.getCharset();
+ StringBuffer deviceStatusXml = new StringBuffer(600);
+ deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
+ deviceStatusXml.append("<Notify>\r\n");
+ deviceStatusXml.append("<CmdType>Alarm</CmdType>\r\n");
+ deviceStatusXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
+ deviceStatusXml.append("<DeviceID>" + deviceAlarm.getChannelId() + "</DeviceID>\r\n");
+ deviceStatusXml.append("<AlarmPriority>" + deviceAlarm.getAlarmPriority() + "</AlarmPriority>\r\n");
+ deviceStatusXml.append("<AlarmMethod>" + deviceAlarm.getAlarmMethod() + "</AlarmMethod>\r\n");
+ deviceStatusXml.append("<AlarmTime>" + deviceAlarm.getAlarmTime() + "</AlarmTime>\r\n");
+ deviceStatusXml.append("<AlarmDescription>" + deviceAlarm.getAlarmDescription() + "</AlarmDescription>\r\n");
+ deviceStatusXml.append("<Longitude>" + deviceAlarm.getLongitude() + "</Longitude>\r\n");
+ deviceStatusXml.append("<Latitude>" + deviceAlarm.getLatitude() + "</Latitude>\r\n");
+ deviceStatusXml.append("<info>\r\n");
+ deviceStatusXml.append("<AlarmType>" + deviceAlarm.getAlarmType() + "</AlarmType>\r\n");
+ deviceStatusXml.append("</info>\r\n");
+ deviceStatusXml.append("</Notify>\r\n");
+
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, deviceStatusXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
+ transmitRequest(device, request);
+
+
+ } catch (SipException | ParseException e) {
+ e.printStackTrace();
+ return false;
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+
+ private void sendNotify(Device device, String catalogXmlContent,
+ SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
+ throws NoSuchFieldException, IllegalAccessException, SipException, ParseException {
+ MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
+ String characterSet = device.getCharset();
+ // 璁剧疆缂栫爜锛� 闃叉涓枃涔辩爜
+ messageFactory.setDefaultContentEncodingCharset(characterSet);
+ Dialog dialog = subscribeInfo.getDialog();
+ if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return;
+ SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+ notifyRequest.setContent(catalogXmlContent, contentTypeHeader);
+
+ SubscriptionStateHeader subscriptionState = sipFactory.createHeaderFactory()
+ .createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
+ notifyRequest.addHeader(subscriptionState);
+
+ EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
+ if (subscribeInfo.getEventId() != null) {
+ event.setEventId(subscribeInfo.getEventId());
+ }
+ notifyRequest.addHeader(event);
+
+ SipURI sipURI = (SipURI) notifyRequest.getRequestURI();
+ if (subscribeInfo.getTransaction() != null) {
+ SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
+ sipURI.setHost(request.getRemoteAddress().getHostAddress());
+ sipURI.setPort(request.getRemotePort());
+ }else {
+ sipURI.setHost(device.getIp());
+ sipURI.setPort(device.getPort());
+ }
+
+ ClientTransaction transaction = null;
+ if ("TCP".equals(device.getTransport())) {
+ transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
+ } else if ("UDP".equals(device.getTransport())) {
+ transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
+ }
+ // 娣诲姞閿欒璁㈤槄
+ if (errorEvent != null) {
+ sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent);
+ }
+ // 娣诲姞璁㈤槄
+ if (okEvent != null) {
+ sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent);
+ }
+ if (transaction == null) {
+ logger.error("骞冲彴{}鐨凾ransport閿欒锛歿}",device.getDeviceId(), device.getTransport());
+ return;
+ }
+ dialog.sendRequest(transaction);
+
+ }
}
--
Gitblit v1.8.0