648540858
2022-08-23 8f7e8efc981cf68a3067fb3421fdfbbf6f6275ab
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -32,6 +32,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.sip.*;
@@ -675,6 +676,46 @@
      streamByeCmd(deviceId, channelId, stream, callId, null);
   }
   @Override
   public void streamByeCmd(SIPDialog dialog, String channelId, SIPRequest request, SipSubscribe.Event okEvent) throws SipException, ParseException, InvalidArgumentException {
      Request byeRequest = dialog.createRequest(Request.BYE);
      SipURI byeURI = (SipURI) byeRequest.getRequestURI();
      byeURI.setHost(request.getRemoteAddress().getHostAddress());
      byeURI.setPort(request.getRemotePort());
      byeURI.setUser(channelId);
      ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
      String protocol = viaHeader.getTransport().toUpperCase();
      viaHeader.setRPort();
      // 增加Contact header
      Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
      byeRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
      List<String> agentParam = new ArrayList<>();
      agentParam.add("wvp-pro");
      // TODO 添加版本信息以及日期
      UserAgentHeader userAgentHeader = null;
      try {
         userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
      } catch (ParseException e) {
         throw new RuntimeException(e);
      }
      byeRequest.addHeader(userAgentHeader);
      ClientTransaction clientTransaction = null;
      if("TCP".equals(protocol)) {
         clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest);
      } else if("UDP".equals(protocol)) {
         clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest);
      }
      CallIdHeader callIdHeader = (CallIdHeader) byeRequest.getHeader(CallIdHeader.NAME);
      if (okEvent != null) {
         sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
      }
      CSeqHeader cSeqHeader = (CSeqHeader)byeRequest.getHeader(CSeqHeader.NAME);
      cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ());
      dialog.sendRequest(clientTransaction);
   }
   /**
    * 视频流停止
    */
@@ -819,7 +860,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -922,16 +963,16 @@
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
         if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
         if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
            cmdXml.append("<Info>\r\n");
         }
         if (!StringUtils.isEmpty(alarmMethod)) {
         if (!ObjectUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!StringUtils.isEmpty(alarmType)) {
         if (!ObjectUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
         if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
            cmdXml.append("</Info>\r\n");
         }
         cmdXml.append("</Control>\r\n");
@@ -965,7 +1006,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1004,7 +1045,7 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1073,13 +1114,13 @@
         cmdXml.append("<Control>\r\n");
         cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
         }
         cmdXml.append("<BasicParam>\r\n");
         if (!StringUtils.isEmpty(name)) {
         if (!ObjectUtils.isEmpty(name)) {
            cmdXml.append("<Name>" + name + "</Name>\r\n");
         }
         if (NumericUtil.isInteger(expiration)) {
@@ -1289,22 +1330,22 @@
         cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         if (!StringUtils.isEmpty(startPriority)) {
         if (!ObjectUtils.isEmpty(startPriority)) {
            cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
         }
         if (!StringUtils.isEmpty(endPriority)) {
         if (!ObjectUtils.isEmpty(endPriority)) {
            cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
         }
         if (!StringUtils.isEmpty(alarmMethod)) {
         if (!ObjectUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!StringUtils.isEmpty(alarmType)) {
         if (!ObjectUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!StringUtils.isEmpty(startTime)) {
         if (!ObjectUtils.isEmpty(startTime)) {
            cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
         }
         if (!StringUtils.isEmpty(endTime)) {
         if (!ObjectUtils.isEmpty(endTime)) {
            cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
         }
         cmdXml.append("</Query>\r\n");
@@ -1339,7 +1380,7 @@
         cmdXml.append("<Query>\r\n");
         cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1375,7 +1416,7 @@
         cmdXml.append("<Query>\r\n");
         cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
@@ -1506,22 +1547,22 @@
         cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
         cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
         cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         if (!StringUtils.isEmpty(startPriority)) {
         if (!ObjectUtils.isEmpty(startPriority)) {
            cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
         }
         if (!StringUtils.isEmpty(endPriority)) {
         if (!ObjectUtils.isEmpty(endPriority)) {
            cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
         }
         if (!StringUtils.isEmpty(alarmMethod)) {
         if (!ObjectUtils.isEmpty(alarmMethod)) {
            cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
         }
         if (!StringUtils.isEmpty(alarmType)) {
         if (!ObjectUtils.isEmpty(alarmType)) {
            cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
         }
         if (!StringUtils.isEmpty(startTime)) {
         if (!ObjectUtils.isEmpty(startTime)) {
            cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
         }
         if (!StringUtils.isEmpty(endTime)) {
         if (!ObjectUtils.isEmpty(endTime)) {
            cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
         }
         cmdXml.append("</Query>\r\n");
@@ -1602,7 +1643,7 @@
         dragXml.append("<Control>\r\n");
         dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
         dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
         if (StringUtils.isEmpty(channelId)) {
         if (ObjectUtils.isEmpty(channelId)) {
            dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
         } else {
            dragXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");