From 2b1f7a47394363e95deb4dfa0f1c67d41e747f7f Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 01 二月 2023 10:56:40 +0800 Subject: [PATCH] Merge branch 'wvp-28181-2.0' into fix-269 --- src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 105 insertions(+), 0 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 new file mode 100644 index 0000000..39dff93 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java @@ -0,0 +1,105 @@ +package com.genersoft.iot.vmp.gb28181.task.impl; + +import com.genersoft.iot.vmp.conf.DynamicTask; +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; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import javax.sip.*; +import javax.sip.header.ToHeader; +import java.text.ParseException; +import java.util.Timer; +import java.util.TimerTask; + +/** + * 鐩綍璁㈤槄浠诲姟 + * @author lin + */ +public class CatalogSubscribeTask implements ISubscribeTask { + private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class); + private Device device; + private final ISIPCommander sipCommander; + private SIPRequest request; + + private DynamicTask dynamicTask; + + private String taskKey = "catalog-subscribe-timeout"; + + + public CatalogSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) { + this.device = device; + this.sipCommander = sipCommander; + this.dynamicTask = dynamicTask; + } + + @Override + public void run() { + if (dynamicTask.get(taskKey) != null) { + dynamicTask.stop(taskKey); + } + SIPRequest sipRequest = null; + try { + sipRequest = sipCommander.catalogSubscribe(device, request, eventResult -> { + ResponseEvent event = (ResponseEvent) eventResult.event; + // 鎴愬姛 + 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 -> { + this.request = null; + // 澶辫触 + logger.warn("[鐩綍璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg); + dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000); + }); + } catch (InvalidArgumentException | SipException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 鐩綍璁㈤槄: {}", e.getMessage()); + + } + if (sipRequest != null) { + this.request = sipRequest; + } + } + + @Override + public void stop() { + /** + * dialog 鐨勫悇涓姸鎬� + * EARLY-> Early state鐘舵��-鍒濆璇锋眰鍙戦�佷互鍚庯紝鏀跺埌浜嗕竴涓复鏃跺搷搴旀秷鎭� + * CONFIRMED-> Confirmed Dialog鐘舵��-宸茬‘璁� + * COMPLETED-> Completed Dialog鐘舵��-宸插畬鎴� + * TERMINATED-> Terminated Dialog鐘舵��-缁堟 + */ + logger.info("鍙栨秷鐩綍璁㈤槄鏃禿ialog鐘舵�佷负{}", DialogState.CONFIRMED); + if (dynamicTask.get(taskKey) != null) { + dynamicTask.stop(taskKey); + } + device.setSubscribeCycleForCatalog(0); + try { + 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); + }); + } catch (InvalidArgumentException | SipException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 鍙栨秷鐩綍璁㈤槄璁㈤槄: {}", e.getMessage()); + } + } +} -- Gitblit v1.8.0