lin
3 years ago
18 changed files with 530 additions and 42 deletions
@ -0,0 +1,8 @@ |
|||
package com.genersoft.iot.vmp.gb28181.bean; |
|||
|
|||
public class CmdType { |
|||
|
|||
public static final String CATALOG = "Catalog"; |
|||
public static final String ALARM = "Alarm"; |
|||
public static final String MOBILE_POSITION = "MobilePosition"; |
|||
} |
@ -0,0 +1,78 @@ |
|||
package com.genersoft.iot.vmp.gb28181.bean; |
|||
|
|||
import javax.sip.RequestEvent; |
|||
import javax.sip.header.*; |
|||
import javax.sip.message.Request; |
|||
|
|||
public class SubscribeInfo { |
|||
|
|||
public SubscribeInfo() { |
|||
} |
|||
|
|||
public SubscribeInfo(RequestEvent evt, String id) { |
|||
this.id = id; |
|||
Request request = evt.getRequest(); |
|||
CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
|||
this.callId = callIdHeader.getCallId(); |
|||
FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME); |
|||
this.fromTag = fromHeader.getTag(); |
|||
ExpiresHeader expiresHeader = (ExpiresHeader)request.getHeader(ExpiresHeader.NAME); |
|||
this.expires = expiresHeader.getExpires(); |
|||
this.event = (EventHeader)request.getHeader(EventHeader.NAME); |
|||
} |
|||
|
|||
private String id; |
|||
private int expires; |
|||
private String callId; |
|||
private EventHeader event; |
|||
private String fromTag; |
|||
private String toTag; |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public int getExpires() { |
|||
return expires; |
|||
} |
|||
|
|||
public String getCallId() { |
|||
return callId; |
|||
} |
|||
|
|||
public EventHeader getEvent() { |
|||
return event; |
|||
} |
|||
|
|||
public String getFromTag() { |
|||
return fromTag; |
|||
} |
|||
|
|||
public void setToTag(String toTag) { |
|||
this.toTag = toTag; |
|||
} |
|||
|
|||
public String getToTag() { |
|||
return toTag; |
|||
} |
|||
|
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public void setExpires(int expires) { |
|||
this.expires = expires; |
|||
} |
|||
|
|||
public void setCallId(String callId) { |
|||
this.callId = callId; |
|||
} |
|||
|
|||
public void setEvent(EventHeader event) { |
|||
this.event = event; |
|||
} |
|||
|
|||
public void setFromTag(String fromTag) { |
|||
this.fromTag = fromTag; |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
package com.genersoft.iot.vmp.gb28181.event.subscribe; |
|||
|
|||
import com.genersoft.iot.vmp.common.VideoManagerConstants; |
|||
import com.genersoft.iot.vmp.conf.DynamicTask; |
|||
import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; |
|||
import com.genersoft.iot.vmp.conf.UserSetup; |
|||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
|||
import org.checkerframework.checker.units.qual.A; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.redis.connection.Message; |
|||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 平台订阅到期事件 |
|||
*/ |
|||
@Component |
|||
public class SubscribeListenerForPlatform extends RedisKeyExpirationEventMessageListener { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(SubscribeListenerForPlatform.class); |
|||
|
|||
@Autowired |
|||
private UserSetup userSetup; |
|||
|
|||
@Autowired |
|||
private DynamicTask dynamicTask; |
|||
|
|||
public SubscribeListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { |
|||
super(listenerContainer, userSetup); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 监听失效的key |
|||
* @param message |
|||
* @param pattern |
|||
*/ |
|||
@Override |
|||
public void onMessage(Message message, byte[] pattern) { |
|||
// 获取失效的key
|
|||
String expiredKey = message.toString(); |
|||
logger.debug(expiredKey); |
|||
// 订阅到期
|
|||
String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() + "_"; |
|||
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) { |
|||
// 取消定时任务
|
|||
dynamicTask.stopCron(expiredKey); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
package com.genersoft.iot.vmp.gb28181.task; |
|||
|
|||
import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
|||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
|||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; |
|||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
|||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
|||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
|||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.List; |
|||
|
|||
public class GPSSubscribeTask implements Runnable{ |
|||
|
|||
private IRedisCatchStorage redisCatchStorage; |
|||
private IVideoManagerStorager storager; |
|||
private ISIPCommanderForPlatform sipCommanderForPlatform; |
|||
private String platformId; |
|||
private String sn; |
|||
private String key; |
|||
|
|||
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
|
|||
public GPSSubscribeTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorager storager, String platformId, String sn, String key) { |
|||
this.redisCatchStorage = redisCatchStorage; |
|||
this.storager = storager; |
|||
this.platformId = platformId; |
|||
this.sn = sn; |
|||
this.key = key; |
|||
this.sipCommanderForPlatform = sipCommanderForPlatform; |
|||
} |
|||
|
|||
@Override |
|||
public void run() { |
|||
|
|||
SubscribeInfo subscribe = redisCatchStorage.getSubscribe(key); |
|||
if (subscribe != null) { |
|||
System.out.println("发送GPS消息"); |
|||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId); |
|||
if (parentPlatform == null || parentPlatform.isStatus()) { |
|||
// TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
|
|||
List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(platformId); |
|||
if (gbStreams.size() > 0) { |
|||
for (GbStream gbStream : gbStreams) { |
|||
String gbId = gbStream.getGbId(); |
|||
GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); |
|||
if (gpsMsgInfo != null && gbStream.isStatus()) { |
|||
// 发送GPS消息
|
|||
sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue