648540858
2021-11-02 b1e5a869167112869b9fd85c0830686edb306bf5
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
@@ -9,6 +9,7 @@
import javax.sip.*;
import javax.sip.header.CallIdHeader;
import javax.sip.header.Header;
import javax.sip.message.Response;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
@@ -93,15 +94,15 @@
      ListeningPoint tcpListeningPoint = null;
      SipProviderImpl tcpSipProvider  = null;
      try {
         tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "TCP");
         tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "TCP");
         tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint);
         tcpSipProvider.addSipListener(this);
         logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "}");
         logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "}");
      } catch (TransportNotSupportedException e) {
         e.printStackTrace();
      } catch (InvalidArgumentException e) {
         logger.error("无法使用 [ {}:{} ]作为SIP[ TCP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
               , sipConfig.getMonitorIp(), sipConfig.getSipPort());
               , sipConfig.getMonitorIp(), sipConfig.getPort());
      } catch (TooManyListenersException e) {
         e.printStackTrace();
      } catch (ObjectInUseException e) {
@@ -116,7 +117,7 @@
      ListeningPoint udpListeningPoint = null;
      SipProviderImpl udpSipProvider = null;
      try {
         udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP");
         udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "UDP");
         udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint);
         udpSipProvider.addSipListener(this);
//         udpSipProvider.setAutomaticDialogSupportEnabled(false);
@@ -124,13 +125,13 @@
         e.printStackTrace();
      } catch (InvalidArgumentException e) {
         logger.error("无法使用 [ {}:{} ]作为SIP[ UDP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
               , sipConfig.getMonitorIp(), sipConfig.getSipPort());
               , sipConfig.getMonitorIp(), sipConfig.getPort());
      } catch (TooManyListenersException e) {
         e.printStackTrace();
      } catch (ObjectInUseException e) {
         e.printStackTrace();
      }
      logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "]");
      logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "]");
      return udpSipProvider;
   }
@@ -168,7 +169,8 @@
            if (callIdHeader != null) {
               SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());
               if (subscribe != null) {
                  subscribe.response(evt);
                  SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt);
                  subscribe.response(eventResult);
               }
            }
         }
@@ -181,7 +183,8 @@
            if (callIdHeader != null) {
               SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
               if (subscribe != null) {
                  subscribe.response(evt);
                  SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(evt);
                  subscribe.response(eventResult);
               }
            }
         }
@@ -204,7 +207,11 @@
   @Override
   public void processTimeout(TimeoutEvent timeoutEvent) {
      // TODO Auto-generated method stub
      CallIdHeader callIdHeader = timeoutEvent.getClientTransaction().getDialog().getCallId();
      String callId = callIdHeader.getCallId();
      SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
      SipSubscribe.EventResult<TimeoutEvent> timeoutEventEventResult = new SipSubscribe.EventResult<>(timeoutEvent);
      errorSubscribe.response(timeoutEventEventResult);
   }
   /**
@@ -220,6 +227,7 @@
   @Override
   public void processIOException(IOExceptionEvent exceptionEvent) {
      // TODO Auto-generated method stub
   }
   /**
@@ -235,6 +243,11 @@
   @Override
   public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
      // TODO Auto-generated method stub
//      CallIdHeader callIdHeader = transactionTerminatedEvent.getClientTransaction().getDialog().getCallId();
//      String callId = callIdHeader.getCallId();
//      SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
//      SipSubscribe.EventResult<TransactionTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(transactionTerminatedEvent);
//      errorSubscribe.response(eventResult);
   }
   /**
@@ -250,6 +263,11 @@
   @Override
   public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
      // TODO Auto-generated method stub
//      CallIdHeader callIdHeader = dialogTerminatedEvent.getDialog().getCallId();
//      String callId = callIdHeader.getCallId();
//      SipSubscribe.Event errorSubscribe = sipSubscribe.getErrorSubscribe(callId);
//      SipSubscribe.EventResult<DialogTerminatedEvent> eventResult = new SipSubscribe.EventResult<>(dialogTerminatedEvent);
//      errorSubscribe.response(eventResult);
   }