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/event/device/RequestTimeoutEventImpl.java |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/device/RequestTimeoutEventImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/device/RequestTimeoutEventImpl.java
new file mode 100644
index 0000000..bffa4cb
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/device/RequestTimeoutEventImpl.java
@@ -0,0 +1,42 @@
+package com.genersoft.iot.vmp.gb28181.event.device;
+
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
+import com.genersoft.iot.vmp.service.IDeviceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import javax.sip.ClientTransaction;
+import javax.sip.address.SipURI;
+import javax.sip.header.CallIdHeader;
+import javax.sip.header.ToHeader;
+import javax.sip.message.Request;
+
+/**
+ * @author lin
+ */
+@Component
+public class RequestTimeoutEventImpl implements ApplicationListener<RequestTimeoutEvent> {
+
+    @Autowired
+    private IDeviceService deviceService;
+
+    @Override
+    public void onApplicationEvent(RequestTimeoutEvent event) {
+        ClientTransaction clientTransaction = event.getTimeoutEvent().getClientTransaction();
+        if (clientTransaction != null) {
+            Request request = clientTransaction.getRequest();
+            if (request != null) {
+                String host = ((SipURI) request.getRequestURI()).getHost();
+                int port = ((SipURI) request.getRequestURI()).getPort();
+                Device device = deviceService.getDeviceByHostAndPort(host, port);
+                if (device == null) {
+                    return;
+                }
+                deviceService.offline(device.getDeviceId());
+            }
+
+        }
+    }
+}

--
Gitblit v1.8.0