From 5cd3e0e919d427c68d2e21be20f27af9b24622b0 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 16 三月 2023 09:32:21 +0800
Subject: [PATCH] 更新前后端分离部署文档
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java | 85 ++++++++++++++++++++++++------------------
1 files changed, 48 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
index 63dc7d8..b6c27ab 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
@@ -1,28 +1,28 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
+import com.genersoft.iot.vmp.common.VideoManagerConstants;
+import com.genersoft.iot.vmp.conf.DynamicTask;
+import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
+import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
+import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.service.IDeviceService;
-import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
+import gov.nist.javax.sip.message.SIPRequest;
import org.dom4j.Element;
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 org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
import javax.sip.SipException;
-import javax.sip.header.ViaHeader;
import javax.sip.message.Response;
import java.text.ParseException;
@@ -32,6 +32,7 @@
@Component
public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
+
private Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
private final static String cmdType = "Keepalive";
@@ -40,6 +41,12 @@
@Autowired
private IDeviceService deviceService;
+
+ @Autowired
+ private UserSetting userSetting;
+
+ @Autowired
+ private DynamicTask dynamicTask;
@Override
public void afterPropertiesSet() throws Exception {
@@ -52,39 +59,43 @@
// 鏈敞鍐岀殑璁惧涓嶅仛澶勭悊
return;
}
+ SIPRequest request = (SIPRequest) evt.getRequest();
+ // 鍥炲200 OK
try {
- // 鍒ゆ柇RPort鏄惁鏀瑰彉锛屾敼鍙樺垯璇存槑璺敱nat淇℃伅鍙樺寲锛屼慨鏀硅澶囦俊鎭�
- // 鑾峰彇鍒伴�氫俊鍦板潃绛変俊鎭�
- ViaHeader viaHeader = (ViaHeader) evt.getRequest().getHeader(ViaHeader.NAME);
- String received = viaHeader.getReceived();
- int rPort = viaHeader.getRPort();
- // 瑙f瀽鏈湴鍦板潃鏇夸唬
- if (ObjectUtils.isEmpty(received) || rPort == -1) {
- received = viaHeader.getHost();
- rPort = viaHeader.getPort();
- }
- if (device.getPort() != rPort) {
- device.setPort(rPort);
- device.setHostAddress(received.concat(":").concat(String.valueOf(rPort)));
- }
- device.setKeepaliveTime(DateUtil.getNow());
- // 鍥炲200 OK
- responseAck(getServerTransaction(evt), Response.OK);
- if (device.getOnline() == 1) {
- deviceService.updateDevice(device);
- }else {
- // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
- if (!deviceService.expire(device)){
- deviceService.online(device);
- }
- }
- } catch (SipException e) {
- e.printStackTrace();
- } catch (InvalidArgumentException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
+ responseAck(request, Response.OK);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 蹇冭烦鍥炲: {}", e.getMessage());
}
+
+ RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress());
+ if (!device.getIp().equalsIgnoreCase(remoteAddressInfo.getIp()) || device.getPort() != remoteAddressInfo.getPort()) {
+ device.setPort(remoteAddressInfo.getPort());
+ device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));
+ device.setIp(remoteAddressInfo.getIp());
+ }
+ if (device.getKeepaliveTime() == null) {
+ device.setKeepaliveIntervalTime(60);
+ }else {
+ long lastTime = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(device.getKeepaliveTime());
+ device.setKeepaliveIntervalTime(new Long(System.currentTimeMillis()/1000-lastTime).intValue());
+ }
+
+ device.setKeepaliveTime(DateUtil.getNow());
+
+ if (device.getOnline() == 1) {
+ deviceService.updateDevice(device);
+ }else {
+ // 瀵逛簬宸茬粡绂荤嚎鐨勮澶囧垽鏂粬鐨勬敞鍐屾槸鍚﹀凡缁忚繃鏈�
+ if (!deviceService.expire(device)){
+ device.setOnline(0);
+ deviceService.online(device);
+ }
+ }
+ // 鍒锋柊杩囨湡浠诲姟
+ String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
+ // 濡傛灉涓夋蹇冭烦澶辫触锛屽垯璁剧疆璁惧绂荤嚎
+ dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId(), "涓夋蹇冭烦澶辫触"), device.getKeepaliveIntervalTime()*1000*3);
+
}
@Override
--
Gitblit v1.8.0