优化sip消息,去除自动dialog创建
This commit is contained in:
parent
1ee56d50d8
commit
710600db6f
@ -64,8 +64,8 @@ public class MediaConfig{
|
||||
@Value("${media.secret}")
|
||||
private String secret;
|
||||
|
||||
@Value("${media.stream-none-reader-delay-ms:10000}")
|
||||
private int streamNoneReaderDelayMS = 10000;
|
||||
@Value("${media.stream-none-reader-delay-ms:15000}")
|
||||
private int streamNoneReaderDelayMS = 15000;
|
||||
|
||||
@Value("${media.rtp.enable}")
|
||||
private boolean rtpEnable;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.conf.DefaultProperties;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
@ -41,43 +42,7 @@ public class SipLayer{
|
||||
@Bean("sipStack")
|
||||
@DependsOn({"sipFactory"})
|
||||
SipStack createSipStack() throws PeerUnavailableException {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
|
||||
properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getMonitorIp());
|
||||
/**
|
||||
* 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码
|
||||
* gov/nist/javax/sip/SipStackImpl.class
|
||||
* sip消息的解析在 gov.nist.javax.sip.stack.UDPMessageChannel的processIncomingDataPacket方法
|
||||
*/
|
||||
|
||||
// * gov/nist/javax/sip/SipStackImpl.class
|
||||
if (logger.isDebugEnabled()) {
|
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
|
||||
}
|
||||
// 接收所有notify请求,即使没有订阅
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
|
||||
properties.setProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING", "false");
|
||||
properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
|
||||
// 为_NULL _对话框传递_终止的_事件
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_NULL_DIALOG", "true");
|
||||
// 会话清理策略
|
||||
properties.setProperty("gov.nist.javax.sip.RELEASE_REFERENCES_STRATEGY", "Normal");
|
||||
// 处理由该服务器处理的基于底层TCP的保持生存超时
|
||||
properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60");
|
||||
// 获取实际内容长度,不使用header中的长度信息
|
||||
properties.setProperty("gov.nist.javax.sip.COMPUTE_CONTENT_LENGTH_FROM_MESSAGE_BODY", "true");
|
||||
|
||||
/**
|
||||
* sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE
|
||||
*/
|
||||
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR");
|
||||
// properties.setProperty("gov.nist.javax.sip.SIP_MESSAGE_VALVE", "com.genersoft.iot.vmp.gb28181.session.SipMessagePreprocessing");
|
||||
// if (logger.isDebugEnabled()) {
|
||||
// properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");
|
||||
// }
|
||||
|
||||
sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
|
||||
|
||||
sipStack = ( SipStackImpl )sipFactory.createSipStack(DefaultProperties.getProperties(sipConfig.getMonitorIp(), false));
|
||||
return sipStack;
|
||||
}
|
||||
|
||||
|
@ -380,4 +380,5 @@ public class Device {
|
||||
public void setTreeType(String treeType) {
|
||||
this.treeType = treeType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
|
||||
public class SendRtpItem {
|
||||
|
||||
/**
|
||||
@ -77,10 +79,20 @@ public class SendRtpItem {
|
||||
private String serverId;
|
||||
|
||||
/**
|
||||
* invite的callId
|
||||
* invite 的 callId
|
||||
*/
|
||||
private String CallId;
|
||||
|
||||
/**
|
||||
* invite 的 fromTag
|
||||
*/
|
||||
private String fromTag;
|
||||
|
||||
/**
|
||||
* invite 的 toTag
|
||||
*/
|
||||
private String toTag;
|
||||
|
||||
/**
|
||||
* 发送时,rtp的pt(uint8_t),不传时默认为96
|
||||
*/
|
||||
@ -96,15 +108,12 @@ public class SendRtpItem {
|
||||
*/
|
||||
private boolean onlyAudio = false;
|
||||
|
||||
|
||||
/**
|
||||
* 播放类型
|
||||
*/
|
||||
private InviteStreamType playType;
|
||||
|
||||
private byte[] transaction;
|
||||
|
||||
private byte[] dialog;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
@ -225,22 +234,6 @@ public class SendRtpItem {
|
||||
this.playType = playType;
|
||||
}
|
||||
|
||||
public byte[] getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public void setTransaction(byte[] transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public byte[] getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setDialog(byte[] dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
public int getPt() {
|
||||
return pt;
|
||||
}
|
||||
@ -272,4 +265,20 @@ public class SendRtpItem {
|
||||
public void setServerId(String serverId) {
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public String getFromTag() {
|
||||
return fromTag;
|
||||
}
|
||||
|
||||
public void setFromTag(String fromTag) {
|
||||
this.fromTag = fromTag;
|
||||
}
|
||||
|
||||
public String getToTag() {
|
||||
return toTag;
|
||||
}
|
||||
|
||||
public void setToTag(String toTag) {
|
||||
this.toTag = toTag;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeHandlerTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.IPlatformService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -23,15 +24,6 @@ public class SubscribeHolder {
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform sipCommanderForPlatform;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
private final String taskOverduePrefix = "subscribe_overdue_";
|
||||
|
||||
private static ConcurrentHashMap<String, SubscribeInfo> catalogMap = new ConcurrentHashMap<>();
|
||||
@ -62,15 +54,13 @@ public class SubscribeHolder {
|
||||
}
|
||||
// 添加任务处理订阅过期
|
||||
dynamicTask.stop(taskOverdueKey);
|
||||
|
||||
}
|
||||
|
||||
public void putMobilePositionSubscribe(String platformId, SubscribeInfo subscribeInfo) {
|
||||
mobilePositionMap.put(platformId, subscribeInfo);
|
||||
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + "MobilePosition_" + platformId;
|
||||
// 添加任务处理GPS定时推送
|
||||
dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform,
|
||||
storager, platformId, subscribeInfo.getSn(), key, this, dynamicTask),
|
||||
dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(platformId),
|
||||
subscribeInfo.getGpsInterval() * 1000);
|
||||
String taskOverdueKey = taskOverduePrefix + "MobilePosition_" + platformId;
|
||||
// 添加任务处理订阅过期
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.utils.SerializeUtils;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
|
||||
import javax.sip.ClientTransaction;
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
@ -11,30 +14,24 @@ import javax.sip.message.Request;
|
||||
public class SubscribeInfo {
|
||||
|
||||
|
||||
public SubscribeInfo(RequestEvent evt, String id) {
|
||||
public SubscribeInfo(ServerTransaction serverTransaction, String id) {
|
||||
this.id = id;
|
||||
Request request = evt.getRequest();
|
||||
ExpiresHeader expiresHeader = (ExpiresHeader)request.getHeader(ExpiresHeader.NAME);
|
||||
this.expires = expiresHeader.getExpires();
|
||||
SIPRequest request = (SIPRequest)serverTransaction.getRequest();
|
||||
this.request = request;
|
||||
this.expires = request.getExpires().getExpires();
|
||||
EventHeader eventHeader = (EventHeader)request.getHeader(EventHeader.NAME);
|
||||
this.eventId = eventHeader.getEventId();
|
||||
this.eventType = eventHeader.getEventType();
|
||||
this.transaction = evt.getServerTransaction();
|
||||
this.dialog = evt.getDialog();
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
this.callId = callIdHeader.getCallId();
|
||||
}
|
||||
|
||||
public SubscribeInfo() {
|
||||
}
|
||||
|
||||
private String id;
|
||||
|
||||
private SIPRequest request;
|
||||
private int expires;
|
||||
private String callId;
|
||||
private String eventId;
|
||||
private String eventType;
|
||||
private ServerTransaction transaction;
|
||||
private Dialog dialog;
|
||||
private SIPResponse response;
|
||||
|
||||
/**
|
||||
* 以下为可选字段
|
||||
@ -43,29 +40,28 @@ public class SubscribeInfo {
|
||||
private String sn;
|
||||
private int gpsInterval;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
public String getCallId() {
|
||||
return callId;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setExpires(int expires) {
|
||||
this.expires = expires;
|
||||
public SIPRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public void setCallId(String callId) {
|
||||
this.callId = callId;
|
||||
public void setRequest(SIPRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public int getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
public void setExpires(int expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
public String getEventId() {
|
||||
@ -84,20 +80,12 @@ public class SubscribeInfo {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public ServerTransaction getTransaction() {
|
||||
return transaction;
|
||||
public SIPResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setTransaction(ServerTransaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public Dialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setDialog(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
public void setResponse(SIPResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public String getSn() {
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.genersoft.iot.vmp.gb28181.conf;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 获取sip默认配置
|
||||
* @author lin
|
||||
*/
|
||||
public class DefaultProperties {
|
||||
|
||||
public static Properties getProperties(String ip, boolean isDebug) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
|
||||
properties.setProperty("javax.sip.IP_ADDRESS", ip);
|
||||
properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "off");
|
||||
/**
|
||||
* 完整配置参考 gov.nist.javax.sip.SipStackImpl,需要下载源码
|
||||
* gov/nist/javax/sip/SipStackImpl.class
|
||||
* sip消息的解析在 gov.nist.javax.sip.stack.UDPMessageChannel的processIncomingDataPacket方法
|
||||
*/
|
||||
|
||||
// * gov/nist/javax/sip/SipStackImpl.class
|
||||
if (isDebug) {
|
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
|
||||
}
|
||||
// 接收所有notify请求,即使没有订阅
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
|
||||
properties.setProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING", "false");
|
||||
properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
|
||||
// 为_NULL _对话框传递_终止的_事件
|
||||
properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_NULL_DIALOG", "true");
|
||||
// 会话清理策略
|
||||
properties.setProperty("gov.nist.javax.sip.RELEASE_REFERENCES_STRATEGY", "Normal");
|
||||
// 处理由该服务器处理的基于底层TCP的保持生存超时
|
||||
properties.setProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "60");
|
||||
// 获取实际内容长度,不使用header中的长度信息
|
||||
properties.setProperty("gov.nist.javax.sip.COMPUTE_CONTENT_LENGTH_FROM_MESSAGE_BODY", "true");
|
||||
|
||||
/**
|
||||
* sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE
|
||||
*/
|
||||
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR");
|
||||
|
||||
return properties;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@ -104,22 +105,27 @@ public class SipSubscribe {
|
||||
this.type = EventResultType.timeout;
|
||||
this.msg = "消息超时未回复";
|
||||
this.statusCode = -1024;
|
||||
this.dialog = timeoutEvent.getClientTransaction().getDialog();
|
||||
this.callId = this.dialog != null?timeoutEvent.getClientTransaction().getDialog().getCallId().getCallId(): null;
|
||||
if (timeoutEvent.isServerTransaction()) {
|
||||
this.callId = ((SIPRequest)timeoutEvent.getServerTransaction().getRequest()).getCallIdHeader().getCallId();
|
||||
}else {
|
||||
this.callId = ((SIPRequest)timeoutEvent.getClientTransaction().getRequest()).getCallIdHeader().getCallId();
|
||||
}
|
||||
}else if (event instanceof TransactionTerminatedEvent) {
|
||||
TransactionTerminatedEvent transactionTerminatedEvent = (TransactionTerminatedEvent)event;
|
||||
this.type = EventResultType.transactionTerminated;
|
||||
this.msg = "事务已结束";
|
||||
this.statusCode = -1024;
|
||||
this.callId = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId().getCallId();
|
||||
this.dialog = transactionTerminatedEvent.getClientTransaction().getDialog();
|
||||
if (transactionTerminatedEvent.isServerTransaction()) {
|
||||
this.callId = ((SIPRequest)transactionTerminatedEvent.getServerTransaction().getRequest()).getCallIdHeader().getCallId();
|
||||
}else {
|
||||
this.callId = ((SIPRequest)transactionTerminatedEvent.getClientTransaction().getRequest()).getCallIdHeader().getCallId();
|
||||
}
|
||||
}else if (event instanceof DialogTerminatedEvent) {
|
||||
DialogTerminatedEvent dialogTerminatedEvent = (DialogTerminatedEvent)event;
|
||||
this.type = EventResultType.dialogTerminated;
|
||||
this.msg = "会话已结束";
|
||||
this.statusCode = -1024;
|
||||
this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId();
|
||||
this.dialog = dialogTerminatedEvent.getDialog();
|
||||
}else if (event instanceof DeviceNotFoundEvent) {
|
||||
DeviceNotFoundEvent deviceNotFoundEvent = (DeviceNotFoundEvent)event;
|
||||
this.type = EventResultType.deviceNotFoundEvent;
|
||||
|
@ -7,6 +7,4 @@ import javax.sip.DialogState;
|
||||
*/
|
||||
public interface ISubscribeTask extends Runnable{
|
||||
void stop();
|
||||
|
||||
DialogState getDialogState();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ 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;
|
||||
@ -12,6 +13,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.header.ToHeader;
|
||||
import java.text.ParseException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@ -23,7 +26,7 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
|
||||
private Device device;
|
||||
private final ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
private SIPRequest request;
|
||||
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@ -41,24 +44,26 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
dialog = eventResult.dialog;
|
||||
}
|
||||
SIPRequest sipRequest = sipCommander.catalogSubscribe(device, request, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[目录订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
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 -> {
|
||||
dialog = null;
|
||||
this.request = null;
|
||||
// 失败
|
||||
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000);
|
||||
});
|
||||
if (sipRequest != null) {
|
||||
this.request = sipRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,9 +79,8 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
sipCommander.catalogSubscribe(device, request, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
@ -90,13 +94,4 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
logger.warn("[取消目录订阅订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogState getDialogState() {
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getState();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,11 @@ import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.IPlatformService;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -20,71 +22,23 @@ import java.util.List;
|
||||
*/
|
||||
public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeHandlerTask.class);
|
||||
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
private IVideoManagerStorage storager;
|
||||
private ISIPCommanderForPlatform sipCommanderForPlatform;
|
||||
private SubscribeHolder subscribeHolder;
|
||||
private ParentPlatform platform;
|
||||
private IPlatformService platformService;
|
||||
private String platformId;
|
||||
|
||||
private String sn;
|
||||
private String key;
|
||||
|
||||
public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage,
|
||||
ISIPCommanderForPlatform sipCommanderForPlatform,
|
||||
IVideoManagerStorage storager,
|
||||
String platformId,
|
||||
String sn,
|
||||
String key,
|
||||
SubscribeHolder subscribeInfo,
|
||||
DynamicTask dynamicTask) {
|
||||
this.redisCatchStorage = redisCatchStorage;
|
||||
this.storager = storager;
|
||||
this.platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
this.sn = sn;
|
||||
this.key = key;
|
||||
this.sipCommanderForPlatform = sipCommanderForPlatform;
|
||||
this.subscribeHolder = subscribeInfo;
|
||||
public MobilePositionSubscribeHandlerTask(String platformId) {
|
||||
this.platformService = SpringBeanFactory.getBean("platformServiceImpl");
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
|
||||
if (subscribe != null) {
|
||||
|
||||
// TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
|
||||
List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId());
|
||||
if (gbStreams.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (DeviceChannel deviceChannel : gbStreams) {
|
||||
String gbId = deviceChannel.getChannelId();
|
||||
GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
|
||||
// 无最新位置不发送
|
||||
if (gpsMsgInfo != null) {
|
||||
// 经纬度都为0不发送
|
||||
if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
|
||||
continue;
|
||||
}
|
||||
// 发送GPS消息
|
||||
sipCommanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe);
|
||||
}
|
||||
}
|
||||
}
|
||||
platformService.sendNotifyMobilePosition(this.platformId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogState getDialogState() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ 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 gov.nist.javax.sip.message.SIPResponse;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -12,6 +14,8 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.header.ToHeader;
|
||||
import java.text.ParseException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@ -23,7 +27,8 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
|
||||
private Device device;
|
||||
private ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
|
||||
private SIPRequest request;
|
||||
private DynamicTask dynamicTask;
|
||||
private String taskKey = "mobile-position-subscribe-timeout";
|
||||
|
||||
@ -38,24 +43,26 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
dialog = eventResult.dialog;
|
||||
}
|
||||
SIPRequest sipRequest = sipCommander.mobilePositionSubscribe(device, request, eventResult -> {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
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 -> {
|
||||
dialog = null;
|
||||
this.request = null;
|
||||
// 失败
|
||||
logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
dynamicTask.startDelay(taskKey, MobilePositionSubscribeTask.this, 2000);
|
||||
});
|
||||
if (sipRequest != null) {
|
||||
this.request = sipRequest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -71,10 +78,8 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
logger.info("取消移动订阅时dialog状态为{}", dialog.getState());
|
||||
device.setSubscribeCycleForMobilePosition(0);
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
|
||||
sipCommander.mobilePositionSubscribe(device, request, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
@ -88,12 +93,4 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
logger.warn("[取消移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public DialogState getDialogState() {
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getState();
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
@Async("taskExecutor")
|
||||
public void processRequest(RequestEvent requestEvent) {
|
||||
String method = requestEvent.getRequest().getMethod();
|
||||
if ("NOTIFY".equalsIgnoreCase(requestEvent.getRequest().getMethod())) {
|
||||
System.out.println();
|
||||
}
|
||||
ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);
|
||||
if (sipRequestProcessor == null) {
|
||||
logger.warn("不支持方法{}的request", method);
|
||||
@ -173,6 +170,12 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
|
||||
@Override
|
||||
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
|
||||
// if (transactionTerminatedEvent.isServerTransaction()) {
|
||||
// ServerTransaction serverTransaction = transactionTerminatedEvent.getServerTransaction();
|
||||
// serverTransaction.get
|
||||
// }
|
||||
|
||||
|
||||
// Transaction transaction = null;
|
||||
// System.out.println("processTransactionTerminated");
|
||||
// if (transactionTerminatedEvent.isServerTransaction()) {
|
||||
|
@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
|
||||
import javax.sip.Dialog;
|
||||
|
||||
@ -313,7 +314,7 @@ public interface ISIPCommander {
|
||||
* @param device 视频设备
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent , SipSubscribe.Event errorEvent);
|
||||
SIPRequest mobilePositionSubscribe(Device device, SIPRequest request, SipSubscribe.Event okEvent , SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 订阅、取消订阅报警信息
|
||||
@ -333,7 +334,7 @@ public interface ISIPCommander {
|
||||
* @param device 视频设备
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
|
||||
SIPRequest catalogSubscribe(Device device, SIPRequest request, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 拉框控制命令
|
||||
|
@ -117,4 +117,5 @@ public interface ISIPCommanderForPlatform {
|
||||
* @param callId callId
|
||||
*/
|
||||
void streamByeCmd(ParentPlatform platform, String callId);
|
||||
void streamByeCmd(ParentPlatform platform, SendRtpItem sendRtpItem);
|
||||
}
|
||||
|
@ -2,10 +2,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.utils.GitUtil;
|
||||
import gov.nist.javax.sip.message.MessageFactoryImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.DigestUtils;
|
||||
@ -154,8 +157,17 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
return registerRequest;
|
||||
}
|
||||
|
||||
public Request createMessageRequest(ParentPlatform parentPlatform, String content, SendRtpItem sendRtpItem) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(sendRtpItem.getCallId());
|
||||
return createMessageRequest(parentPlatform, content, sendRtpItem.getToTag(), SipUtils.getNewViaTag(), sendRtpItem.getFromTag(), callIdHeader);
|
||||
}
|
||||
|
||||
public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String viaTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
return createMessageRequest(parentPlatform, content, fromTag, viaTag, null, callIdHeader);
|
||||
}
|
||||
|
||||
|
||||
public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String viaTag, String toTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
Request request = null;
|
||||
String serverAddress = parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort();
|
||||
// sipuri
|
||||
@ -174,7 +186,7 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), serverAddress);
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, null);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
@ -192,4 +204,107 @@ public class SIPRequestHeaderPlarformProvider {
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public SIPRequest createNotifyRequest(ParentPlatform parentPlatform, String content, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
SIPRequest request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()),
|
||||
parentPlatform.getTransport(), SipUtils.getNewViaTag());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
|
||||
parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, subscribeInfo.getResponse().getToTag());
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getRequest().getFromTag());
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.NOTIFY);
|
||||
MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
|
||||
// 设置编码, 防止中文乱码
|
||||
messageFactory.setDefaultContentEncodingCharset("gb2312");
|
||||
|
||||
CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(subscribeInfo.getRequest().getCallIdHeader().getCallId());
|
||||
|
||||
request = (SIPRequest) messageFactory.createRequest(requestURI, Request.NOTIFY, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards);
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil));
|
||||
|
||||
EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
|
||||
if (subscribeInfo.getEventId() != null) {
|
||||
event.setEventId(subscribeInfo.getEventId());
|
||||
}
|
||||
|
||||
request.addHeader(event);
|
||||
|
||||
SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active");
|
||||
request.setHeader(active);
|
||||
|
||||
String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(parentPlatform.getDeviceGBId(), sipAddress));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public SIPRequest createByeRequest(ParentPlatform platform, SendRtpItem sendRtpItem) throws PeerUnavailableException, ParseException, InvalidArgumentException {
|
||||
|
||||
if (sendRtpItem == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SIPRequest request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+ ":" + platform.getServerPort());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(platform.getDeviceIp(), Integer.parseInt(platform.getDevicePort()),
|
||||
platform.getTransport(), SipUtils.getNewViaTag());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),
|
||||
platform.getDeviceIp() + ":" + platform.getDevicePort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, sendRtpItem.getToTag());
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerGBDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, sendRtpItem.getFromTag());
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.BYE);
|
||||
MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
|
||||
// 设置编码, 防止中文乱码
|
||||
messageFactory.setDefaultContentEncodingCharset("gb2312");
|
||||
|
||||
CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(sendRtpItem.getCallId());
|
||||
|
||||
request = (SIPRequest) messageFactory.createRequest(requestURI, Request.BYE, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards);
|
||||
|
||||
request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil));
|
||||
|
||||
String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
|
||||
.createSipURI(platform.getDeviceGBId(), sipAddress));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.utils.GitUtil;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@ -199,24 +200,24 @@ public class SIPRequestHeaderProvider {
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createSubscribeRequest(Device device, String content, String viaTag, String fromTag, String toTag, Integer expires, String event, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
public Request createSubscribeRequest(Device device, String content, SIPRequest requestOld, Integer expires, String event, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(),
|
||||
device.getTransport(), viaTag);
|
||||
device.getTransport(), SipUtils.getNewViaTag());
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, requestOld == null ? SipUtils.getNewFromTag() :requestOld.getFromTag());
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, requestOld == null ? null :requestOld.getToTag());
|
||||
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
@ -238,7 +239,7 @@ public class SIPRequestHeaderProvider {
|
||||
// Event
|
||||
EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event);
|
||||
|
||||
int random = (int)Math.random() * 1000000000;
|
||||
int random = (int) Math.floor(Math.random() * 10000);
|
||||
eventHeader.setEventId(random + "");
|
||||
request.addHeader(eventHeader);
|
||||
|
||||
|
@ -1424,7 +1424,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
@Override
|
||||
public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
|
||||
public SIPRequest mobilePositionSubscribe(Device device, SIPRequest requestOld, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer subscribePostitionXml = new StringBuffer(200);
|
||||
String charset = device.getCharset();
|
||||
@ -1434,38 +1434,27 @@ public class SIPCommander implements ISIPCommander {
|
||||
subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
if (device.getSubscribeCycleForMobilePosition() > 0) {
|
||||
subscribePostitionXml.append("<Interval>" + String.valueOf(device.getMobilePositionSubmissionInterval()) + "</Interval>\r\n");
|
||||
subscribePostitionXml.append("<Interval>" + device.getMobilePositionSubmissionInterval() + "</Interval>\r\n");
|
||||
}
|
||||
subscribePostitionXml.append("</Query>\r\n");
|
||||
|
||||
Request request;
|
||||
if (dialog != null) {
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
request = dialog.createRequest(Request.SUBSCRIBE);
|
||||
ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
||||
request.setExpires(expiresHeader);
|
||||
CallIdHeader callIdHeader;
|
||||
|
||||
request.setRequestURI(requestURI);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
|
||||
|
||||
CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
||||
cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ());
|
||||
request.removeHeader(CSeqHeader.NAME);
|
||||
request.addHeader(cSeqHeader);
|
||||
if (requestOld != null) {
|
||||
callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(requestOld.getCallIdHeader().getCallId());
|
||||
}else {
|
||||
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
||||
}
|
||||
SIPRequest request = (SIPRequest)headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), requestOld, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
||||
|
||||
transmitRequest(device, request, errorEvent, okEvent);
|
||||
|
||||
return true;
|
||||
return request;
|
||||
|
||||
} catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1515,7 +1504,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, expires, "presence" , callIdHeader);
|
||||
Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), null, expires, "presence" , callIdHeader);
|
||||
transmitRequest(device, request);
|
||||
|
||||
return true;
|
||||
@ -1527,7 +1516,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
||||
public SIPRequest catalogSubscribe(Device device, SIPRequest requestOld, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
String charset = device.getCharset();
|
||||
@ -1538,40 +1527,24 @@ public class SIPCommander implements ISIPCommander {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
CallIdHeader callIdHeader ;
|
||||
|
||||
Request request;
|
||||
if (dialog != null) {
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
request = dialog.createRequest(Request.SUBSCRIBE);
|
||||
ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
||||
request.setExpires(expiresHeader);
|
||||
|
||||
request.setRequestURI(requestURI);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
request.setContent(cmdXml.toString(), contentTypeHeader);
|
||||
|
||||
CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
||||
cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ());
|
||||
request.removeHeader(CSeqHeader.NAME);
|
||||
request.addHeader(cSeqHeader);
|
||||
|
||||
if (requestOld != null) {
|
||||
callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(requestOld.getCallIdHeader().getCallId());
|
||||
}else {
|
||||
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
}
|
||||
|
||||
// 有效时间默认为60秒以上
|
||||
request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), SipUtils.getNewViaTag(),
|
||||
SipUtils.getNewFromTag(), null, device.getSubscribeCycleForCatalog(), "Catalog" ,
|
||||
SIPRequest request = (SIPRequest)headerProvider.createSubscribeRequest(device, cmdXml.toString(), requestOld, device.getSubscribeCycleForCatalog(), "Catalog" ,
|
||||
callIdHeader);
|
||||
|
||||
}
|
||||
transmitRequest(device, request, errorEvent, okEvent);
|
||||
return true;
|
||||
return request;
|
||||
|
||||
} catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1847,61 +1820,4 @@ public class SIPCommander implements ISIPCommander {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendNotify(Device device, String catalogXmlContent,
|
||||
SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
|
||||
throws SipException, ParseException {
|
||||
MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
|
||||
String characterSet = device.getCharset();
|
||||
// 设置编码, 防止中文乱码
|
||||
messageFactory.setDefaultContentEncodingCharset(characterSet);
|
||||
Dialog dialog = subscribeInfo.getDialog();
|
||||
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
return;
|
||||
}
|
||||
SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
notifyRequest.setContent(catalogXmlContent, contentTypeHeader);
|
||||
|
||||
SubscriptionStateHeader subscriptionState = sipFactory.createHeaderFactory()
|
||||
.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
|
||||
notifyRequest.addHeader(subscriptionState);
|
||||
|
||||
EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
|
||||
if (subscribeInfo.getEventId() != null) {
|
||||
event.setEventId(subscribeInfo.getEventId());
|
||||
}
|
||||
notifyRequest.addHeader(event);
|
||||
|
||||
SipURI sipURI = (SipURI) notifyRequest.getRequestURI();
|
||||
if (subscribeInfo.getTransaction() != null) {
|
||||
SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
|
||||
sipURI.setHost(request.getRemoteAddress().getHostAddress());
|
||||
sipURI.setPort(request.getRemotePort());
|
||||
}else {
|
||||
sipURI.setHost(device.getIp());
|
||||
sipURI.setPort(device.getPort());
|
||||
}
|
||||
|
||||
ClientTransaction transaction = null;
|
||||
if ("TCP".equals(device.getTransport())) {
|
||||
transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
} else if ("UDP".equals(device.getTransport())) {
|
||||
transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
}
|
||||
// 添加错误订阅
|
||||
if (errorEvent != null) {
|
||||
sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent);
|
||||
}
|
||||
// 添加订阅
|
||||
if (okEvent != null) {
|
||||
sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent);
|
||||
}
|
||||
if (transaction == null) {
|
||||
logger.error("平台{}的Transport错误:{}",device.getDeviceId(), device.getTransport());
|
||||
return;
|
||||
}
|
||||
dialog.sendRequest(transaction);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
@ -45,7 +46,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class);
|
||||
|
||||
@Autowired
|
||||
private SIPRequestHeaderPlarformProvider headerProviderPlarformProvider;
|
||||
private SIPRequestHeaderPlarformProvider headerProviderPlatformProvider;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
@ -72,6 +73,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
@Autowired
|
||||
private SipFactory sipFactory;
|
||||
|
||||
@Autowired
|
||||
private SubscribeHolder subscribeHolder;
|
||||
|
||||
@Override
|
||||
public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
|
||||
return register(parentPlatform, null, null, errorEvent, okEvent, false, true);
|
||||
@ -96,7 +100,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
callIdHeader = udpSipProvider.getNewCallId();
|
||||
}
|
||||
|
||||
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform,
|
||||
request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform,
|
||||
redisCatchStorage.getCSEQ(), SipUtils.getNewFromTag(),
|
||||
SipUtils.getNewViaTag(), callIdHeader, isRegister);
|
||||
// 将 callid 写入缓存, 等注册成功可以更新状态
|
||||
@ -118,7 +122,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}else {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister);
|
||||
request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister);
|
||||
}
|
||||
|
||||
transmitRequest(parentPlatform, request, null, okEvent);
|
||||
@ -152,7 +156,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(
|
||||
parentPlatform,
|
||||
keepaliveXml.toString(),
|
||||
SipUtils.getNewFromTag(),
|
||||
@ -218,7 +222,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@ -312,7 +316,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request, null, eventResult -> {
|
||||
int indexNext = index + parentPlatform.getCatalogGroup();
|
||||
sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext);
|
||||
@ -352,7 +356,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@ -390,7 +394,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@ -425,10 +429,6 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
deviceStatusXml.append("<Altitude>" + gpsMsgInfo.getAltitude() + "</Altitude>\r\n");
|
||||
deviceStatusXml.append("</Notify>\r\n");
|
||||
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
callIdHeader.setCallId(subscribeInfo.getCallId());
|
||||
|
||||
sendNotify(parentPlatform, deviceStatusXml.toString(), subscribeInfo, eventResult -> {
|
||||
logger.error("发送NOTIFY通知消息失败。错误:{} {}", eventResult.statusCode, eventResult.msg);
|
||||
}, null);
|
||||
@ -451,8 +451,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
if (parentPlatform == null) {
|
||||
return false;
|
||||
}
|
||||
logger.info("[发送 报警订阅] {}/{}->{},{}", parentPlatform.getServerGBId(), deviceAlarm.getChannelId(),
|
||||
deviceAlarm.getLongitude(), deviceAlarm.getLatitude());
|
||||
logger.info("[发送报警通知] {}/{}->{},{}: {}", parentPlatform.getServerGBId(), deviceAlarm.getChannelId(),
|
||||
deviceAlarm.getLongitude(), deviceAlarm.getLatitude(), JSONObject.toJSON(deviceAlarm));
|
||||
try {
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
StringBuffer deviceStatusXml = new StringBuffer(600);
|
||||
@ -475,7 +475,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException e) {
|
||||
@ -527,18 +527,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendNotify(ParentPlatform parentPlatform, String catalogXmlContent,
|
||||
private ClientTransaction sendNotify(ParentPlatform parentPlatform, String catalogXmlContent,
|
||||
SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
|
||||
throws NoSuchFieldException, IllegalAccessException, SipException, ParseException, InvalidArgumentException {
|
||||
MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
|
||||
String characterSet = parentPlatform.getCharacterSet();
|
||||
// 设置编码, 防止中文乱码
|
||||
messageFactory.setDefaultContentEncodingCharset(characterSet);
|
||||
Dialog dialog = subscribeInfo.getDialog();
|
||||
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
return;
|
||||
}
|
||||
SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
|
||||
|
||||
SIPRequest notifyRequest = headerProviderPlatformProvider.createNotifyRequest(parentPlatform, catalogXmlContent, subscribeInfo);
|
||||
|
||||
notifyRequest.getCSeqHeader().setSeqNumber(redisCatchStorage.getCSEQ());
|
||||
|
||||
@ -558,26 +555,32 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
sipURI.setHost(parentPlatform.getServerIP());
|
||||
sipURI.setPort(parentPlatform.getServerPort());
|
||||
|
||||
// ClientTransaction transaction = subscribeInfo.getClientTransaction();
|
||||
// if (transaction == null || transaction.getState().equals(TransactionState.COMPLETED)) {
|
||||
// if ("TCP".equals(parentPlatform.getTransport())) {
|
||||
// transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
// } else if ("UDP".equals(parentPlatform.getTransport())) {
|
||||
// transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
// }
|
||||
// }
|
||||
|
||||
ClientTransaction transaction = null;
|
||||
if ("TCP".equals(parentPlatform.getTransport())) {
|
||||
transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
} else if ("UDP".equals(parentPlatform.getTransport())) {
|
||||
transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
|
||||
}
|
||||
|
||||
// 添加错误订阅
|
||||
if (errorEvent != null) {
|
||||
sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent);
|
||||
sipSubscribe.addErrorSubscribe(subscribeInfo.getRequest().getCallIdHeader().getCallId(), errorEvent);
|
||||
}
|
||||
// 添加订阅
|
||||
if (okEvent != null) {
|
||||
sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent);
|
||||
sipSubscribe.addOkSubscribe(subscribeInfo.getRequest().getCallIdHeader().getCallId(), okEvent);
|
||||
}
|
||||
if (transaction == null) {
|
||||
logger.error("平台{}的Transport错误:{}",parentPlatform.getServerGBId(), parentPlatform.getTransport());
|
||||
return;
|
||||
}
|
||||
dialog.sendRequest(transaction);
|
||||
|
||||
transaction.sendRequest();
|
||||
return transaction;
|
||||
}
|
||||
|
||||
private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, List<DeviceChannel> channels, int sumNum, String type, SubscribeInfo subscribeInfo) {
|
||||
@ -753,7 +756,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
// callid
|
||||
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader);
|
||||
transmitRequest(parentPlatform, request);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@ -772,36 +775,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] dialogByteArray = sendRtpItem.getDialog();
|
||||
if (dialogByteArray == null) {
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray);
|
||||
SipStack sipStack;
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
sipStack = tcpSipProvider.getSipStack();
|
||||
} else {
|
||||
sipStack = udpSipProvider.getSipStack();
|
||||
}
|
||||
SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog);
|
||||
if (dialog != sipDialog) {
|
||||
dialog = sipDialog;
|
||||
}
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
dialog.setSipProvider(tcpSipProvider);
|
||||
} else {
|
||||
dialog.setSipProvider(udpSipProvider);
|
||||
}
|
||||
|
||||
Field sipStackField = SIPDialog.class.getDeclaredField("sipStack");
|
||||
sipStackField.setAccessible(true);
|
||||
sipStackField.set(dialog, sipStack);
|
||||
Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners");
|
||||
eventListenersField.setAccessible(true);
|
||||
eventListenersField.set(dialog, new HashSet<>());
|
||||
|
||||
SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE);
|
||||
String characterSet = platform.getCharacterSet();
|
||||
StringBuffer mediaStatusXml = new StringBuffer(200);
|
||||
mediaStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
|
||||
@ -811,6 +786,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
mediaStatusXml.append("<DeviceID>" + sendRtpItem.getChannelId() + "</DeviceID>\r\n");
|
||||
mediaStatusXml.append("<NotifyType>121</NotifyType>\r\n");
|
||||
mediaStatusXml.append("</Notify>\r\n");
|
||||
|
||||
SIPRequest messageRequest = (SIPRequest)headerProviderPlatformProvider.createMessageRequest(platform, mediaStatusXml.toString(),
|
||||
sendRtpItem);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
messageRequest.setContent(mediaStatusXml.toString(), contentTypeHeader);
|
||||
SipURI sipURI = (SipURI) messageRequest.getRequestURI();
|
||||
@ -822,17 +801,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}else {
|
||||
clientTransaction = udpSipProvider.getNewClientTransaction(messageRequest);
|
||||
}
|
||||
dialog.sendRequest(clientTransaction);
|
||||
clientTransaction.sendRequest();
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -846,61 +823,46 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
|
||||
}
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platform.getServerGBId(), null, null, callId);
|
||||
if (sendRtpItem != null) {
|
||||
streamByeCmd(platform, sendRtpItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamByeCmd(ParentPlatform platform, SendRtpItem sendRtpItem) {
|
||||
if (sendRtpItem == null ) {
|
||||
logger.info("[向上级发送BYE], sendRtpItem 为NULL");
|
||||
return;
|
||||
}
|
||||
if (platform == null) {
|
||||
logger.info("[向上级发送BYE], platform 为NULL");
|
||||
return;
|
||||
}
|
||||
logger.info("[向上级发送BYE], {}/{}", platform.getServerGBId(), sendRtpItem.getChannelId());
|
||||
String mediaServerId = sendRtpItem.getMediaServerId();
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaServerItem != null) {
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc());
|
||||
zlmrtpServerFactory.closeRTPServer(mediaServerItem, sendRtpItem.getStreamId());
|
||||
}
|
||||
byte[] dialogByteArray = sendRtpItem.getDialog();
|
||||
if (dialogByteArray != null) {
|
||||
SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray);
|
||||
SipStack sipStack;
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
sipStack = tcpSipProvider.getSipStack();
|
||||
} else {
|
||||
sipStack = udpSipProvider.getSipStack();
|
||||
}
|
||||
SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog);
|
||||
if (dialog != sipDialog) {
|
||||
dialog = sipDialog;
|
||||
}
|
||||
try {
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
dialog.setSipProvider(tcpSipProvider);
|
||||
} else {
|
||||
dialog.setSipProvider(udpSipProvider);
|
||||
|
||||
SIPRequest byeRequest = headerProviderPlatformProvider.createByeRequest(platform, sendRtpItem);
|
||||
if (byeRequest == null) {
|
||||
logger.warn("[向上级发送bye]:无法创建 byeRequest");
|
||||
}
|
||||
Field sipStackField = SIPDialog.class.getDeclaredField("sipStack");
|
||||
sipStackField.setAccessible(true);
|
||||
sipStackField.set(dialog, sipStack);
|
||||
Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners");
|
||||
eventListenersField.setAccessible(true);
|
||||
eventListenersField.set(dialog, new HashSet<>());
|
||||
|
||||
Request byeRequest = dialog.createRequest(Request.BYE);
|
||||
|
||||
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
|
||||
byeURI.setHost(platform.getServerIP());
|
||||
byeURI.setPort(platform.getServerPort());
|
||||
ClientTransaction clientTransaction;
|
||||
if ("TCP".equals(platform.getTransport())) {
|
||||
clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest);
|
||||
} else {
|
||||
clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest);
|
||||
}
|
||||
dialog.sendRequest(clientTransaction);
|
||||
clientTransaction.sendRequest();
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (InvalidArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.event.request;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import gov.nist.javax.sip.stack.SIPServerTransaction;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.dom4j.Document;
|
||||
@ -19,10 +21,7 @@ import javax.sip.*;
|
||||
import javax.sip.address.Address;
|
||||
import javax.sip.address.AddressFactory;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.ContentTypeHeader;
|
||||
import javax.sip.header.ExpiresHeader;
|
||||
import javax.sip.header.HeaderFactory;
|
||||
import javax.sip.header.ViaHeader;
|
||||
import javax.sip.header.*;
|
||||
import javax.sip.message.MessageFactory;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
@ -59,9 +58,6 @@ public abstract class SIPRequestProcessorParent {
|
||||
public ServerTransaction getServerTransaction(RequestEvent evt) {
|
||||
Request request = evt.getRequest();
|
||||
ServerTransaction serverTransaction = evt.getServerTransaction();
|
||||
if (serverTransaction != null) {
|
||||
System.out.println(serverTransaction.getState().toString());
|
||||
}
|
||||
// 判断TCP还是UDP
|
||||
boolean isTcp = false;
|
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
|
||||
@ -123,105 +119,107 @@ public abstract class SIPRequestProcessorParent {
|
||||
return null;
|
||||
}
|
||||
|
||||
class ResponseAckExtraParam{
|
||||
String content;
|
||||
ContentTypeHeader contentTypeHeader;
|
||||
SipURI sipURI;
|
||||
int expires = -1;
|
||||
}
|
||||
|
||||
/***
|
||||
* 回复状态码
|
||||
* 100 trying
|
||||
* 200 OK
|
||||
* 400
|
||||
* 404
|
||||
* @param evt
|
||||
* @throws SipException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
if (serverTransaction == null) {
|
||||
logger.warn("回复失败:{}", response);
|
||||
return;
|
||||
}
|
||||
serverTransaction.sendResponse(response);
|
||||
if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(evt.getRequest().getMethod())) {
|
||||
|
||||
if (serverTransaction.getDialog() != null) {
|
||||
serverTransaction.getDialog().delete();
|
||||
}
|
||||
}
|
||||
public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode) throws SipException, InvalidArgumentException, ParseException {
|
||||
return responseAck(serverTransaction, statusCode, null);
|
||||
}
|
||||
|
||||
public void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
||||
public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
|
||||
return responseAck(serverTransaction, statusCode, msg, null);
|
||||
}
|
||||
|
||||
public SIPResponse responseAck(ServerTransaction serverTransaction, int statusCode, String msg, ResponseAckExtraParam responseAckExtraParam) throws SipException, InvalidArgumentException, ParseException {
|
||||
ToHeader toHeader = (ToHeader) serverTransaction.getRequest().getHeader(ToHeader.NAME);
|
||||
if (toHeader.getTag() == null) {
|
||||
toHeader.setTag(SipUtils.getNewTag());
|
||||
}
|
||||
SIPResponse response = (SIPResponse)getMessageFactory().createResponse(statusCode, serverTransaction.getRequest());
|
||||
if (msg != null) {
|
||||
response.setReasonPhrase(msg);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
}
|
||||
if (responseAckExtraParam != null) {
|
||||
if (responseAckExtraParam.sipURI != null && serverTransaction.getRequest().getMethod().equals(Request.INVITE)) {
|
||||
logger.debug("responseSdpAck SipURI: {}:{}", responseAckExtraParam.sipURI.getHost(), responseAckExtraParam.sipURI.getPort());
|
||||
Address concatAddress = SipFactory.getInstance().createAddressFactory().createAddress(
|
||||
SipFactory.getInstance().createAddressFactory().createSipURI(responseAckExtraParam.sipURI.getUser(), responseAckExtraParam.sipURI.getHost()+":"+responseAckExtraParam.sipURI.getPort()
|
||||
));
|
||||
response.addHeader(SipFactory.getInstance().createHeaderFactory().createContactHeader(concatAddress));
|
||||
}
|
||||
if (responseAckExtraParam.contentTypeHeader != null) {
|
||||
response.setContent(responseAckExtraParam.content, responseAckExtraParam.contentTypeHeader);
|
||||
}
|
||||
|
||||
if (serverTransaction.getRequest().getMethod().equals(Request.SUBSCRIBE)) {
|
||||
if (responseAckExtraParam.expires == -1) {
|
||||
logger.error("[参数不全] 2xx的SUBSCRIBE回复,必须设置Expires header");
|
||||
}else {
|
||||
ExpiresHeader expiresHeader = SipFactory.getInstance().createHeaderFactory().createExpiresHeader(responseAckExtraParam.expires);
|
||||
response.addHeader(expiresHeader);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (serverTransaction.getRequest().getMethod().equals(Request.SUBSCRIBE)) {
|
||||
logger.error("[参数不全] 2xx的SUBSCRIBE回复,必须设置Expires header");
|
||||
}
|
||||
}
|
||||
serverTransaction.sendResponse(response);
|
||||
if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(evt.getRequest().getMethod())) {
|
||||
if (statusCode >= 200 && !"NOTIFY".equalsIgnoreCase(serverTransaction.getRequest().getMethod())) {
|
||||
if (serverTransaction.getDialog() != null) {
|
||||
serverTransaction.getDialog().delete();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复带sdp的200
|
||||
* @param evt
|
||||
* @param sdp
|
||||
* @throws SipException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void responseSdpAck(RequestEvent evt, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
||||
SipFactory sipFactory = SipFactory.getInstance();
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
|
||||
response.setContent(sdp, contentTypeHeader);
|
||||
public SIPResponse responseSdpAck(ServerTransaction serverTransaction, String sdp, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException {
|
||||
|
||||
ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
|
||||
|
||||
// 兼容国标中的使用编码@域名作为RequestURI的情况
|
||||
SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
|
||||
SipURI sipURI = (SipURI)serverTransaction.getRequest().getRequestURI();
|
||||
if (sipURI.getPort() == -1) {
|
||||
sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
}
|
||||
logger.debug("responseSdpAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort());
|
||||
ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam();
|
||||
responseAckExtraParam.contentTypeHeader = contentTypeHeader;
|
||||
responseAckExtraParam.content = sdp;
|
||||
responseAckExtraParam.sipURI = sipURI;
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(
|
||||
sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
||||
));
|
||||
response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
if (serverTransaction == null) {
|
||||
|
||||
}
|
||||
getServerTransaction(evt).sendResponse(response);
|
||||
return responseAck(serverTransaction, Response.OK, null, responseAckExtraParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复带xml的200
|
||||
* @param evt
|
||||
* @param xml
|
||||
* @throws SipException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public Response responseXmlAck(RequestEvent evt, String xml, ParentPlatform platform) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
||||
SipFactory sipFactory = SipFactory.getInstance();
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
response.setContent(xml, contentTypeHeader);
|
||||
public SIPResponse responseXmlAck(ServerTransaction serverTransaction, String xml, ParentPlatform platform, Integer expires) throws SipException, InvalidArgumentException, ParseException {
|
||||
ContentTypeHeader contentTypeHeader = SipFactory.getInstance().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
||||
|
||||
// 兼容国标中的使用编码@域名作为RequestURI的情况
|
||||
SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
|
||||
SipURI sipURI = (SipURI)serverTransaction.getRequest().getRequestURI();
|
||||
if (sipURI.getPort() == -1) {
|
||||
sipURI = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
sipURI = SipFactory.getInstance().createAddressFactory().createSipURI(platform.getServerGBId(), platform.getServerIP()+":"+platform.getServerPort());
|
||||
}
|
||||
logger.debug("responseXmlAck SipURI: {}:{}", sipURI.getHost(), sipURI.getPort());
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(
|
||||
sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
||||
));
|
||||
response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
response.addHeader(evt.getRequest().getHeader(ExpiresHeader.NAME));
|
||||
getServerTransaction(evt).sendResponse(response);
|
||||
return response;
|
||||
ResponseAckExtraParam responseAckExtraParam = new ResponseAckExtraParam();
|
||||
responseAckExtraParam.contentTypeHeader = contentTypeHeader;
|
||||
responseAckExtraParam.content = xml;
|
||||
responseAckExtraParam.sipURI = sipURI;
|
||||
responseAckExtraParam.expires = expires;
|
||||
return responseAck(serverTransaction, Response.OK, null, responseAckExtraParam);
|
||||
}
|
||||
|
||||
public Element getRootElement(RequestEvent evt) throws DocumentException {
|
||||
|
@ -87,14 +87,10 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
Dialog dialog = evt.getDialog();
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
if (dialog == null) {
|
||||
return;
|
||||
}
|
||||
if (dialog.getState()== DialogState.CONFIRMED) {
|
||||
|
||||
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
|
||||
logger.info("ACK请求: platformGbId->{}", platformGbId);
|
||||
logger.info("[收到ACK]: platformGbId->{}", platformGbId);
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformGbId);
|
||||
// 取消设置的超时任务
|
||||
dynamicTask.stop(callIdHeader.getCallId());
|
||||
@ -132,21 +128,14 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
JSONObject jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
|
||||
startSendRtpStreamHand(evt, sendRtpItem, parentPlatform, jsonObject, param, callIdHeader);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
private void startSendRtpStreamHand(RequestEvent evt, SendRtpItem sendRtpItem, ParentPlatform parentPlatform,
|
||||
JSONObject jsonObject, Map<String, Object> param, CallIdHeader callIdHeader) {
|
||||
if (jsonObject == null) {
|
||||
logger.error("RTP推流失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("调用ZLM推流接口, 结果: {}", jsonObject);
|
||||
logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
} else {
|
||||
logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param));
|
||||
if (sendRtpItem.isOnlyAudio()) {
|
||||
|
@ -78,17 +78,12 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
Dialog dialog = evt.getDialog();
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
if (dialog == null) {
|
||||
return;
|
||||
}
|
||||
if (dialog.getState().equals(DialogState.TERMINATED)) {
|
||||
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
|
||||
String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
|
||||
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(platformGbId, channelId, null, callIdHeader.getCallId());
|
||||
logger.info("收到bye, [{}/{}]", platformGbId, channelId);
|
||||
logger.info("[收到bye] {}/{}", platformGbId, channelId);
|
||||
if (sendRtpItem != null){
|
||||
String streamId = sendRtpItem.getStreamId();
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
@ -96,13 +91,13 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
param.put("app",sendRtpItem.getApp());
|
||||
param.put("stream",streamId);
|
||||
param.put("ssrc",sendRtpItem.getSsrc());
|
||||
logger.info("收到bye:停止向上级推流:" + streamId);
|
||||
logger.info("[收到bye] 停止向上级推流:{}", streamId);
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
redisCatchStorage.deleteSendRTPServer(platformGbId, channelId, callIdHeader.getCallId(), null);
|
||||
zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
|
||||
int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId);
|
||||
if (totalReaderCount <= 0) {
|
||||
logger.info("收到bye: {} 无其它观看者,通知设备停止推流", streamId);
|
||||
logger.info("[收到bye] {} 无其它观看者,通知设备停止推流", streamId);
|
||||
if (sendRtpItem.getPlayType().equals(InviteStreamType.PLAY)) {
|
||||
cmder.streamByeCmd(sendRtpItem.getDeviceId(), channelId, streamId, null);
|
||||
}
|
||||
@ -145,7 +140,6 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlayBack.getStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -8,7 +8,6 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
@ -28,9 +27,10 @@ import com.genersoft.iot.vmp.service.impl.RedisPushStreamResponseListener;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.utils.SerializeUtils;
|
||||
import gov.nist.javax.sdp.TimeDescriptionImpl;
|
||||
import gov.nist.javax.sdp.fields.TimeField;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@ -128,17 +128,19 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
String channelId = SipUtils.getChannelIdFromRequest(request);
|
||||
String requesterId = SipUtils.getUserIdFromFromHeader(request);
|
||||
CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
if (requesterId == null || channelId == null) {
|
||||
logger.info("无法从FromHeader的Address中获取到平台id,返回400");
|
||||
// 参数不全, 发400,请求错误
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 查询请求是否来自上级平台\设备
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId);
|
||||
if (platform == null) {
|
||||
inviteFromDeviceHandle(evt, requesterId);
|
||||
inviteFromDeviceHandle(serverTransaction, requesterId);
|
||||
} else {
|
||||
// 查询平台下是否有该通道
|
||||
DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId);
|
||||
@ -150,12 +152,13 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
StreamProxyItem proxyByAppAndStream =null;
|
||||
// 不是通道可能是直播流
|
||||
if (channel != null && gbStream == null) {
|
||||
if (channel.getStatus() == 0) {
|
||||
logger.info("通道离线,返回400");
|
||||
responseAck(evt, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline");
|
||||
return;
|
||||
}
|
||||
responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中
|
||||
// if (channel.getStatus() == 0) {
|
||||
// logger.info("通道离线,返回400");
|
||||
// responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline");
|
||||
// return;
|
||||
// }
|
||||
// 通道存在,发100,TRYING
|
||||
responseAck(serverTransaction, Response.TRYING);
|
||||
} else if (channel == null && gbStream != null) {
|
||||
|
||||
String mediaServerId = gbStream.getMediaServerId();
|
||||
@ -163,13 +166,13 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (mediaServerItem == null) {
|
||||
if ("proxy".equals(gbStream.getStreamType())) {
|
||||
logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
|
||||
responseAck(evt, Response.GONE);
|
||||
responseAck(serverTransaction, Response.GONE);
|
||||
return;
|
||||
} else {
|
||||
streamPushItem = streamPushService.getPush(gbStream.getApp(), gbStream.getStream());
|
||||
if (streamPushItem == null || streamPushItem.getServerId().equals(userSetting.getServerId())) {
|
||||
logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
|
||||
responseAck(evt, Response.GONE);
|
||||
responseAck(serverTransaction, Response.GONE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -178,25 +181,25 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
streamPushItem = streamPushService.getPush(gbStream.getApp(), gbStream.getStream());
|
||||
if (streamPushItem == null) {
|
||||
logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
|
||||
responseAck(evt, Response.GONE);
|
||||
responseAck(serverTransaction, Response.GONE);
|
||||
return;
|
||||
}
|
||||
}else if("proxy".equals(gbStream.getStreamType())){
|
||||
proxyByAppAndStream = streamProxyService.getStreamProxyByAppAndStream(gbStream.getApp(), gbStream.getStream());
|
||||
if (proxyByAppAndStream == null) {
|
||||
logger.info("[ app={}, stream={} ]找不到zlm {},返回410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
|
||||
responseAck(evt, Response.GONE);
|
||||
responseAck(serverTransaction, Response.GONE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中
|
||||
responseAck(serverTransaction, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中
|
||||
} else if (catalog != null) {
|
||||
responseAck(evt, Response.BAD_REQUEST, "catalog channel can not play"); // 目录不支持点播
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, "catalog channel can not play"); // 目录不支持点播
|
||||
return;
|
||||
} else {
|
||||
logger.info("通道不存在,返回404");
|
||||
responseAck(evt, Response.NOT_FOUND); // 通道不存在,发404,资源不存在
|
||||
responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在,发404,资源不存在
|
||||
return;
|
||||
}
|
||||
// 解析sdp消息, 使用jainsip 自带的sdp解析方式
|
||||
@ -209,7 +212,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
String ssrc;
|
||||
SessionDescription sdp;
|
||||
if (ssrcIndex >= 0) {
|
||||
//ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段
|
||||
//ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段
|
||||
ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
|
||||
String substring = contentString.substring(0, contentString.indexOf("y="));
|
||||
sdp = SdpFactory.getInstance().createSessionDescription(substring);
|
||||
@ -256,9 +259,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
mediaTransmissionTCP = true;
|
||||
if ("active".equalsIgnoreCase(setup)) {
|
||||
tcpActive = true;
|
||||
// 不支持tcp主动
|
||||
responseAck(evt, Response.NOT_IMPLEMENTED, "tcp active not support"); // 目录不支持点播
|
||||
return;
|
||||
} else if ("passive".equalsIgnoreCase(setup)) {
|
||||
tcpActive = false;
|
||||
}
|
||||
@ -270,7 +270,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (port == -1) {
|
||||
logger.info("不支持的媒体格式,返回415");
|
||||
// 回复不支持的格式
|
||||
responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
|
||||
responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
|
||||
return;
|
||||
}
|
||||
String username = sdp.getOrigin().getUsername();
|
||||
@ -283,24 +283,25 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
device = storager.queryVideoDeviceByPlatformIdAndChannelId(requesterId, channelId);
|
||||
if (device == null) {
|
||||
logger.warn("点播平台{}的通道{}时未找到设备信息", requesterId, channel);
|
||||
responseAck(evt, Response.SERVER_INTERNAL_ERROR);
|
||||
responseAck(serverTransaction, Response.SERVER_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
mediaServerItem = playService.getNewMediaServerItem(device);
|
||||
if (mediaServerItem == null) {
|
||||
logger.warn("未找到可用的zlm");
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
return;
|
||||
}
|
||||
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
|
||||
device.getDeviceId(), channelId,
|
||||
mediaTransmissionTCP);
|
||||
|
||||
if (tcpActive != null) {
|
||||
sendRtpItem.setTcpActive(tcpActive);
|
||||
}
|
||||
if (sendRtpItem == null) {
|
||||
logger.warn("服务器端口资源不足");
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
return;
|
||||
}
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
@ -342,7 +343,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 回复bye
|
||||
cmderFroPlatform.streamByeCmd(platform, callIdHeader.getCallId());
|
||||
}, 60 * 1000);
|
||||
responseSdpAck(evt, content.toString(), platform);
|
||||
responseSdpAck(serverTransaction, content.toString(), platform);
|
||||
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
@ -357,8 +358,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
Response response = null;
|
||||
try {
|
||||
response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
serverTransaction.sendResponse(response);
|
||||
System.out.println("未知错误。直接转发设备点播的错误");
|
||||
if (serverTransaction.getDialog() != null) {
|
||||
serverTransaction.getDialog().delete();
|
||||
}
|
||||
@ -382,7 +383,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
}
|
||||
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
|
||||
try {
|
||||
responseAck(evt, Response.REQUEST_TIMEOUT);
|
||||
responseAck(serverTransaction, Response.REQUEST_TIMEOUT);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -420,6 +421,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false);
|
||||
logger.info(JSONObject.toJSONString(ssrcInfo));
|
||||
sendRtpItem.setStreamId(ssrcInfo.getStream());
|
||||
|
||||
// 写入redis, 超时时回复
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
|
||||
@ -440,26 +442,26 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if("push".equals(gbStream.getStreamType())) {
|
||||
if (streamPushItem != null && streamPushItem.isPushIng()) {
|
||||
// 推流状态
|
||||
pushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
} else {
|
||||
// 未推流 拉起
|
||||
notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
}else if ("proxy".equals(gbStream.getStreamType())){
|
||||
if(null != proxyByAppAndStream &&proxyByAppAndStream.isStatus()){
|
||||
pushProxyStream(evt, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}else{
|
||||
//开启代理拉流
|
||||
boolean start1 = streamProxyService.start(gbStream.getApp(), gbStream.getStream());
|
||||
if(start1) {
|
||||
pushProxyStream(evt, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}else{
|
||||
//失败后通知
|
||||
notifyStreamOnline(evt, gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
notifyStreamOnline(evt, serverTransaction,gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
}
|
||||
@ -482,7 +484,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
/**
|
||||
* 安排推流
|
||||
*/
|
||||
private void pushProxyStream(RequestEvent evt, GbStream gbStream, ParentPlatform platform,
|
||||
private void pushProxyStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, ParentPlatform platform,
|
||||
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
|
||||
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
|
||||
String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException {
|
||||
@ -495,7 +497,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
if (sendRtpItem == null) {
|
||||
logger.warn("服务器端口资源不足");
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
return;
|
||||
}
|
||||
if (tcpActive != null) {
|
||||
@ -505,17 +507,19 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 写入redis, 超时时回复
|
||||
sendRtpItem.setStatus(1);
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
SIPRequest request = (SIPRequest) evt.getRequest();
|
||||
sendRtpItem.setFromTag(request.getFromTag());
|
||||
|
||||
SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
|
||||
if (response != null) {
|
||||
sendRtpItem.setToTag(response.getToTag());
|
||||
}
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
sendStreamAck(mediaServerItem, sendRtpItem, platform, evt);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private void pushStream(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
private void pushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
|
||||
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
|
||||
String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException {
|
||||
@ -530,7 +534,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
if (sendRtpItem == null) {
|
||||
logger.warn("服务器端口资源不足");
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
return;
|
||||
}
|
||||
if (tcpActive != null) {
|
||||
@ -540,39 +544,43 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 写入redis, 超时时回复
|
||||
sendRtpItem.setStatus(1);
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
|
||||
SIPRequest request = (SIPRequest) evt.getRequest();
|
||||
sendRtpItem.setFromTag(request.getFromTag());
|
||||
SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
|
||||
if (response != null) {
|
||||
sendRtpItem.setToTag(response.getToTag());
|
||||
}
|
||||
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
sendStreamAck(mediaServerItem, sendRtpItem, platform, evt);
|
||||
|
||||
} else {
|
||||
// 不在线 拉起
|
||||
notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
|
||||
} else {
|
||||
// 其他平台内容
|
||||
otherWvpPushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 通知流上线
|
||||
*/
|
||||
private void notifyStreamOnline(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
private void notifyStreamOnline(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
|
||||
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
|
||||
String channelId, String addressStr, String ssrc, String requesterId) throws InvalidArgumentException, ParseException, SipException {
|
||||
if ("proxy".equals(gbStream.getStreamType())) {
|
||||
// TODO 控制启用以使设备上线
|
||||
logger.info("[ app={}, stream={} ]通道未推流,启用流后开始推流", gbStream.getApp(), gbStream.getStream());
|
||||
responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline");
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline");
|
||||
} else if ("push".equals(gbStream.getStreamType())) {
|
||||
if (!platform.isStartOfflinePush()) {
|
||||
// 平台设置中关闭了拉起离线的推流则直接回复
|
||||
responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing");
|
||||
responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing");
|
||||
return;
|
||||
}
|
||||
// 发送redis消息以使设备上线
|
||||
@ -587,7 +595,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
logger.info("[ app={}, stream={} ] 等待设备开始推流超时", gbStream.getApp(), gbStream.getStream());
|
||||
try {
|
||||
mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream());
|
||||
responseAck(evt, Response.REQUEST_TIMEOUT); // 超时
|
||||
responseAck(serverTransaction, Response.REQUEST_TIMEOUT); // 超时
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -610,7 +618,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (sendRtpItem == null) {
|
||||
logger.warn("上级点时创建sendRTPItem失败,可能是服务器端口资源不足");
|
||||
try {
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -627,15 +635,17 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 写入redis, 超时时回复
|
||||
sendRtpItem.setStatus(1);
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
|
||||
SIPRequest request = (SIPRequest) evt.getRequest();
|
||||
sendRtpItem.setFromTag(request.getFromTag());
|
||||
SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
|
||||
if (response != null) {
|
||||
sendRtpItem.setToTag(response.getToTag());
|
||||
}
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
sendStreamAck(mediaServerItem, sendRtpItem, platform, evt);
|
||||
} else {
|
||||
// 其他平台内容
|
||||
otherWvpPushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
});
|
||||
@ -646,7 +656,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
dynamicTask.stop(callIdHeader.getCallId());
|
||||
mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream());
|
||||
try {
|
||||
responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, response.getMsg());
|
||||
responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, response.getMsg());
|
||||
} catch (SipException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -662,7 +672,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
/**
|
||||
* 来自其他wvp的推流
|
||||
*/
|
||||
private void otherWvpPushStream(RequestEvent evt, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
private void otherWvpPushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
|
||||
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
|
||||
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
|
||||
String channelId, String addressStr, String ssrc, String requesterId) {
|
||||
@ -675,7 +685,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (sendRtpItem == null || responseSendItemMsg.getMediaServerItem() == null) {
|
||||
logger.warn("服务器端口资源不足");
|
||||
try {
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -693,12 +703,14 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
// 写入redis, 超时时回复
|
||||
sendRtpItem.setStatus(1);
|
||||
sendRtpItem.setCallId(callIdHeader.getCallId());
|
||||
byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog());
|
||||
sendRtpItem.setDialog(dialogByteArray);
|
||||
byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction());
|
||||
sendRtpItem.setTransaction(transactionByteArray);
|
||||
|
||||
SIPRequest request = (SIPRequest) evt.getRequest();
|
||||
sendRtpItem.setFromTag(request.getFromTag());
|
||||
SIPResponse response = sendStreamAck(responseSendItemMsg.getMediaServerItem(), serverTransaction,sendRtpItem, platform, evt);
|
||||
if (response != null) {
|
||||
sendRtpItem.setToTag(response.getToTag());
|
||||
}
|
||||
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
||||
sendStreamAck(responseSendItemMsg.getMediaServerItem(), sendRtpItem, platform, evt);
|
||||
}, (wvpResult) -> {
|
||||
try {
|
||||
// 错误
|
||||
@ -708,12 +720,12 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
StreamPushItem currentStreamPushItem = streamPushService.getPush(streamPushItem.getApp(), streamPushItem.getStream());
|
||||
if (currentStreamPushItem.isPushIng()) {
|
||||
// 在线状态
|
||||
pushStream(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
|
||||
} else {
|
||||
// 不在线 拉起
|
||||
notifyStreamOnline(evt, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
notifyStreamOnline(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
|
||||
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
|
||||
}
|
||||
}
|
||||
@ -727,7 +739,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
|
||||
try {
|
||||
responseAck(evt, Response.BUSY_HERE);
|
||||
responseAck(serverTransaction, Response.BUSY_HERE);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -739,7 +751,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
});
|
||||
}
|
||||
|
||||
public void sendStreamAck(MediaServerItem mediaServerItem, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) {
|
||||
public SIPResponse sendStreamAck(MediaServerItem mediaServerItem, ServerTransaction serverTransaction, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) {
|
||||
|
||||
StringBuffer content = new StringBuffer(200);
|
||||
content.append("v=0\r\n");
|
||||
@ -762,7 +774,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
content.append("f=\r\n");
|
||||
|
||||
try {
|
||||
responseSdpAck(evt, content.toString(), platform);
|
||||
return responseSdpAck(serverTransaction, content.toString(), platform);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -770,18 +782,18 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void inviteFromDeviceHandle(RequestEvent evt, String requesterId) throws InvalidArgumentException, ParseException, SipException, SdpException {
|
||||
public void inviteFromDeviceHandle(ServerTransaction serverTransaction, String requesterId) throws InvalidArgumentException, ParseException, SipException, SdpException {
|
||||
|
||||
// 非上级平台请求,查询是否设备请求(通常为接收语音广播的设备)
|
||||
Device device = redisCatchStorage.getDevice(requesterId);
|
||||
Request request = evt.getRequest();
|
||||
if (device != null) {
|
||||
logger.info("收到设备" + requesterId + "的语音广播Invite请求");
|
||||
responseAck(evt, Response.TRYING);
|
||||
responseAck(serverTransaction, Response.TRYING);
|
||||
|
||||
String contentString = new String(request.getRawContent());
|
||||
String contentString = new String(serverTransaction.getRequest().getRawContent());
|
||||
// jainSip不支持y=字段, 移除移除以解析。
|
||||
String substring = contentString;
|
||||
String ssrc = "0000000404";
|
||||
@ -829,7 +841,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
if (port == -1) {
|
||||
logger.info("不支持的媒体格式,返回415");
|
||||
// 回复不支持的格式
|
||||
responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
|
||||
responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
|
||||
return;
|
||||
}
|
||||
String username = sdp.getOrigin().getUsername();
|
||||
@ -838,7 +850,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
|
||||
|
||||
} else {
|
||||
logger.warn("来自无效设备/平台的请求");
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.message.Response;
|
||||
@ -94,7 +95,8 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
taskQueue.offer(new HandlerCatchData(evt, null, null));
|
||||
responseAck(evt, Response.OK);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
if (!taskQueueHandlerRun) {
|
||||
taskQueueHandlerRun = true;
|
||||
taskExecutor.execute(()-> {
|
||||
|
@ -17,6 +17,12 @@ import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import gov.nist.javax.sip.stack.SIPClientTransaction;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
import gov.nist.javax.sip.stack.SIPServerTransaction;
|
||||
import gov.nist.javax.sip.stack.SIPServerTransactionImpl;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
@ -49,22 +55,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@Qualifier(value="tcpSipProvider")
|
||||
private SipProviderImpl tcpSipProvider;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
@Qualifier(value="udpSipProvider")
|
||||
private SipProviderImpl udpSipProvider;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private SubscribeHolder subscribeHolder;
|
||||
|
||||
@ -81,6 +71,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
Request request = evt.getRequest();
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
@ -90,12 +81,12 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
}
|
||||
String cmd = XmlUtil.getText(rootElement, "CmdType");
|
||||
if (CmdType.MOBILE_POSITION.equals(cmd)) {
|
||||
processNotifyMobilePosition(evt, rootElement);
|
||||
processNotifyMobilePosition(serverTransaction, rootElement);
|
||||
// } else if (CmdType.ALARM.equals(cmd)) {
|
||||
// logger.info("接收到Alarm订阅");
|
||||
// processNotifyAlarm(evt, rootElement);
|
||||
// processNotifyAlarm(serverTransaction, rootElement);
|
||||
} else if (CmdType.CATALOG.equals(cmd)) {
|
||||
processNotifyCatalogList(evt, rootElement);
|
||||
processNotifyCatalogList(serverTransaction, rootElement);
|
||||
} else {
|
||||
logger.info("接收到消息:" + cmd);
|
||||
|
||||
@ -108,7 +99,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
ServerTransaction transaction = getServerTransaction(evt);
|
||||
if (transaction != null) {
|
||||
transaction.sendResponse(response);
|
||||
transaction.getDialog().delete();
|
||||
transaction.terminate();
|
||||
} else {
|
||||
logger.info("processRequest serverTransactionId is null.");
|
||||
@ -123,24 +113,20 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
/**
|
||||
* 处理移动位置订阅消息
|
||||
*/
|
||||
private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) throws SipException {
|
||||
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
||||
private void processNotifyMobilePosition(ServerTransaction serverTransaction, Element rootElement) throws SipException {
|
||||
if (serverTransaction == null) {
|
||||
return;
|
||||
}
|
||||
String platformId = SipUtils.getUserIdFromFromHeader(serverTransaction.getRequest());
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
|
||||
SubscribeInfo subscribeInfo = new SubscribeInfo(serverTransaction, platformId);
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
if (evt.getServerTransaction() == null) {
|
||||
ServerTransaction serverTransaction = "TCP".equalsIgnoreCase(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
|
||||
: udpSipProvider.getNewServerTransaction(evt.getRequest());
|
||||
subscribeInfo.setTransaction(serverTransaction);
|
||||
Dialog dialog = serverTransaction.getDialog();
|
||||
dialog.terminateOnBye(false);
|
||||
subscribeInfo.setDialog(dialog);
|
||||
}
|
||||
|
||||
String sn = XmlUtil.getText(rootElement, "SN");
|
||||
logger.info("[回复 移动位置订阅]: {}", platformId);
|
||||
logger.info("[回复上级的移动位置订阅请求]: {}", platformId);
|
||||
StringBuilder resultXml = new StringBuilder(200);
|
||||
resultXml.append("<?xml version=\"1.0\" ?>\r\n")
|
||||
.append("<Response>\r\n")
|
||||
@ -158,17 +144,19 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
}else {
|
||||
subscribeInfo.setGpsInterval(Integer.parseInt(interval));
|
||||
}
|
||||
|
||||
subscribeInfo.setSn(sn);
|
||||
subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
|
||||
|
||||
}else if (subscribeInfo.getExpires() == 0) {
|
||||
subscribeHolder.removeMobilePositionSubscribe(platformId);
|
||||
}
|
||||
|
||||
try {
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
||||
responseXmlAck(evt, resultXml.toString(), parentPlatform);
|
||||
SIPResponse response = responseXmlAck(serverTransaction, resultXml.toString(), parentPlatform, subscribeInfo.getExpires());
|
||||
if (subscribeInfo.getExpires() == 0) {
|
||||
subscribeHolder.removeMobilePositionSubscribe(platformId);
|
||||
}else {
|
||||
subscribeInfo.setResponse(response);
|
||||
subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
|
||||
}
|
||||
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -178,25 +166,20 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
|
||||
}
|
||||
|
||||
private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException {
|
||||
|
||||
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
||||
private void processNotifyCatalogList(ServerTransaction serverTransaction, Element rootElement) throws SipException {
|
||||
if (serverTransaction == null) {
|
||||
return;
|
||||
}
|
||||
String platformId = SipUtils.getUserIdFromFromHeader(serverTransaction.getRequest());
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
if (platform == null){
|
||||
return;
|
||||
}
|
||||
SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
|
||||
if (evt.getServerTransaction() == null) {
|
||||
ServerTransaction serverTransaction = "TCP".equalsIgnoreCase(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
|
||||
: udpSipProvider.getNewServerTransaction(evt.getRequest());
|
||||
subscribeInfo.setTransaction(serverTransaction);
|
||||
Dialog dialog = serverTransaction.getDialog();
|
||||
dialog.terminateOnBye(false);
|
||||
subscribeInfo.setDialog(dialog);
|
||||
}
|
||||
SubscribeInfo subscribeInfo = new SubscribeInfo(serverTransaction, platformId);
|
||||
|
||||
String sn = XmlUtil.getText(rootElement, "SN");
|
||||
logger.info("[回复 目录订阅]: {}/{}", platformId, deviceId);
|
||||
logger.info("[回复上级的目录订阅请求]: {}/{}", platformId, deviceId);
|
||||
StringBuilder resultXml = new StringBuilder(200);
|
||||
resultXml.append("<?xml version=\"1.0\" ?>\r\n")
|
||||
.append("<Response>\r\n")
|
||||
@ -213,7 +196,13 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
|
||||
}
|
||||
try {
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
||||
responseXmlAck(evt, resultXml.toString(), parentPlatform);
|
||||
SIPResponse response = responseXmlAck(serverTransaction, resultXml.toString(), parentPlatform, subscribeInfo.getExpires());
|
||||
if (subscribeInfo.getExpires() == 0) {
|
||||
subscribeHolder.removeCatalogSubscribe(platformId);
|
||||
}else {
|
||||
subscribeInfo.setResponse(response);
|
||||
subscribeHolder.putCatalogSubscribe(platformId, subscribeInfo);
|
||||
}
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.*;
|
||||
import javax.sip.message.Response;
|
||||
@ -65,9 +66,12 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
|
||||
// 先从会话内查找
|
||||
SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null);
|
||||
if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题
|
||||
|
||||
// 兼容海康 媒体通知 消息from字段不是设备ID的问题
|
||||
if (ssrcTransaction != null) {
|
||||
deviceId = ssrcTransaction.getDeviceId();
|
||||
}
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
// 查询设备是否存在
|
||||
Device device = redisCatchStorage.getDevice(deviceId);
|
||||
// 查询上级平台是否存在
|
||||
@ -86,7 +90,7 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
}
|
||||
if (device == null && parentPlatform == null) {
|
||||
// 不存在则回复404
|
||||
responseAck(evt, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
||||
responseAck(serverTransaction, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
||||
logger.warn("[设备未找到 ]: {}", deviceId);
|
||||
if (sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()) != null){
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new DeviceNotFoundEvent(evt.getDialog()));
|
||||
@ -101,14 +105,14 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
String streamId = sendRtpItem.getStreamId();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
responseAck(evt, Response.NOT_FOUND, "stream " + streamId + " not found");
|
||||
responseAck(serverTransaction, Response.NOT_FOUND, "stream " + streamId + " not found");
|
||||
return;
|
||||
}
|
||||
Device device1 = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playbackControlCmd(device1,streamInfo,new String(evt.getRequest().getRawContent()),eventResult -> {
|
||||
// 失败的回复
|
||||
try {
|
||||
responseAck(evt, eventResult.statusCode, eventResult.msg);
|
||||
responseAck(serverTransaction, eventResult.statusCode, eventResult.msg);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -119,7 +123,7 @@ public class InfoRequestProcessor extends SIPRequestProcessorParent implements I
|
||||
}, eventResult -> {
|
||||
// 成功的回复
|
||||
try {
|
||||
responseAck(evt, eventResult.statusCode);
|
||||
responseAck(serverTransaction, eventResult.statusCode);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -23,6 +23,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CSeqHeader;
|
||||
@ -79,6 +80,9 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
||||
if (ssrcTransaction != null) {
|
||||
deviceId = ssrcTransaction.getDeviceId();
|
||||
}
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
|
||||
// 查询设备是否存在
|
||||
Device device = redisCatchStorage.getDevice(deviceId);
|
||||
// 查询上级平台是否存在
|
||||
@ -98,7 +102,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
||||
}
|
||||
if (device == null && parentPlatform == null) {
|
||||
// 不存在则回复404
|
||||
responseAck(evt, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
||||
responseAck(serverTransaction, Response.NOT_FOUND, "device "+ deviceId +" not found");
|
||||
logger.warn("[设备未找到 ]: {}", deviceId);
|
||||
if (sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()) != null){
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new DeviceNotFoundEvent(evt.getDialog()));
|
||||
@ -110,13 +114,13 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
||||
rootElement = getRootElement(evt);
|
||||
if (rootElement == null) {
|
||||
logger.error("处理MESSAGE请求 未获取到消息体{}", evt.getRequest());
|
||||
responseAck(evt, Response.BAD_REQUEST, "content is null");
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, "content is null");
|
||||
return;
|
||||
}
|
||||
} catch (DocumentException e) {
|
||||
logger.warn("解析XML消息内容异常", e);
|
||||
// 不存在则回复404
|
||||
responseAck(evt, Response.BAD_REQUEST, e.getMessage());
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
String name = rootElement.getName();
|
||||
IMessageHandler messageHandler = messageHandlerMap.get(name);
|
||||
@ -129,7 +133,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
||||
}else {
|
||||
// 不支持的message
|
||||
// 不存在则回复415
|
||||
responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE, "Unsupported message type, must Control/Notify/Query/Response");
|
||||
responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE, "Unsupported message type, must Control/Notify/Query/Response");
|
||||
}
|
||||
}
|
||||
} catch (SipException e) {
|
||||
|
@ -61,6 +61,8 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
|
||||
@Override
|
||||
public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
|
||||
// 此处是上级发出的DeviceControl指令
|
||||
String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
|
||||
String channelId = getText(rootElement, "DeviceID");
|
||||
@ -107,7 +109,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
|
||||
Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
|
||||
if (deviceForPlatform == null) {
|
||||
try {
|
||||
responseAck(evt, Response.NOT_FOUND);
|
||||
responseAck(serverTransaction, Response.NOT_FOUND);
|
||||
return;
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
@ -120,7 +122,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
|
||||
cmder.fronEndCmd(deviceForPlatform, channelId, cmdString, eventResult -> {
|
||||
// 失败的回复
|
||||
try {
|
||||
responseAck(evt, eventResult.statusCode, eventResult.msg);
|
||||
responseAck(serverTransaction, eventResult.statusCode, eventResult.msg);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -131,7 +133,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
|
||||
}, eventResult -> {
|
||||
// 成功的回复
|
||||
try {
|
||||
responseAck(evt, eventResult.statusCode);
|
||||
responseAck(serverTransaction, eventResult.statusCode);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -77,7 +77,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
|
||||
logger.info("[收到报警通知]设备:{}", device.getDeviceId());
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
logger.error("[收到报警通知], 回复200OK失败", e);
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
|
||||
if (sipConfig.isAlarm()) {
|
||||
deviceAlarmService.add(deviceAlarm);
|
||||
}
|
||||
|
||||
logger.info("[收到报警通知]内容:{}", JSONObject.toJSON(deviceAlarm));
|
||||
if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) {
|
||||
publisher.deviceAlarmEventPublish(deviceAlarm);
|
||||
}
|
||||
@ -190,7 +190,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
|
||||
logger.info("收到来自平台[{}]的报警通知", parentPlatform.getServerGBId());
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -69,7 +69,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
|
||||
}
|
||||
device.setKeepaliveTime(DateUtil.getNow());
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
if (device.getOnline() == 1) {
|
||||
deviceService.updateDevice(device);
|
||||
}else {
|
||||
|
@ -66,7 +66,7 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i
|
||||
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -65,7 +65,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
|
||||
rootElement = getRootElement(evt, device.getCharset());
|
||||
if (rootElement == null) {
|
||||
logger.warn("[ 移动设备位置数据通知 ] content cannot be null, {}", evt.getRequest());
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(getServerTransaction(evt), Response.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
MobilePosition mobilePosition = new MobilePosition();
|
||||
@ -116,7 +116,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
|
||||
}
|
||||
storager.updateChannelPosition(deviceChannel);
|
||||
//回复 200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
|
||||
// 发送redis消息。 通知位置信息的变化
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
@ -58,7 +58,7 @@ public class AlarmQueryMessageHandler extends SIPRequestProcessorParent implemen
|
||||
|
||||
logger.info("不支持alarm查询");
|
||||
try {
|
||||
responseAck(evt, Response.NOT_FOUND, "not support alarm query");
|
||||
responseAck(getServerTransaction(evt), Response.NOT_FOUND, "not support alarm query");
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -66,7 +66,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
|
||||
FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
||||
try {
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
Element snElement = rootElement.element("SN");
|
||||
String sn = snElement.getText();
|
||||
// 准备回复通道信息
|
||||
|
@ -48,7 +48,7 @@ public class DeviceInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
||||
try {
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -61,7 +61,7 @@ public class DeviceStatusQueryMessageHandler extends SIPRequestProcessorParent i
|
||||
FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.message.Response;
|
||||
@ -68,7 +69,7 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
|
||||
|
||||
FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
Element snElement = rootElement.element("SN");
|
||||
int sn = Integer.parseInt(snElement.getText());
|
||||
Element deviceIDElement = rootElement.element("DeviceID");
|
||||
@ -108,7 +109,7 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(endTime), sn, secrecy, type, (eventResult -> {
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -119,7 +120,7 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
}),(eventResult -> {
|
||||
// 查询失败
|
||||
try {
|
||||
responseAck(evt, eventResult.statusCode, eventResult.msg);
|
||||
responseAck(serverTransaction, eventResult.statusCode, eventResult.msg);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -132,7 +133,7 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
}else if (channelSources.get(1).getCount() > 0) { // 直播流
|
||||
// TODO
|
||||
try {
|
||||
responseAck(evt, Response.NOT_IMPLEMENTED); // 回复未实现
|
||||
responseAck(serverTransaction, Response.NOT_IMPLEMENTED); // 回复未实现
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
@ -142,7 +143,7 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
|
||||
}
|
||||
}else { // 错误的请求
|
||||
try {
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -18,6 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
@ -46,8 +47,9 @@ public class BroadcastResponseMessageHandler extends SIPRequestProcessorParent i
|
||||
try {
|
||||
String channelId = getText(rootElement, "DeviceID");
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + device.getDeviceId() + channelId;
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
// 此处是对本平台发出Broadcast指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
@ -87,7 +88,8 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
||||
taskQueue.offer(new HandlerCatchData(evt, device, element));
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
if (!taskQueueHandlerRun) {
|
||||
taskQueueHandlerRun = true;
|
||||
taskExecutor.execute(()-> {
|
||||
@ -103,7 +105,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
|
||||
Element sumNumElement = rootElement.element("SumNum");
|
||||
Element snElement = rootElement.element("SN");
|
||||
if (snElement == null || sumNumElement == null || deviceListElement == null) {
|
||||
responseAck(take.getEvt(), Response.BAD_REQUEST, "xml error");
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, "xml error");
|
||||
continue;
|
||||
}
|
||||
int sumNum = Integer.parseInt(sumNumElement.getText());
|
||||
|
@ -52,7 +52,7 @@ public class ConfigDownloadResponseMessageHandler extends SIPRequestProcessorPar
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + device.getDeviceId() + channelId;
|
||||
try {
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(element, json);
|
||||
|
@ -46,7 +46,7 @@ public class DeviceControlResponseMessageHandler extends SIPRequestProcessorPare
|
||||
public void handForDevice(RequestEvent evt, Device device, Element element) {
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
JSONObject json = new JSONObject();
|
||||
String channelId = getText(element, "DeviceID");
|
||||
XmlUtil.node2Json(element, json);
|
||||
|
@ -25,6 +25,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
@ -74,11 +75,12 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
|
||||
logger.warn("[接收到DeviceInfo应答消息,但是设备已经离线]:" + (device != null ? device.getDeviceId():"" ));
|
||||
return;
|
||||
}
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
try {
|
||||
rootElement = getRootElement(evt, device.getCharset());
|
||||
if (rootElement == null) {
|
||||
logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null, {}", evt.getRequest());
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
@ -99,7 +101,7 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
|
||||
msg.setData(device);
|
||||
deferredResultHolder.invokeAllResult(msg);
|
||||
// 回复200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -59,7 +59,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen
|
||||
}
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
} catch (SipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -25,6 +25,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
@ -64,11 +65,13 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
|
||||
@Override
|
||||
public void handForDevice(RequestEvent evt, Device device, Element rootElement) {
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
|
||||
try {
|
||||
rootElement = getRootElement(evt, device.getCharset());
|
||||
if (rootElement == null) {
|
||||
logger.warn("[ 移动设备位置数据查询回复 ] content cannot be null, {}", evt.getRequest());
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
MobilePosition mobilePosition = new MobilePosition();
|
||||
@ -130,7 +133,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
|
||||
jsonObject.put("speed", mobilePosition.getSpeed());
|
||||
redisCatchStorage.sendMobilePositionMsg(jsonObject);
|
||||
//回复 200 OK
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.ServerTransaction;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
@ -51,10 +52,13 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent
|
||||
public void handForDevice(RequestEvent evt, Device device, Element element) {
|
||||
Element rootElement = null;
|
||||
try {
|
||||
|
||||
ServerTransaction serverTransaction = getServerTransaction(evt);
|
||||
|
||||
rootElement = getRootElement(evt, device.getCharset());
|
||||
if (rootElement == null) {
|
||||
logger.warn("[ 设备预置位查询应答 ] content cannot be null, {}", evt.getRequest());
|
||||
responseAck(evt, Response.BAD_REQUEST);
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
Element presetListNumElement = rootElement.element("PresetList");
|
||||
@ -63,7 +67,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent
|
||||
String deviceId = getText(rootElement, "DeviceID");
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId;
|
||||
if (snElement == null || presetListNumElement == null) {
|
||||
responseAck(evt, Response.BAD_REQUEST, "xml error");
|
||||
responseAck(serverTransaction, Response.BAD_REQUEST, "xml error");
|
||||
return;
|
||||
}
|
||||
int sumNum = Integer.parseInt(presetListNumElement.attributeValue("Num"));
|
||||
@ -93,7 +97,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent
|
||||
requestMessage.setKey(key);
|
||||
requestMessage.setData(presetQuerySipReqList);
|
||||
deferredResultHolder.invokeAllResult(requestMessage);
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(serverTransaction, Response.OK);
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidArgumentException e) {
|
||||
|
@ -72,7 +72,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
|
||||
|
||||
// 回复200 OK
|
||||
try {
|
||||
responseAck(evt, Response.OK);
|
||||
responseAck(getServerTransaction(evt), Response.OK);
|
||||
taskQueue.offer(new HandlerCatchData(evt, device, rootElement));
|
||||
if (!taskQueueHandlerRun) {
|
||||
taskQueueHandlerRun = true;
|
||||
|
@ -7,6 +7,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcesso
|
||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||
import com.genersoft.iot.vmp.utils.GitUtil;
|
||||
import gov.nist.javax.sip.ResponseEventExt;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import gov.nist.javax.sip.stack.SIPClientTransaction;
|
||||
import gov.nist.javax.sip.stack.SIPDialog;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -78,7 +80,7 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract {
|
||||
// 下发ack
|
||||
if (statusCode == Response.OK) {
|
||||
ResponseEventExt event = (ResponseEventExt)evt;
|
||||
SIPDialog dialog = (SIPDialog)evt.getDialog();
|
||||
SIPDialog dialog = new SIPDialog((SIPClientTransaction) event.getClientTransaction(), (SIPResponse) event.getResponse());
|
||||
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
|
||||
Request reqAck = dialog.createAck(cseq.getSeqNumber());
|
||||
SipURI requestURI = (SipURI) reqAck.getRequestURI();
|
||||
|
@ -103,7 +103,7 @@ public class ZLMHttpHookListener {
|
||||
@PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8")
|
||||
public JSONObject onServerKeepalive(@RequestBody JSONObject json){
|
||||
|
||||
logger.info("[ ZLM HOOK ] on_server_keepalive API调用,参数:" + json.toString());
|
||||
logger.info("[ ZLM HOOK ]on_server_keepalive API调用,参数:" + json.toString());
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive);
|
||||
if (subscribes != null && subscribes.size() > 0) {
|
||||
@ -453,6 +453,7 @@ public class ZLMHttpHookListener {
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
// 如果正在给上级推送,则发送bye
|
||||
|
||||
|
||||
}else{
|
||||
streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
|
||||
if (streamInfo != null) {
|
||||
@ -509,6 +510,19 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!regist) {
|
||||
List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByStream(stream);
|
||||
if (sendRtpItems.size() > 0) {
|
||||
for (SendRtpItem sendRtpItem : sendRtpItems) {
|
||||
if (sendRtpItem.getApp().equals(app)) {
|
||||
String platformId = sendRtpItem.getPlatformId();
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
|
||||
commanderFroPlatform.streamByeCmd(platform, sendRtpItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject ret = new JSONObject();
|
||||
|
@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -83,7 +84,11 @@ public class ZLMMediaListManager {
|
||||
}
|
||||
if (transform != null) {
|
||||
if (getChannelOnlineEventLister(transform.getApp(), transform.getStream()) != null) {
|
||||
try {
|
||||
getChannelOnlineEventLister(transform.getApp(), transform.getStream()).run(transform.getApp(), transform.getStream(), transform.getServerId());
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
removedChannelOnlineEventLister(transform.getApp(), transform.getStream());
|
||||
}
|
||||
}
|
||||
@ -95,7 +100,11 @@ public class ZLMMediaListManager {
|
||||
// 查看推流状态
|
||||
if (zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream)) {
|
||||
if (getChannelOnlineEventLister(app, stream) != null) {
|
||||
try {
|
||||
getChannelOnlineEventLister(app, stream).run(app, stream, mediaServerId);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
removedChannelOnlineEventLister(app, stream);
|
||||
}
|
||||
}
|
||||
|
@ -330,12 +330,12 @@ public class ZLMRTPServerFactory {
|
||||
Boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param);
|
||||
if (jsonObject == null) {
|
||||
logger.error("停止RTP推流失败: 请检查ZLM服务");
|
||||
logger.error("[停止RTP推流] 失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
result= true;
|
||||
logger.info("停止RTP推流成功");
|
||||
logger.info("[停止RTP推流] 成功");
|
||||
} else {
|
||||
logger.error("停止RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param));
|
||||
logger.error("[停止RTP推流] 失败: {}, 参数:{}->\r\n{}",jsonObject.getString("msg"),JSONObject.toJSON(param), jsonObject);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -137,8 +137,6 @@ public class ZlmHttpHookSubscribe {
|
||||
@Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次
|
||||
public void execute(){
|
||||
|
||||
logger.info("[hook订阅] 清理");
|
||||
|
||||
Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5));
|
||||
int total = 0;
|
||||
for (HookType hookType : allSubscribes.keySet()) {
|
||||
@ -153,6 +151,5 @@ public class ZlmHttpHookSubscribe {
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("[hook订阅] 清理结束,共清理{}条过期数据", total);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.genersoft.iot.vmp.media.zlm.dto;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public interface ChannelOnlineEvent {
|
||||
|
||||
void run(String app, String stream, String serverId);
|
||||
void run(String app, String stream, String serverId) throws ParseException;
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 国标平台的业务类
|
||||
* @author lin
|
||||
@ -42,4 +47,10 @@ public interface IPlatformService {
|
||||
* @param parentPlatform
|
||||
*/
|
||||
void login(ParentPlatform parentPlatform);
|
||||
|
||||
/**
|
||||
* 向上级平台发送位置订阅
|
||||
* @param platformId 平台
|
||||
*/
|
||||
void sendNotifyMobilePosition(String platformId);
|
||||
}
|
||||
|
@ -73,8 +73,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
||||
result = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
|
||||
// TODO 后续给平台增加控制开关以控制是否响应目录订阅
|
||||
List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
|
||||
if (deviceChannelList != null) {
|
||||
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -83,7 +85,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
||||
List<DeviceChannel> deviceChannelList = new ArrayList<>();
|
||||
if (channelReduces.size() > 0){
|
||||
PlatformCatalog catalog = catalogManager.select(catalogId);
|
||||
if (catalog == null && !catalogId.equals(platform.getServerGBId())) {
|
||||
if (catalog == null && !catalogId.equals(platform.getDeviceGBId())) {
|
||||
logger.warn("未查询到目录{}的信息", catalogId);
|
||||
return null;
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IPlatformService;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@ -57,6 +56,9 @@ public class PlatformServiceImpl implements IPlatformService {
|
||||
@Autowired
|
||||
private SubscribeHolder subscribeHolder;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@ -228,4 +230,34 @@ public class PlatformServiceImpl implements IPlatformService {
|
||||
60*1000);
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNotifyMobilePosition(String platformId) {
|
||||
ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
|
||||
if (subscribe != null) {
|
||||
|
||||
// TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
|
||||
List<DeviceChannel> gbStreams = gbStreamMapper.queryGbStreamListInPlatform(platform.getServerGBId());
|
||||
if (gbStreams.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (DeviceChannel deviceChannel : gbStreams) {
|
||||
String gbId = deviceChannel.getChannelId();
|
||||
GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
|
||||
// 无最新位置不发送
|
||||
if (gpsMsgInfo != null) {
|
||||
// 经纬度都为0不发送
|
||||
if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
|
||||
continue;
|
||||
}
|
||||
// 发送GPS消息
|
||||
commanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -86,7 +87,7 @@ public class RedisGbPlayMsgListener implements MessageListener {
|
||||
|
||||
|
||||
public interface PlayMsgCallback{
|
||||
void handler(ResponseSendItemMsg responseSendItemMsg);
|
||||
void handler(ResponseSendItemMsg responseSendItemMsg) throws ParseException;
|
||||
}
|
||||
|
||||
public interface PlayMsgCallbackForStartSendRtpStream{
|
||||
@ -134,7 +135,11 @@ public class RedisGbPlayMsgListener implements MessageListener {
|
||||
PlayMsgCallback playMsgCallback = callbacks.get(key);
|
||||
if (playMsgCallback != null) {
|
||||
callbacksForError.remove(key);
|
||||
try {
|
||||
playMsgCallback.handler(responseSendItemMsg);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ERROR_CODE_MEDIA_SERVER_NOT_FOUND:
|
||||
|
@ -710,14 +710,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
@Override
|
||||
public void sendMobilePositionMsg(JSONObject jsonObject) {
|
||||
String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION;
|
||||
logger.info("[redis发送通知]移动位置 {}: {}", key, jsonObject.toString());
|
||||
logger.info("[redis发送通知] 移动位置 {}: {}", key, jsonObject.toString());
|
||||
RedisUtil.convertAndSend(key, jsonObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStreamPushRequestedMsg(MessageForPushChannel msg) {
|
||||
String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED;
|
||||
logger.info("[redis发送通知]推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream());
|
||||
logger.info("[redis发送通知] 推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream());
|
||||
RedisUtil.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
|
||||
}
|
||||
|
||||
|
@ -413,24 +413,20 @@ public class DeviceQuery {
|
||||
@GetMapping("/{deviceId}/subscribe_info")
|
||||
@Operation(summary = "获取设备的订阅状态")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
public WVPResult<Map<String, String>> getSubscribeInfo(@PathVariable String deviceId) {
|
||||
public WVPResult<Map<String, Integer>> getSubscribeInfo(@PathVariable String deviceId) {
|
||||
Set<String> allKeys = dynamicTask.getAllKeys();
|
||||
Map<String, String> dialogStateMap = new HashMap<>();
|
||||
Map<String, Integer> dialogStateMap = new HashMap<>();
|
||||
for (String key : allKeys) {
|
||||
if (key.startsWith(deviceId)) {
|
||||
ISubscribeTask subscribeTask = (ISubscribeTask)dynamicTask.get(key);
|
||||
DialogState dialogState = subscribeTask.getDialogState();
|
||||
if (dialogState == null) {
|
||||
continue;
|
||||
}
|
||||
if (subscribeTask instanceof CatalogSubscribeTask) {
|
||||
dialogStateMap.put("catalog", dialogState.toString());
|
||||
dialogStateMap.put("catalog", 1);
|
||||
}else if (subscribeTask instanceof MobilePositionSubscribeTask) {
|
||||
dialogStateMap.put("mobilePosition", dialogState.toString());
|
||||
dialogStateMap.put("mobilePosition", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
WVPResult<Map<String, String>> wvpResult = new WVPResult<>();
|
||||
WVPResult<Map<String, Integer>> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setData(dialogStateMap);
|
||||
return wvpResult;
|
||||
|
@ -84,12 +84,13 @@ export default {
|
||||
method: 'get',
|
||||
url: `/api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}`
|
||||
}).then((res)=> {
|
||||
console.log(res)
|
||||
if (res.data.code === 0) {
|
||||
this.streamInfo = res.data.data;
|
||||
if (parseFloat(res.data.progress) == 1) {
|
||||
this.percentage = 100;
|
||||
}else {
|
||||
this.percentage = (res.data.data.progress*100).toFixed(1);
|
||||
this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1);
|
||||
}
|
||||
if (callback)callback();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user