From dd986dcbdde5aa9b2864863b769ad0c033a2fb77 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 18 Oct 2022 14:30:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=9B=BD=E6=A0=87=E7=BA=A7?= =?UTF-8?q?=E8=81=94=E4=B8=ADServerTransaction=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/impl/SIPCommanderFroPlatform.java | 97 +++++-------------- 1 file changed, 23 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 4b67c1b2..8f0f6c72 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -3,6 +3,7 @@ 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.SIPSender; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; @@ -54,21 +55,11 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { @Autowired private ZLMRTPServerFactory zlmrtpServerFactory; - @Lazy - @Autowired - @Qualifier(value="tcpSipProvider") - private SipProviderImpl tcpSipProvider; - - @Lazy - @Autowired - @Qualifier(value="udpSipProvider") - private SipProviderImpl udpSipProvider; - @Autowired private SipFactory sipFactory; @Autowired - private SubscribeHolder subscribeHolder; + private SIPSender sipSender; @Override public void register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException { @@ -85,13 +76,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean registerAgain, boolean isRegister) throws SipException, InvalidArgumentException, ParseException { Request request; if (!registerAgain ) { - CallIdHeader callIdHeader = null; - if(parentPlatform.getTransport().equalsIgnoreCase("TCP")) { - callIdHeader = tcpSipProvider.getNewCallId(); - } - if(parentPlatform.getTransport().equalsIgnoreCase("UDP")) { - callIdHeader = udpSipProvider.getNewCallId(); - } + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(), SipUtils.getNewFromTag(), @@ -113,12 +98,11 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { }); }else { - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); request = headerProviderPlatformProvider.createRegisterRequest(parentPlatform, SipUtils.getNewFromTag(), null, callId, www, callIdHeader, isRegister); } - transmitRequest(parentPlatform, request, null, okEvent); + sipSender.transmitRequest( request, null, okEvent); } @Override @@ -133,8 +117,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { keepaliveXml.append("OK\r\n"); keepaliveXml.append("\r\n"); - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest( parentPlatform, @@ -142,39 +125,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request, errorEvent, okEvent); + sipSender.transmitRequest( request, errorEvent, okEvent); return callIdHeader.getCallId(); } - private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException { - transmitRequest(parentPlatform, request, null, null); - } - - private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent) throws SipException { - transmitRequest(parentPlatform, request, errorEvent, null); - } - - private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException { - logger.debug("\n发送消息:\n{}", request); - if("TCP".equalsIgnoreCase(parentPlatform.getTransport())) { - tcpSipProvider.sendRequest(request); - - } else if("UDP".equalsIgnoreCase(parentPlatform.getTransport())) { - udpSipProvider.sendRequest(request); - } - - CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); - // 添加错误订阅 - if (errorEvent != null) { - sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent); - } - // 添加订阅 - if (okEvent != null) { - sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent); - } - - } - /** * 向上级回复通道信息 * @param channel 通道信息 @@ -194,11 +148,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { String catalogXml = getCatalogXml(channels, sn, parentPlatform, size); // callid - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request); + sipSender.transmitRequest( request); } @@ -281,11 +234,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { } String catalogXml = getCatalogXml(deviceChannels, sn, parentPlatform, channels.size()); // callid - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request, null, eventResult -> { + sipSender.transmitRequest( request, null, eventResult -> { int indexNext = index + parentPlatform.getCatalogGroup(); try { sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext); @@ -321,11 +273,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { deviceInfoXml.append("OK\r\n"); deviceInfoXml.append("\r\n"); - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceInfoXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request); + sipSender.transmitRequest( request); } /** @@ -352,11 +303,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { deviceStatusXml.append("OK\r\n"); deviceStatusXml.append("\r\n"); - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request); + sipSender.transmitRequest( request); } @@ -415,11 +365,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { deviceStatusXml.append("\r\n"); deviceStatusXml.append("\r\n"); - CallIdHeader callIdHeader = parentPlatform.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), SipUtils.getNewFromTag(), SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request); + sipSender.transmitRequest( request); } @@ -466,7 +415,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SIPRequest notifyRequest = headerProviderPlatformProvider.createNotifyRequest(parentPlatform, catalogXmlContent, subscribeInfo); - transmitRequest(parentPlatform, notifyRequest); + sipSender.transmitRequest( notifyRequest); } private String getCatalogXmlContentForCatalogAddOrUpdate(ParentPlatform parentPlatform, List channels, int sumNum, String type, SubscribeInfo subscribeInfo) { @@ -631,10 +580,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { recordXml.append("\r\n"); // callid - CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() - : udpSipProvider.getNewCallId(); + CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getTransport()); + Request request = headerProviderPlatformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, SipUtils.getNewViaTag(), callIdHeader); - transmitRequest(parentPlatform, request); + sipSender.transmitRequest( request); } @@ -658,7 +607,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { SIPRequest messageRequest = (SIPRequest)headerProviderPlatformProvider.createMessageRequest(platform, mediaStatusXml.toString(), sendRtpItem); - transmitRequest(platform, messageRequest); + sipSender.transmitRequest(messageRequest); } @@ -694,6 +643,6 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { if (byeRequest == null) { logger.warn("[向上级发送bye]:无法创建 byeRequest"); } - transmitRequest(platform,byeRequest); + sipSender.transmitRequest(byeRequest); } }