设备注册 未完
This commit is contained in:
parent
6bb578d1bd
commit
b5cb55c7ee
@ -1,4 +1,4 @@
|
||||
package cn.skcks.docking.gb28181.core.sip.message.processor.request;
|
||||
package cn.skcks.docking.gb28181.core.sip.message.processor.register.request;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.skcks.docking.gb28181.config.sip.SipConfig;
|
||||
@ -11,10 +11,9 @@ import cn.skcks.docking.gb28181.core.sip.message.processor.MessageProcessor;
|
||||
import cn.skcks.docking.gb28181.core.sip.message.sender.SipMessageSender;
|
||||
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||
import cn.skcks.docking.gb28181.service.docking.DockingDeviceService;
|
||||
import cn.skcks.docking.gb28181.service.docking.device.DockingDeviceService;
|
||||
import gov.nist.javax.sip.address.SipUri;
|
||||
import gov.nist.javax.sip.header.Authorization;
|
||||
import gov.nist.javax.sip.header.SIPDate;
|
||||
import gov.nist.javax.sip.header.SIPDateHeader;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
@ -23,7 +22,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@ -32,12 +30,11 @@ import javax.sip.RequestEvent;
|
||||
import javax.sip.address.Address;
|
||||
import javax.sip.header.ExpiresHeader;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.header.ViaHeader;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ -66,8 +63,8 @@ public class RegisterRequestProcessor implements MessageProcessor {
|
||||
SipUri uri = (SipUri)address.getURI();
|
||||
String deviceId = uri.getUser();
|
||||
log.debug("请求注册 设备id => {}", deviceId);
|
||||
DockingDevice deviceInfo = dockingDeviceService.getDeviceInfo(deviceId);
|
||||
if(deviceInfo == null){
|
||||
DockingDevice device = dockingDeviceService.getDeviceInfo(deviceId);
|
||||
if(device == null){
|
||||
log.info("新注册的设备 deviceId => {}", deviceId);
|
||||
}
|
||||
|
||||
@ -104,38 +101,41 @@ public class RegisterRequestProcessor implements MessageProcessor {
|
||||
}
|
||||
|
||||
|
||||
if (deviceInfo == null) {
|
||||
deviceInfo = new DockingDevice();
|
||||
deviceInfo.setStreamMode(ListeningPoint.UDP);
|
||||
deviceInfo.setCharset("GB2312");
|
||||
deviceInfo.setGeoCoordSys("WGS84");
|
||||
deviceInfo.setDeviceId(deviceId);
|
||||
deviceInfo.setOnLine(false);
|
||||
if (device == null) {
|
||||
device = new DockingDevice();
|
||||
device.setStreamMode(ListeningPoint.UDP);
|
||||
device.setCharset("GB2312");
|
||||
device.setGeoCoordSys("WGS84");
|
||||
device.setDeviceId(deviceId);
|
||||
device.setOnLine(false);
|
||||
} else {
|
||||
if (ObjectUtils.isEmpty(deviceInfo.getStreamMode())) {
|
||||
deviceInfo.setStreamMode(ListeningPoint.UDP);
|
||||
if (ObjectUtils.isEmpty(device.getStreamMode())) {
|
||||
device.setStreamMode(ListeningPoint.UDP);
|
||||
}
|
||||
if (ObjectUtils.isEmpty(deviceInfo.getCharset())) {
|
||||
deviceInfo.setCharset("GB2312");
|
||||
if (ObjectUtils.isEmpty(device.getCharset())) {
|
||||
device.setCharset("GB2312");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(deviceInfo.getGeoCoordSys())) {
|
||||
deviceInfo.setGeoCoordSys("WGS84");
|
||||
if (ObjectUtils.isEmpty(device.getGeoCoordSys())) {
|
||||
device.setGeoCoordSys("WGS84");
|
||||
}
|
||||
}
|
||||
|
||||
deviceInfo.setIp(remoteInfo.getIp());
|
||||
deviceInfo.setPort(remoteInfo.getPort());
|
||||
deviceInfo.setHostAddress(remoteInfo.getIp().concat(":").concat(String.valueOf(remoteInfo.getPort())));
|
||||
deviceInfo.setLocalIp(senderIp);
|
||||
device.setIp(remoteInfo.getIp());
|
||||
device.setPort(remoteInfo.getPort());
|
||||
device.setHostAddress(remoteInfo.getIp().concat(":").concat(String.valueOf(remoteInfo.getPort())));
|
||||
device.setLocalIp(senderIp);
|
||||
ViaHeader viaHeader = request.getTopmostViaHeader();
|
||||
String transport = viaHeader.getTransport();
|
||||
device.setTransport(ListeningPoint.TCP.equalsIgnoreCase(transport) ? ListeningPoint.TCP : ListeningPoint.UDP);
|
||||
|
||||
int expires = request.getExpires().getExpires();
|
||||
deviceInfo.setExpires(expires);
|
||||
device.setExpires(expires);
|
||||
// expires == 0 时 注销
|
||||
if (expires == 0) {
|
||||
log.info("设备注销 deviceId => {}", deviceId);
|
||||
} else {
|
||||
deviceInfo.setRegisterTime(DateUtil.now());
|
||||
SipTransactionInfo sipTransactionInfo = new SipTransactionInfo((SIPResponse)response);
|
||||
device.setRegisterTime(DateUtil.now());
|
||||
dockingDeviceService.online(device);
|
||||
}
|
||||
|
||||
sender.send(senderIp, response);
|
@ -1,23 +0,0 @@
|
||||
package cn.skcks.docking.gb28181.service.docking;
|
||||
|
||||
import cn.skcks.docking.gb28181.common.redis.RedisUtil;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.mapper.DockingDeviceDynamicSqlSupport;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.mapper.DockingDeviceMapper;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class DockingDeviceService {
|
||||
private final DockingDeviceMapper dockingDeviceMapper;
|
||||
|
||||
public DockingDevice getDeviceInfo(String deviceId){
|
||||
return dockingDeviceMapper.selectOne((s -> {
|
||||
return s.where(DockingDeviceDynamicSqlSupport.deviceId, SqlBuilder.isEqualTo(deviceId));
|
||||
})).orElse(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package cn.skcks.docking.gb28181.service.docking.device;
|
||||
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.mapper.DockingDeviceDynamicSqlSupport;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.mapper.DockingDeviceMapper;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||
import cn.skcks.docking.gb28181.service.docking.device.cache.DockingDeviceCacheService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DockingDeviceService {
|
||||
private final DockingDeviceMapper dockingDeviceMapper;
|
||||
private final DockingDeviceCacheService deviceCacheService;
|
||||
|
||||
public DockingDevice getDeviceInfo(String deviceId) {
|
||||
DockingDevice device = deviceCacheService.getDeviceInfo(deviceId);
|
||||
if (device == null) {
|
||||
device = dockingDeviceMapper
|
||||
.selectOne((s -> s.where(DockingDeviceDynamicSqlSupport.deviceId, SqlBuilder.isEqualTo(deviceId))))
|
||||
.orElse(null);
|
||||
if (device != null) {
|
||||
deviceCacheService.cacheDeviceInfo(deviceId, device);
|
||||
}
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
public void online(DockingDevice device) {
|
||||
String deviceId = device.getDeviceId();
|
||||
log.info("[设备上线] deviceId => {}, {}://{}:{}", deviceId, device.getTransport(), device.getIp(), device.getPort());
|
||||
dockingDeviceMapper.insert(device);
|
||||
deviceCacheService.cacheDeviceInfo(deviceId, device);
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package cn.skcks.docking.gb28181.service.cache;
|
||||
package cn.skcks.docking.gb28181.service.docking.device.cache;
|
||||
|
||||
import cn.skcks.docking.gb28181.common.json.JsonUtils;
|
||||
import cn.skcks.docking.gb28181.common.redis.RedisUtil;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||
import cn.skcks.docking.gb28181.service.docking.DockingDeviceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -13,19 +12,19 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class DockingDeviceCacheService {
|
||||
private final DockingDeviceService dockingDeviceService;
|
||||
public static final String PREFIX = "DockingDevice";
|
||||
|
||||
public DockingDevice getDeviceInfo(String deviceId) {
|
||||
String key = StringUtils.joinWith(":", PREFIX, deviceId);
|
||||
String json = RedisUtil.StringOps.get(key);
|
||||
if (json == null){
|
||||
DockingDevice device = dockingDeviceService.getDeviceInfo(deviceId);
|
||||
if(device != null){
|
||||
RedisUtil.StringOps.set(key, JsonUtils.toCompressJson(device));
|
||||
}
|
||||
return device;
|
||||
return null;
|
||||
}
|
||||
return JsonUtils.parse(json, DockingDevice.class);
|
||||
}
|
||||
|
||||
public void cacheDeviceInfo(String deviceId,DockingDevice device) {
|
||||
String key = StringUtils.joinWith(":", PREFIX, deviceId);
|
||||
RedisUtil.StringOps.set(key,JsonUtils.toCompressJson(device));
|
||||
}
|
||||
}
|
@ -5,6 +5,19 @@ project:
|
||||
version: @project.version@
|
||||
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
# [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1
|
||||
# host: 192.168.1.241
|
||||
host: 10.10.10.200
|
||||
# [必须修改] 端口号
|
||||
port: 16379
|
||||
# [可选] 数据库 DB
|
||||
database: 10
|
||||
# [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
|
||||
password: 12341234
|
||||
# [可选] 超时时间
|
||||
timeout: 10000
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
Loading…
Reference in New Issue
Block a user