From cc9f7a0e73fff6121c2571e7313baebaa527b3b5 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Thu, 5 Oct 2023 13:11:45 +0800 Subject: [PATCH] =?UTF-8?q?play=20playback=20=E8=B6=85=E6=97=B6=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E5=8F=91=E9=80=81=20bye=20=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/service/play/PlayService.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java index 1f1a37c..1cadb81 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/play/PlayService.java @@ -204,7 +204,7 @@ public class PlayService { subscribe.getSipResponseSubscribe().delPublisher(subscribeKey); } }; - byeSubscribe(callId,3600,()->{ + byeSubscribe(inviteRequestBuilder,provider,callId,3600,()->{ RedisUtil.KeyOps.delete(key); }); subscribe.getSipResponseSubscribe().addSubscribe(subscribeKey, subscriber); @@ -313,7 +313,7 @@ public class PlayService { subscribe.getRecordInfoSubscribe().delPublisher(subscribeKey); } }; - byeSubscribe(callId,DateUtil.between(startTime,endTime,DateUnit.SECOND),()->{ + byeSubscribe(inviteRequestBuilder,provider,callId,DateUtil.between(startTime,endTime,DateUnit.SECOND),()->{ RedisUtil.KeyOps.delete(key); }); subscribe.getSipResponseSubscribe().addSubscribe(subscribeKey, subscriber); @@ -325,11 +325,12 @@ public class PlayService { return result; } - public void byeSubscribe(String callId, long seconds, Runnable cb){ + public void byeSubscribe(InviteRequestBuilder inviteRequestBuilder,SipProvider provider, String callId, long seconds, Runnable cb){ GenericTimeoutSubscribe sipRequestSubscribe = subscribe.getSipRequestSubscribe(); String subscribeKey = GenericSubscribe.Helper.getKey(Request.BYE, callId); sipRequestSubscribe.addPublisher(subscribeKey,seconds + 30,TimeUnit.SECONDS); Flow.Subscriber subscriber = new Flow.Subscriber<>(){ + SIPRequest request; @Override public void onSubscribe(Flow.Subscription subscription) { subscription.request(1); @@ -339,11 +340,7 @@ public class PlayService { @SneakyThrows public void onNext(SIPRequest item) { subscribe.getRecordInfoSubscribe().delPublisher(GenericSubscribe.Helper.getKey(Request.INVITE, callId)); - String transport = item.getTopmostViaHeader().getTransport(); - String hostAddress = item.getLocalAddress().getHostAddress(); - Response byeResponse = InviteResponseBuilder.builder().build().createByeResponse(item, SipUtil.nanoId()); - sipService.getProvider(transport,hostAddress).sendResponse(byeResponse); - cb.run(); + request = item; subscribe.getRecordInfoSubscribe().complete(subscribeKey); } @@ -352,8 +349,17 @@ public class PlayService { } + @SneakyThrows @Override public void onComplete() { + if(request != null){ + Response byeResponse = InviteResponseBuilder.builder().build().createByeResponse(request, SipUtil.nanoId()); + provider.sendResponse(byeResponse); + } else { + Request byeRequest = inviteRequestBuilder.createByeRequest(callId, SipRequestBuilder.getCSeq()); + provider.sendRequest(byeRequest); + } + cb.run(); subscribe.getRecordInfoSubscribe().delPublisher(subscribeKey); } };