From f10b458fc919fbcadc4936bf3a7886088e20ac71 Mon Sep 17 00:00:00 2001
From: 648540858 <456panlinlin>
Date: 星期五, 08 四月 2022 14:44:49 +0800
Subject: [PATCH] 优化订阅信息的发送与取消订阅

---
 src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java                        |   75 ++++++++++++
 src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java                                |   12 -
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java                        |   29 +++-
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java                                 |   11 +
 src/main/java/com/genersoft/iot/vmp/conf/runner/SipDeviceRunner.java                                   |   14 +
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java |    8 
 src/main/java/com/genersoft/iot/vmp/gb28181/task/ISubscribeTask.java                                   |    5 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java                            |    6 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java  |    2 
 /dev/null                                                                                              |   38 ------
 web_src/src/components/dialog/deviceEdit.vue                                                           |   11 +
 src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeTask.java                 |   77 ++++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java          |   16 ++
 src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java                                              |   14 +
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java      |    6 
 15 files changed, 242 insertions(+), 82 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
index bbe0e81..0c57bde 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
@@ -1,5 +1,6 @@
 package com.genersoft.iot.vmp.conf;
 
+import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -21,6 +22,7 @@
     private ThreadPoolTaskScheduler threadPoolTaskScheduler;
 
     private Map<String, ScheduledFuture<?>> futureMap = new ConcurrentHashMap<>();
+    private Map<String, Runnable> runnableMap = new ConcurrentHashMap<>();
 
     @Bean
     public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
@@ -34,12 +36,12 @@
      * @param cycleForCatalog 闂撮殧
      * @return
      */
