From fde9332d9b705e327b3b624f28e7f2f44f5a4930 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sat, 30 Sep 2023 17:00:20 +0800 Subject: [PATCH] createByeRequest, createByeResponse --- .../method/invite/request/InviteRequestBuilder.java | 12 ++++++++---- .../invite/response/InviteResponseBuilder.java | 8 ++++++++ .../docking/gb28181/sip/process/RequestTest.java | 5 +++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java index 4687b18..43ba85c 100644 --- a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java +++ b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java @@ -24,7 +24,7 @@ import java.util.Date; @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class InviteRequestBuilder extends RequestBuilder implements InviteBuilder { - private SubjectHeader createSubject(String senderId, String senderStreamId, String receiveId, String receiveStreamId){ + private SubjectHeader createSubject(String senderId, String senderStreamId, String receiveId, String receiveStreamId) { String subject = StringUtils.joinWith(",", // 发送者 channelId:流序号 StringUtils.joinWith(":", senderId, senderStreamId), @@ -33,8 +33,8 @@ public class InviteRequestBuilder extends RequestBuilder implements InviteBuilde return SipBuilder.createSubjectHeader(subject); } - public Request createPlayInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId){ - GB28181Description description = GB28181SDPBuilder.Receiver.play(getTargetId(), channelId, Connection.IP4,rtpIp,rtpPort,ssrc,mediaStreamMode); + public Request createPlayInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId) { + GB28181Description description = GB28181SDPBuilder.Receiver.play(getTargetId(), channelId, Connection.IP4, rtpIp, rtpPort, ssrc, mediaStreamMode); SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, description); Address address = request.getFrom().getAddress(); @@ -64,7 +64,7 @@ public class InviteRequestBuilder extends RequestBuilder implements InviteBuilde } public Request createDownloadInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId, Date startTime, Date endTime, Double downloadSpeed) { - GB28181Description description = GB28181SDPBuilder.Receiver.download(getTargetId(), channelId, Connection.IP4, rtpIp, rtpPort, ssrc, mediaStreamMode, startTime, endTime,downloadSpeed); + GB28181Description description = GB28181SDPBuilder.Receiver.download(getTargetId(), channelId, Connection.IP4, rtpIp, rtpPort, ssrc, mediaStreamMode, startTime, endTime, downloadSpeed); SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, description); Address address = request.getFrom().getAddress(); @@ -77,4 +77,8 @@ public class InviteRequestBuilder extends RequestBuilder implements InviteBuilde public Request createDownloadInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, Date startTime, Date endTime, Double downloadSpeed) { return createDownloadInviteRequest(callId, cSeq, channelId, rtpIp, rtpPort, ssrc, mediaStreamMode, String.valueOf(0), startTime, endTime, downloadSpeed); } + + public Request createByeRequest(String callId, long cSeq) { + return createRequest(Request.BYE, callId, cSeq); + } } diff --git a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/response/InviteResponseBuilder.java b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/response/InviteResponseBuilder.java index 798846b..f62edcd 100644 --- a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/response/InviteResponseBuilder.java +++ b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/response/InviteResponseBuilder.java @@ -58,4 +58,12 @@ public class InviteResponseBuilder implements InviteBuilder { public Response createTryingInviteResponse(Request request){ return SipResponseBuilder.createResponse(Response.TRYING,request); } + + public Response createByeResponse(Request request){ + return createByeResponse(request, ""); + } + + public Response createByeResponse(Request request, String toTag){ + return addHeader(SipResponseBuilder.createResponse(Response.OK,request), toTag); + } } diff --git a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java index 0239a5e..e9fe3e8 100644 --- a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java +++ b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java @@ -98,6 +98,11 @@ public class RequestTest { log.info("\n{}", tryingInviteResponse); inviteResponse = inviteResponseBuilder.createInviteResponse(downloadInviteRequest, senderRtp, senderRtpPort, SipUtil.nanoId()); log.info("\n{}", inviteResponse); + + Request byeRequest = inviteRequestBuilder.createByeRequest(callId, 2); + log.info("\n{}", byeRequest); + Response byeResponse = inviteResponseBuilder.createByeResponse(byeRequest, SipUtil.nanoId()); + log.info("\n{}", byeResponse); }