648540858
2022-02-24 a42dda2bd3cc1cf8c20cc61e7ad9211eadecbaf3
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
@@ -1,12 +1,14 @@
package com.genersoft.iot.vmp.gb28181.event;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.sip.*;
import javax.sip.header.CallIdHeader;
import javax.sip.message.Response;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
@@ -24,7 +26,8 @@
    private Map<String, Date> timeSubscribes = new ConcurrentHashMap<>();
//    @Scheduled(cron="*/5 * * * * ?")   //每五秒执行一次
    @Scheduled(cron="0 * */1 * * ?")   //每小时执行一次
//    @Scheduled(fixedRate= 100 * 60 * 60 )
    @Scheduled(cron="0 0 * * * ?")   //每小时执行一次, 每个整点
    public void execute(){
        logger.info("[定时任务] 清理过期的订阅信息");
        Calendar calendar = Calendar.getInstance();
@@ -59,11 +62,15 @@
            this.event = event;
            if (event instanceof ResponseEvent) {
                ResponseEvent responseEvent = (ResponseEvent)event;
               this.type = "response";
               this.msg = responseEvent.getResponse().getReasonPhrase();
               this.statusCode = responseEvent.getResponse().getStatusCode();
               this.callId = responseEvent.getDialog().getCallId().getCallId();
               this.dialog = responseEvent.getDialog();
                Response response = responseEvent.getResponse();
                this.dialog = responseEvent.getDialog();
                this.type = "response";
                if (response != null) {
                    this.msg = response.getReasonPhrase();
                    this.statusCode = response.getStatusCode();
                }
                this.callId = ((CallIdHeader)response.getHeader(CallIdHeader.NAME)).getCallId();
            }else if (event instanceof TimeoutEvent) {
                TimeoutEvent timeoutEvent = (TimeoutEvent)event;
                this.type = "timeout";
@@ -85,6 +92,13 @@
                this.statusCode = -1024;
                this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId();
                this.dialog = dialogTerminatedEvent.getDialog();
            }else if (event instanceof DeviceNotFoundEvent) {
                DeviceNotFoundEvent deviceNotFoundEvent = (DeviceNotFoundEvent)event;
                this.type = "deviceNotFoundEvent";
                this.msg = "设备未找到";
                this.statusCode = -1024;
                this.callId = deviceNotFoundEvent.getDialog().getCallId().getCallId();
                this.dialog = deviceNotFoundEvent.getDialog();
            }
        }
    }