-    public String startCron(String key, Runnable task, int cycleForCatalog) {
+    public void startCron(String key, Runnable task, int cycleForCatalog) {
         stop(key);
         // scheduleWithFixedDelay 蹇呴』绛夊緟涓婁竴涓换鍔$粨鏉熸墠寮�濮嬭鏃秔eriod锛� cycleForCatalog琛ㄧず鎵ц鐨勯棿闅�
         ScheduledFuture future = threadPoolTaskScheduler.scheduleWithFixedDelay(task, cycleForCatalog * 1000L);
         futureMap.put(key, future);
-        return "startCron";
+        runnableMap.put(key, task);
     }
 
     /**
@@ -49,18 +51,22 @@
      * @param delay 寤舵椂 /姣
      * @return
      */
-    public String startDelay(String key, Runnable task, int delay) {
+    public void startDelay(String key, Runnable task, int delay) {
         stop(key);
         Date starTime = new Date(System.currentTimeMillis() + delay);
         // scheduleWithFixedDelay 蹇呴』绛夊緟涓婁竴涓换鍔$粨鏉熸墠寮�濮嬭鏃秔eriod锛� cycleForCatalog琛ㄧず鎵ц鐨勯棿闅�
         ScheduledFuture future = threadPoolTaskScheduler.schedule(task, starTime);
         futureMap.put(key, future);
-        return "startCron";
     }
 
     public void stop(String key) {
         if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) {
             futureMap.get(key).cancel(true);
+            Runnable runnable = runnableMap.get(key);
+            if (runnable instanceof ISubscribeTask) {
+                ISubscribeTask subscribeTask = (ISubscribeTask) runnable;
+                subscribeTask.stop();
+            }
         }
     }
 
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/runner/SipDeviceRunner.java b/src/main/java/com/genersoft/iot/vmp/conf/runner/SipDeviceRunner.java
index 2c2ea6d..4a89796 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/runner/SipDeviceRunner.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/runner/SipDeviceRunner.java
@@ -14,7 +14,7 @@
 
 
 /**
- * 绯荤粺鍚姩鏃舵帶鍒惰澶囩绾�
+ * 绯荤粺鍚姩鏃舵帶鍒惰澶�
  */
 @Component
 @Order(value=4)
@@ -41,10 +41,14 @@
         for (String deviceId : onlineForAll) {
             storager.online(deviceId);
             Device device = redisCatchStorage.getDevice(deviceId);
-            if (device != null && device.getSubscribeCycleForCatalog() > 0) {
-                // 鏌ヨ鍦ㄧ嚎璁惧閭d簺寮�鍚簡璁㈤槄锛屼负璁惧寮�鍚畾鏃剁殑鐩綍璁㈤槄
-                deviceService.addCatalogSubscribe(device);
-                deviceService.addMobilePositionSubscribe(device);
+            if (device != null ) {
+                if (device.getSubscribeCycleForCatalog() > 0) {
+                    // 鏌ヨ鍦ㄧ嚎璁惧閭d簺寮�鍚簡璁㈤槄锛屼负璁惧寮�鍚畾鏃剁殑鐩綍璁㈤槄
+                    deviceService.addCatalogSubscribe(device);
+                }
+                if (device.getSubscribeCycleForMobilePosition() > 0) {
+                    deviceService.addMobilePositionSubscribe(device);
+                }
             }
         }
         // 閲嶇疆cseq璁℃暟
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/ISubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/ISubscribeTask.java
new file mode 100644
index 0000000..4c6a18a
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/ISubscribeTask.java
@@ -0,0 +1,5 @@
+package com.genersoft.iot.vmp.gb28181.task;
+
+public interface ISubscribeTask extends Runnable{
+    void stop();
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
new file mode 100644
index 0000000..51356d5
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
@@ -0,0 +1,75 @@
+package com.genersoft.iot.vmp.gb28181.task.impl;
+
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sip.Dialog;
+import javax.sip.DialogState;
+import javax.sip.ResponseEvent;
+
+/**
+ * 鐩綍璁㈤槄浠诲姟
+ */
+public class CatalogSubscribeTask implements ISubscribeTask {
+    private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
+    private Device device;
+    private final ISIPCommander sipCommander;
+    private Dialog dialog;
+
+    public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
+        this.device = device;
+        this.sipCommander = sipCommander;
+    }
+
+    @Override
+    public void run() {
+        sipCommander.catalogSubscribe(device, dialog, eventResult -> {
+            if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
+                dialog = eventResult.dialog;
+            }
+            ResponseEvent event = (ResponseEvent) eventResult.event;
+            if (event.getResponse().getRawContent() != null) {
+                // 鎴愬姛
+                logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+            }else {
+                // 鎴愬姛
+                logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+            }
+        },eventResult -> {
+            dialog = null;
+            // 澶辫触
+            logger.warn("[鐩綍璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
+        });
+    }
+
+    @Override
+    public void stop() {
+        /**
+         * dialog 鐨勫悇涓姸鎬�
+         * EARLY-> Early state鐘舵��-鍒濆璇锋眰鍙戦�佷互鍚庯紝鏀跺埌浜嗕竴涓复鏃跺搷搴旀秷鎭�
+         * CONFIRMED-> Confirmed Dialog鐘舵��-宸茬‘璁�
+         * COMPLETED-> Completed Dialog鐘舵��-宸插畬鎴�
+         * TERMINATED-> Terminated Dialog鐘舵��-缁堟
+         */
+        logger.info("鍙栨秷鐩綍璁㈤槄鏃禿ialog鐘舵�佷负{}", DialogState.CONFIRMED);
+        if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
+            device.setSubscribeCycleForCatalog(0);
+            sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
+                ResponseEvent event = (ResponseEvent) eventResult.event;
+                if (event.getResponse().getRawContent() != null) {
+                    // 鎴愬姛
+                    logger.info("[鍙栨秷鐩綍璁㈤槄璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+                }else {
+                    // 鎴愬姛
+                    logger.info("[鍙栨秷鐩綍璁㈤槄璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+                }
+            },eventResult -> {
+                // 澶辫触
+                logger.warn("[鍙栨秷鐩綍璁㈤槄璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
+            });
+        }
+    }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/GPSSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java
similarity index 83%
rename from src/main/java/com/genersoft/iot/vmp/gb28181/task/GPSSubscribeTask.java
rename to src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java
index a2716e3..fcac3e9 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/task/GPSSubscribeTask.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java
@@ -1,10 +1,10 @@
-package com.genersoft.iot.vmp.gb28181.task;
+package com.genersoft.iot.vmp.gb28181.task.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
 import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
+import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -13,7 +13,10 @@
 import java.text.SimpleDateFormat;
 import java.util.List;
 
-public class GPSSubscribeTask implements Runnable{
+/**
+ * 鍚戝凡缁忚闃�(绉诲姩浣嶇疆)鐨勪笂绾у彂閫丮obilePosition娑堟伅
+ */
+public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
 
     private IRedisCatchStorage redisCatchStorage;
     private IVideoManagerStorage storager;
@@ -25,7 +28,7 @@
 
     private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
-    public GPSSubscribeTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
+    public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
         this.redisCatchStorage = redisCatchStorage;
         this.storager = storager;
         this.platformId = platformId;
@@ -66,4 +69,9 @@
             }
         }
     }
+
+    @Override
+    public void stop() {
+
+    }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeTask.java
new file mode 100644
index 0000000..f67f6d2
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeTask.java
@@ -0,0 +1,77 @@
+package com.genersoft.iot.vmp.gb28181.task.impl;
+
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import org.dom4j.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sip.Dialog;
+import javax.sip.DialogState;
+import javax.sip.ResponseEvent;
+
+/**
+ * 绉诲姩浣嶇疆璁㈤槄鐨勫畾鏃舵洿鏂�
+ */
+public class MobilePositionSubscribeTask implements ISubscribeTask {
+    private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
+    private  Device device;
+    private  ISIPCommander sipCommander;
+    private Dialog dialog;
+
+    public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
+        this.device = device;
+        this.sipCommander = sipCommander;
+    }
+
+    @Override
+    public void run() {
+        sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
+            if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
+                dialog = eventResult.dialog;
+            }
+            ResponseEvent event = (ResponseEvent) eventResult.event;
+            if (event.getResponse().getRawContent() != null) {
+                // 鎴愬姛
+                logger.info("[绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+            }else {
+                // 鎴愬姛
+                logger.info("[绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+            }
+        },eventResult -> {
+            dialog = null;
+            // 澶辫触
+            logger.warn("[绉诲姩浣嶇疆璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
+        });
+
+    }
+
+    @Override
+    public void stop() {
+        /**
+         * dialog 鐨勫悇涓姸鎬�
+         * EARLY-> Early state鐘舵��-鍒濆璇锋眰鍙戦�佷互鍚庯紝鏀跺埌浜嗕竴涓复鏃跺搷搴旀秷鎭�
+         * CONFIRMED-> Confirmed Dialog鐘舵��-宸茬‘璁�
+         * COMPLETED-> Completed Dialog鐘舵��-宸插畬鎴�
+         * TERMINATED-> Terminated Dialog鐘舵��-缁堟
+         */
+        logger.info("鍙栨秷绉诲姩璁㈤槄鏃禿ialog鐘舵�佷负{}", dialog.getState());
+        if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
+            device.setSubscribeCycleForMobilePosition(0);
+            sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
+                ResponseEvent event = (ResponseEvent) eventResult.event;
+                if (event.getResponse().getRawContent() != null) {
+                    // 鎴愬姛
+                    logger.info("[鍙栨秷绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+                }else {
+                    // 鎴愬姛
+                    logger.info("[鍙栨秷绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
+                }
+            },eventResult -> {
+                // 澶辫触
+                logger.warn("[鍙栨秷绉诲姩浣嶇疆璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
+            });
+        }
+    }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
index 6b8a6ae..1de03bd 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
@@ -8,6 +8,8 @@
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
 
+import javax.sip.Dialog;
+
 /**    
  * @description:璁惧鑳藉姏鎺ュ彛锛岀敤浜庡畾涔夎澶囩殑鎺у埗銆佹煡璇㈣兘鍔�   
  * @author: swwheihei
@@ -304,7 +306,7 @@
 	 * @param device	瑙嗛璁惧
 	 * @return			true = 鍛戒护鍙戦�佹垚鍔�
 	 */
-	boolean mobilePositionSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
+	boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent , SipSubscribe.Event errorEvent);
 
 	/**
 	 * 璁㈤槄銆佸彇娑堣闃呮姤璀︿俊鎭�
@@ -324,7 +326,7 @@
 	 * @param device		瑙嗛璁惧
 	 * @return				true = 鍛戒护鍙戦�佹垚鍔�
 	 */
-	boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
+	boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
 
 	/**
 	 * 鎷夋鎺у埗鍛戒护
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 4baa349..123d0e7 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
@@ -36,6 +36,8 @@
 import javax.sip.*;
 import javax.sip.address.SipURI;
 import javax.sip.header.CallIdHeader;
+import javax.sip.header.ContentTypeHeader;
+import javax.sip.header.ExpiresHeader;
 import javax.sip.header.ViaHeader;
 import javax.sip.message.Request;
 import java.lang.reflect.Field;
@@ -55,6 +57,9 @@
 	
 	@Autowired
 	private SipConfig sipConfig;
+
+	@Autowired
+	private SipFactory sipFactory;
 
 	@Autowired
 	@Qualifier(value="tcpSipProvider")
@@ -1453,7 +1458,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();
@@ -1467,12 +1472,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;
@@ -1542,7 +1555,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();
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
index e8554f7..1336705 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
@@ -7,7 +7,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
 import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
-import com.genersoft.iot.vmp.gb28181.task.GPSSubscribeTask;
+import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeHandlerTask;
 import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
@@ -147,7 +147,7 @@
 		}
 		String sn = XmlUtil.getText(rootElement, "SN");
 		String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() +  "_MobilePosition_" + platformId;
-		logger.info("鎺ユ敹鍒皗}鐨凪obilePosition璁㈤槄", platformId);
+		logger.info("[notify-MobilePosition]: {}", platformId);
 		StringBuilder resultXml = new StringBuilder(200);
 		resultXml.append("<?xml version=\"1.0\" ?>\r\n")
 				.append("<Response>\r\n")
@@ -162,7 +162,7 @@
 				dynamicTask.stop(key);
 			}
 			String interval = XmlUtil.getText(rootElement, "Interval"); // GPS涓婃姤鏃堕棿闂撮殧
-			dynamicTask.startCron(key, new GPSSubscribeTask(redisCatchStorage, sipCommanderForPlatform, storager,  platformId, sn, key, subscribeHolder), Integer.parseInt(interval));
+			dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform, storager,  platformId, sn, key, subscribeHolder), Integer.parseInt(interval) -1 );
 			subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
 		}else if (subscribeInfo.getExpires() == 0) {
 			dynamicTask.stop(key);
@@ -200,7 +200,7 @@
 		}
 		String sn = XmlUtil.getText(rootElement, "SN");
 		String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() +  "_Catalog_" + platformId;
-		logger.info("鎺ユ敹鍒皗}鐨凜atalog璁㈤槄", platformId);
+		logger.info("[notify-Catalog]: {}", platformId);
 		StringBuilder resultXml = new StringBuilder(200);
 		resultXml.append("<?xml version=\"1.0\" ?>\r\n")
 				.append("<Response>\r\n")
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java
index 1b5081b..c81aabb 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java
@@ -81,7 +81,7 @@
 				}
 				requestURI.setPort(event.getRemotePort());
 				reqAck.setRequestURI(requestURI);
-				logger.info("鍚� " + event.getRemoteIpAddress() + ":" + event.getRemotePort() + "鍥炲ack");
+				logger.info("[鍥炲ack] {}-> {}:{} ",requestURI, event.getRemoteIpAddress(), event.getRemotePort());
 
 				dialog.sendAck(reqAck);
 
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
index 57afd93..de9f176 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -82,9 +82,14 @@
     }
 
     public int createRTPServer(MediaServerItem mediaServerItem, String streamId) {
-
-        Map<String, Object> param = new HashMap<>();
         int result = -1;
+        // 鏌ヨ姝tp server 鏄惁宸茬粡瀛樺湪
+        JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
+        if (rtpInfo.getInteger("code ") == 0 && rtpInfo.getBoolean("exist")) {
+            result = rtpInfo.getInteger("local_port");
+            return result;
+        }
+        Map<String, Object> param = new HashMap<>();
         // 鎺ㄦ祦绔彛璁剧疆0鍒欎娇鐢ㄩ殢鏈虹鍙�
         param.put("enable_tcp", 1);
         param.put("stream_id", streamId);
@@ -301,7 +306,7 @@
             result= true;
             logger.info("鍋滄RTP鎺ㄦ祦鎴愬姛");
         } else {
-            logger.error("RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}",jsonObject.getString("msg"),JSONObject.toJSON(param));
+            logger.error("鍋滄RTP鎺ㄦ祦澶辫触: {}, 鍙傛暟锛歿}",jsonObject.getString("msg"),JSONObject.toJSON(param));
         }
         return result;
     }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/CatalogSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/service/bean/CatalogSubscribeTask.java
deleted file mode 100644
index 68419bf..0000000
--- a/src/main/java/com/genersoft/iot/vmp/service/bean/CatalogSubscribeTask.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.genersoft.iot.vmp.service.bean;
-
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
-import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.sip.ResponseEvent;
-
-/**
- * 鐩綍璁㈤槄浠诲姟
- */
-public class CatalogSubscribeTask implements Runnable{
-    private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
-    private  Device device;
-    private  ISIPCommander sipCommander;
-
-    public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
-        this.device = device;
-        this.sipCommander = sipCommander;
-    }
-
-    @Override
-    public void run() {
-        sipCommander.catalogSubscribe(device, eventResult -> {
-            ResponseEvent event = (ResponseEvent) eventResult.event;
-            if (event.getResponse().getRawContent() != null) {
-                // 鎴愬姛
-                logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
-            }else {
-                // 鎴愬姛
-                logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
-            }
-        },eventResult -> {
-            // 澶辫触
-            logger.warn("[鐩綍璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
-        });
-    }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/MobilePositionSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/service/bean/MobilePositionSubscribeTask.java
deleted file mode 100644
index df4bc6c..0000000
--- a/src/main/java/com/genersoft/iot/vmp/service/bean/MobilePositionSubscribeTask.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.genersoft.iot.vmp.service.bean;
-
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
-import org.dom4j.Element;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.sip.ResponseEvent;
-
-public class MobilePositionSubscribeTask implements Runnable{
-    private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
-    private  Device device;
-    private  ISIPCommander sipCommander;
-
-    public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
-        this.device = device;
-        this.sipCommander = sipCommander;
-    }
-
-    @Override
-    public void run() {
-        sipCommander.mobilePositionSubscribe(device, eventResult -> {
-            ResponseEvent event = (ResponseEvent) eventResult.event;
-            Element rootElement = null;
-            if (event.getResponse().getRawContent() != null) {
-                // 鎴愬姛
-                logger.info("[绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
-            }else {
-                // 鎴愬姛
-                logger.info("[绉诲姩浣嶇疆璁㈤槄]鎴愬姛锛� {}", device.getDeviceId());
-            }
-        },eventResult -> {
-            // 澶辫触
-            logger.warn("[绉诲姩浣嶇疆璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
-        });
-    }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
index 384bf7f..e9f7968 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -4,8 +4,8 @@
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
 import com.genersoft.iot.vmp.service.IDeviceService;
-import com.genersoft.iot.vmp.service.bean.CatalogSubscribeTask;
-import com.genersoft.iot.vmp.service.bean.MobilePositionSubscribeTask;
+import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
+import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,7 +42,7 @@
         int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
         // 璁剧疆鏈�灏忓�间负30
         subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
-        dynamicTask.startCron(device.getDeviceId() + "catalog", catalogSubscribeTask, subscribeCycleForCatalog - 5);
+        dynamicTask.startCron(device.getDeviceId() + "catalog", catalogSubscribeTask, subscribeCycleForCatalog);
         return true;
     }
 
@@ -53,8 +53,6 @@
         }
         logger.info("绉婚櫎鐩綍璁㈤槄: {}", device.getDeviceId());
         dynamicTask.stop(device.getDeviceId() + "catalog");
-        device.setSubscribeCycleForCatalog(0);
-        sipCommander.catalogSubscribe(device, null, null);
         return true;
     }
 
@@ -75,7 +73,7 @@
         int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
         // 璁剧疆鏈�灏忓�间负30
         subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
-        dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, subscribeCycleForCatalog - 5);
+        dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, subscribeCycleForCatalog -1 );
         return true;
     }
 
@@ -86,8 +84,6 @@
         }
         logger.info("绉婚櫎绉诲姩浣嶇疆璁㈤槄: {}", device.getDeviceId());
         dynamicTask.stop(device.getDeviceId() + "mobile_position");
-        device.setSubscribeCycleForCatalog(0);
-        sipCommander.mobilePositionSubscribe(device, null, null);
         return true;
     }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
index 365903c..c360843 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
@@ -8,6 +8,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.github.pagehelper.util.StringUtil;
 
@@ -47,6 +48,9 @@
 	
 	@Autowired
 	private DeferredResultHolder resultHolder;
+
+	@Autowired
+	private IDeviceService deviceService;
 
     /**
      *  鏌ヨ鍘嗗彶杞ㄨ抗
@@ -163,7 +167,7 @@
         device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
         storager.updateDevice(device);
         String result = msg;
-        if (cmder.mobilePositionSubscribe(device, null, null)) {
+        if (deviceService.removeMobilePositionSubscribe(device)) {
             result += "锛屾垚鍔�";
         } else {
             result += "锛屽け璐�";
diff --git a/web_src/src/components/dialog/deviceEdit.vue b/web_src/src/components/dialog/deviceEdit.vue
index 1150d21..1b1aba0 100644
--- a/web_src/src/components/dialog/deviceEdit.vue
+++ b/web_src/src/components/dialog/deviceEdit.vue
@@ -10,7 +10,7 @@
       @close="close()"
     >
       <div id="shared" style="margin-top: 1rem;margin-right: 100px;">
-        <el-form ref="form" :rules="rules" :model="form" label-width="240px" >
+        <el-form ref="form" :rules="rules" :model="form" label-width="200px" >
           <el-form-item label="璁惧缂栧彿" >
             <el-input v-model="form.deviceId" disabled></el-input>
           </el-form-item>
@@ -36,13 +36,13 @@
               <el-option key="UTF-8" label="UTF-8" value="utf-8"></el-option>
             </el-select>
           </el-form-item>
-          <el-form-item label="鐩綍璁㈤槄鍛ㄦ湡(0涓哄仠鐢ㄨ闃�)" prop="subscribeCycleForCatalog" >
+          <el-form-item label="鐩綍璁㈤槄" title="0涓哄彇娑堣闃�" prop="subscribeCycleForCatalog" >
             <el-input v-model="form.subscribeCycleForCatalog" clearable ></el-input>
           </el-form-item>
-          <el-form-item label="绉诲姩浣嶇疆璁㈤槄鍛ㄦ湡(0涓哄仠鐢ㄨ闃�)" prop="subscribeCycleForCatalog" >
+          <el-form-item label="绉诲姩浣嶇疆璁㈤槄" title="0涓哄彇娑堣闃�" prop="subscribeCycleForCatalog" >
             <el-input v-model="form.subscribeCycleForMobilePosition" clearable ></el-input>
           </el-form-item>
-          <el-form-item label="绉诲姩浣嶇疆鎶ラ�侀棿闅�" prop="subscribeCycleForCatalog" >
+          <el-form-item v-if="form.subscribeCycleForMobilePosition > 0" label="绉诲姩浣嶇疆鎶ラ�侀棿闅�" prop="subscribeCycleForCatalog" >
             <el-input v-model="form.mobilePositionSubmissionInterval" clearable ></el-input>
           </el-form-item>
           <el-form-item>
@@ -98,6 +98,9 @@
     onSubmit: function () {
       console.log("onSubmit");
       console.log(this.form);
+      this.form.subscribeCycleForCatalog = this.form.subscribeCycleForCatalog||0
+      this.form.subscribeCycleForMobilePosition = this.form.subscribeCycleForMobilePosition||0
+      this.form.mobilePositionSubmissionInterval = this.form.mobilePositionSubmissionInterval||0
       this.$axios({
         method: 'post',
         url:`/api/device/query/device/update/`,

--
Gitblit v1.8.0