From d7a1b94f905c5f28c9c8f2d48c3f9e28ebcf9cc4 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期六, 24 九月 2022 21:04:58 +0800 Subject: [PATCH] Merge branch 'wvp-28181-2.0' --- src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java | 67 +++++++++++++++------------------ 1 files changed, 31 insertions(+), 36 deletions(-) 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 index 577e724..bfa900a 100644 --- 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 @@ -4,6 +4,7 @@ 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 gov.nist.javax.sip.message.SIPRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Async; @@ -12,6 +13,8 @@ import javax.sip.Dialog; import javax.sip.DialogState; import javax.sip.ResponseEvent; +import javax.sip.header.ToHeader; +import java.text.ParseException; import java.util.Timer; import java.util.TimerTask; @@ -23,7 +26,7 @@ private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class); private Device device; private final ISIPCommander sipCommander; - private Dialog dialog; + private SIPRequest request; private DynamicTask dynamicTask; @@ -41,24 +44,26 @@ if (dynamicTask.get(taskKey) != null) { dynamicTask.stop(taskKey); } - sipCommander.catalogSubscribe(device, dialog, eventResult -> { - if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { - dialog = eventResult.dialog; - } + SIPRequest sipRequest = sipCommander.catalogSubscribe(device, request, eventResult -> { ResponseEvent event = (ResponseEvent) eventResult.event; - if (event.getResponse().getRawContent() != null) { - // 鎴愬姛 - logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId()); - }else { - // 鎴愬姛 - logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId()); + // 鎴愬姛 + logger.info("[鐩綍璁㈤槄]鎴愬姛锛� {}", device.getDeviceId()); + ToHeader toHeader = (ToHeader)event.getResponse().getHeader(ToHeader.NAME); + try { + this.request.getToHeader().setTag(toHeader.getTag()); + } catch (ParseException e) { + logger.info("[鐩綍璁㈤槄]鎴愬姛锛� 浣嗕负request璁剧疆ToTag澶辫触"); + this.request = null; } },eventResult -> { - dialog = null; + this.request = null; // 澶辫触 logger.warn("[鐩綍璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg); dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000); }); + if (sipRequest != null) { + this.request = sipRequest; + } } @Override @@ -74,29 +79,19 @@ if (dynamicTask.get(taskKey) != null) { dynamicTask.stop(taskKey); } - if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { - device.setSubscribeCycleForCatalog(0); - sipCommander.catalogSubscribe(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); - }); - } - } - - @Override - public DialogState getDialogState() { - if (dialog == null) { - return null; - } - return dialog.getState(); + device.setSubscribeCycleForCatalog(0); + sipCommander.catalogSubscribe(device, request, 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); + }); } } -- Gitblit v1.8.0