Commit 4418c62e5c4ef2c116cfaa2346011b011c7338f7

Authored by 648540858
1 parent 01519c25

#239

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
... ... @@ -7,16 +7,22 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
7 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
8 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
9 9 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
  10 +import com.genersoft.iot.vmp.service.IDeviceService;
  11 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  12 +import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
10 13 import org.dom4j.Element;
11 14 import org.slf4j.Logger;
12 15 import org.slf4j.LoggerFactory;
13 16 import org.springframework.beans.factory.InitializingBean;
14 17 import org.springframework.beans.factory.annotation.Autowired;
15 18 import org.springframework.stereotype.Component;
  19 +import org.springframework.util.StringUtils;
  20 +import springfox.documentation.service.Header;
16 21  
17 22 import javax.sip.InvalidArgumentException;
18 23 import javax.sip.RequestEvent;
19 24 import javax.sip.SipException;
  25 +import javax.sip.header.ViaHeader;
20 26 import javax.sip.message.Response;
21 27 import java.text.ParseException;
22 28  
... ... @@ -32,6 +38,12 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
32 38 @Autowired
33 39 private EventPublisher publisher;
34 40  
  41 + @Autowired
  42 + private IVideoManagerStorager videoManagerStorager;
  43 +
  44 + @Autowired
  45 + private IRedisCatchStorage redisCatchStorage;
  46 +
35 47 @Override
36 48 public void afterPropertiesSet() throws Exception {
37 49 notifyMessageHandler.addHandler(cmdType, this);
... ... @@ -44,6 +56,21 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
44 56 if (device != null ) {
45 57 // 回复200 OK
46 58 responseAck(evt, Response.OK);
  59 + // 判断RPort是否改变,改变则说明路由nat信息变化,修改设备信息
  60 + // 获取到通信地址等信息
  61 + ViaHeader viaHeader = (ViaHeader) evt.getRequest().getHeader(ViaHeader.NAME);
  62 + String received = viaHeader.getReceived();
  63 + int rPort = viaHeader.getRPort();
  64 + // 解析本地地址替代
  65 + if (StringUtils.isEmpty(received) || rPort == -1) {
  66 + received = viaHeader.getHost();
  67 + rPort = viaHeader.getPort();
  68 + }
  69 + if (device.getPort() != rPort) {
  70 + device.setPort(rPort);
  71 + videoManagerStorager.updateDevice(device);
  72 + redisCatchStorage.updateDevice(device);
  73 + }
47 74 publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
48 75 }
49 76 } catch (SipException e) {
... ...