|
|
@@ -1,95 +1,96 @@
|
|
|
-//package org.jetlinks.community.media.sip.request.impl;
|
|
|
-//
|
|
|
-//import lombok.AllArgsConstructor;
|
|
|
-//import lombok.extern.slf4j.Slf4j;
|
|
|
-//import org.dom4j.DocumentException;
|
|
|
-//import org.dom4j.Element;
|
|
|
-//import org.jetlinks.community.media.config.UserSetup;
|
|
|
-//import org.jetlinks.community.media.contanst.CmdType;
|
|
|
-//import org.jetlinks.community.media.contanst.VideoManagerConstants;
|
|
|
-//import org.jetlinks.community.media.sip.SipRequestProcessorParent;
|
|
|
-//import org.jetlinks.community.media.storage.impl.RedisCacheStorageImpl;
|
|
|
-//import org.jetlinks.community.utils.SipUtils;
|
|
|
-//import org.jetlinks.community.utils.XmlUtil;
|
|
|
-//import org.slf4j.Logger;
|
|
|
-//import org.slf4j.LoggerFactory;
|
|
|
-//import org.springframework.beans.factory.InitializingBean;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.stereotype.Component;
|
|
|
-//
|
|
|
-//import javax.sip.InvalidArgumentException;
|
|
|
-//import javax.sip.RequestEvent;
|
|
|
-//import javax.sip.ServerTransaction;
|
|
|
-//import javax.sip.SipException;
|
|
|
-//import javax.sip.header.ExpiresHeader;
|
|
|
-//import javax.sip.header.ToHeader;
|
|
|
-//import javax.sip.message.Request;
|
|
|
-//import javax.sip.message.Response;
|
|
|
-//import java.text.ParseException;
|
|
|
-//import java.util.Optional;
|
|
|
-//
|
|
|
-///**
|
|
|
-// * SIP命令类型: SUBSCRIBE请求
|
|
|
-// */
|
|
|
-//@Component
|
|
|
-//@Slf4j
|
|
|
-//public class SubscribeRequestProcessor extends SipRequestProcessorParent {
|
|
|
-//
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private RedisCacheStorageImpl redisCatchStorage;
|
|
|
-//
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private UserSetup userSetup;
|
|
|
-//
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 处理SUBSCRIBE请求
|
|
|
-// *
|
|
|
-// * @param evt
|
|
|
-// */
|
|
|
-// @Override
|
|
|
-// public void processRequest(RequestEvent evt) {
|
|
|
-// Request request = evt.getRequest();
|
|
|
-// try {
|
|
|
-// Element rootElement = getRootElement(evt);
|
|
|
-// String cmd = XmlUtil.getText(rootElement, "CmdType");
|
|
|
-// if (CmdType.MOBILE_POSITION.equals(cmd)) {
|
|
|
-// processNotifyMobilePosition(evt, rootElement);
|
|
|
-// } else if (CmdType.ALARM.equals(cmd)) {
|
|
|
-// log.info("接收到Alarm订阅");
|
|
|
-// processNotifyAlarm(evt, rootElement);
|
|
|
-// } else if (CmdType.CATALOG.equals(cmd)) {
|
|
|
-// processNotifyCatalogList(evt, rootElement);
|
|
|
-// } else {
|
|
|
-// log.info("接收到消息:" + cmd);
|
|
|
-// Response response = null;
|
|
|
-// response = getMessageFactory().createResponse(200, request);
|
|
|
-// if (response != null) {
|
|
|
-// ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30);
|
|
|
-// response.setExpires(expireHeader);
|
|
|
-// }
|
|
|
-// log.info("response : " + response);
|
|
|
-// ServerTransaction transaction = getServerTransaction(evt);
|
|
|
-// if (transaction != null) {
|
|
|
-// transaction.sendResponse(response);
|
|
|
-// transaction.getDialog().delete();
|
|
|
-// transaction.terminate();
|
|
|
-// } else {
|
|
|
-// log.info("processRequest serverTransactionId is null.");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("SIP订阅发生错误,",e);
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 处理移动位置订阅消息
|
|
|
-// */
|
|
|
-// private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) {
|
|
|
+package org.jetlinks.community.media.sip.request.impl;
|
|
|
+
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dom4j.DocumentException;
|
|
|
+import org.dom4j.Element;
|
|
|
+import org.jetlinks.community.media.bean.SubscribeInfo;
|
|
|
+import org.jetlinks.community.media.config.UserSetup;
|
|
|
+import org.jetlinks.community.media.contanst.CmdType;
|
|
|
+import org.jetlinks.community.media.contanst.VideoManagerConstants;
|
|
|
+import org.jetlinks.community.media.sip.SipRequestProcessorParent;
|
|
|
+import org.jetlinks.community.media.storage.impl.RedisCacheStorageImpl;
|
|
|
+import org.jetlinks.community.utils.SipUtils;
|
|
|
+import org.jetlinks.community.utils.XmlUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.sip.InvalidArgumentException;
|
|
|
+import javax.sip.RequestEvent;
|
|
|
+import javax.sip.ServerTransaction;
|
|
|
+import javax.sip.SipException;
|
|
|
+import javax.sip.header.ExpiresHeader;
|
|
|
+import javax.sip.header.ToHeader;
|
|
|
+import javax.sip.message.Request;
|
|
|
+import javax.sip.message.Response;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * SIP命令类型: SUBSCRIBE请求
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class SubscribeRequestProcessor extends SipRequestProcessorParent {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCacheStorageImpl redisCatchStorage;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserSetup userSetup;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理SUBSCRIBE请求
|
|
|
+ *
|
|
|
+ * @param evt
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void processRequest(RequestEvent evt) {
|
|
|
+ Request request = evt.getRequest();
|
|
|
+ try {
|
|
|
+ Element rootElement = getRootElement(evt);
|
|
|
+ String cmd = XmlUtil.getText(rootElement, "CmdType");
|
|
|
+ if (CmdType.MOBILE_POSITION.equals(cmd)) {
|
|
|
+ processNotifyMobilePosition(evt, rootElement);
|
|
|
+ } else if (CmdType.ALARM.equals(cmd)) {
|
|
|
+ log.info("接收到Alarm订阅");
|
|
|
+ processNotifyAlarm(evt, rootElement);
|
|
|
+ } else if (CmdType.CATALOG.equals(cmd)) {
|
|
|
+ processNotifyCatalogList(evt, rootElement);
|
|
|
+ } else {
|
|
|
+ log.info("接收到消息:" + cmd);
|
|
|
+ Response response = null;
|
|
|
+ response = getMessageFactory().createResponse(200, request);
|
|
|
+ if (response != null) {
|
|
|
+ ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30);
|
|
|
+ response.setExpires(expireHeader);
|
|
|
+ }
|
|
|
+ log.info("response : " + response);
|
|
|
+ ServerTransaction transaction = getServerTransaction(evt);
|
|
|
+ if (transaction != null) {
|
|
|
+ transaction.sendResponse(response);
|
|
|
+ transaction.getDialog().delete();
|
|
|
+ transaction.terminate();
|
|
|
+ } else {
|
|
|
+ log.info("processRequest serverTransactionId is null.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SIP订阅发生错误,",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理移动位置订阅消息
|
|
|
+ */
|
|
|
+ private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) {
|
|
|
// String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
|
|
// String deviceID = XmlUtil.getText(rootElement, "DeviceID");
|
|
|
// SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
|
|
|
@@ -133,51 +134,47 @@
|
|
|
// } catch (ParseException e) {
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void processNotifyAlarm(RequestEvent evt, Element rootElement) {
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void processNotifyCatalogList(RequestEvent evt, Element rootElement) {
|
|
|
-// String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
|
|
-// String deviceID = XmlUtil.getText(rootElement, "DeviceID");
|
|
|
-// SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
|
|
|
-// String sn = XmlUtil.getText(rootElement, "SN");
|
|
|
-// String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_" + platformId;
|
|
|
-// log.info("接收到{}的Catalog订阅", platformId);
|
|
|
-// StringBuilder resultXml = new StringBuilder(200);
|
|
|
-// resultXml.append("<?xml version=\"1.0\" ?>\r\n")
|
|
|
-// .append("<Response>\r\n")
|
|
|
-// .append("<CmdType>Catalog</CmdType>\r\n")
|
|
|
-// .append("<SN>" + sn + "</SN>\r\n")
|
|
|
-// .append("<DeviceID>" + deviceID + "</DeviceID>\r\n")
|
|
|
-// .append("<Result>OK</Result>\r\n")
|
|
|
-// .append("</Response>\r\n");
|
|
|
-//
|
|
|
-// if (subscribeInfo.getExpires() > 0) {
|
|
|
-// redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
|
|
-// }else if (subscribeInfo.getExpires() == 0) {
|
|
|
-// redisCatchStorage.delSubscribe(key);
|
|
|
-// }
|
|
|
-//
|
|
|
-// try {
|
|
|
-// Response response = responseXmlAck(evt, resultXml.toString());
|
|
|
-// ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME);
|
|
|
-// subscribeInfo.setToTag(toHeader.getTag());
|
|
|
-// redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
|
|
-//
|
|
|
-// } catch (SipException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// } catch (InvalidArgumentException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// } catch (ParseException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public String getMethod() {
|
|
|
-// return Request.SUBSCRIBE;
|
|
|
-// }
|
|
|
-//}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processNotifyAlarm(RequestEvent evt, Element rootElement) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processNotifyCatalogList(RequestEvent evt, Element rootElement) {
|
|
|
+ String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
|
|
+ String deviceID = XmlUtil.getText(rootElement, "DeviceID");
|
|
|
+ SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
|
|
|
+ String sn = XmlUtil.getText(rootElement, "SN");
|
|
|
+ String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_Catalog_" + platformId;
|
|
|
+ log.info("接收到{}的Catalog订阅", platformId);
|
|
|
+ StringBuilder resultXml = new StringBuilder(200);
|
|
|
+ resultXml.append("<?xml version=\"1.0\" ?>\r\n")
|
|
|
+ .append("<Response>\r\n")
|
|
|
+ .append("<CmdType>Catalog</CmdType>\r\n")
|
|
|
+ .append("<SN>" + sn + "</SN>\r\n")
|
|
|
+ .append("<DeviceID>" + deviceID + "</DeviceID>\r\n")
|
|
|
+ .append("<Result>OK</Result>\r\n")
|
|
|
+ .append("</Response>\r\n");
|
|
|
+
|
|
|
+ if (subscribeInfo.getExpires() > 0) {
|
|
|
+ redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
|
|
+ }else if (subscribeInfo.getExpires() == 0) {
|
|
|
+ redisCatchStorage.delSubscribe(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Response response = responseXmlAck(evt, resultXml.toString());
|
|
|
+ ToHeader toHeader = (ToHeader)response.getHeader(ToHeader.NAME);
|
|
|
+ subscribeInfo.setToTag(toHeader.getTag());
|
|
|
+ redisCatchStorage.updateSubscribe(key, subscribeInfo);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("设备目录订阅发生错误,",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getMethod() {
|
|
|
+ return Request.SUBSCRIBE;
|
|
|
+ }
|
|
|
+}
|