Skip to content

Commit

Permalink
Update method BXML methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hamermike committed Jul 22, 2021
1 parent f285a1d commit e543c1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 7 additions & 14 deletions Bandwidth.Standard/WebRtc/Utils/WebRtcTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ namespace Bandwidth.Standard.WebRtc.Utils
public static class WebRtcTransfer {
private const string SipUri = "sip:sipx.webrtc.bandwidth.com:5060";

public static string GenerateBxml(string deviceToken, string sipUri = SipUri)
public static string GenerateBxml(string deviceToken, string voiceCallId, string sipUri = SipUri)
{
var bxmlVerb = GenerateBxmlVerb(deviceToken, sipUri);
var bxmlVerb = GenerateBxmlVerb(deviceToken, voiceCallId, sipUri);
return GenerateBxml(bxmlVerb);
}

public static string GenerateBxmlVoiceCallId(string deviceToken, string voiceCallId, string sipUri = SipUri)
{
var bxmlVerb = GenerateBxmlVerbVoiceCallId(deviceToken, voiceCallId, sipUri);
return GenerateBxml(bxmlVerb);
}

public static string GenerateBxmlVerb(string deviceToken, string sipUri = SipUri)
{
return $"<Transfer><SipUri uui=\"{deviceToken};encoding=jwt\">{sipUri}</SipUri></Transfer>";
}

public static string GenerateBxmlVerbVoiceCallId(string deviceToken, string voiceCallId, string sipUri = SipUri)
public static string GenerateBxmlVerb(string deviceToken, string voiceCallId, string sipUri = SipUri)
{
if (voiceCallId == null) {
return $"<Transfer><SipUri uui=\"{deviceToken};encoding=jwt\">{sipUri}</SipUri></Transfer>";
}

voiceCallId = voiceCallId.Substring(1).Replace("-", "");
return $"<Transfer><SipUri uui=\"{voiceCallId};encoding=base64,{deviceToken};encoding=jwt\">{sipUri}</SipUri></Transfer>";
}
Expand Down
8 changes: 4 additions & 4 deletions Bandwidth.StandardTests/WebRtc/BxmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BxmlTests
public void GenerateBxml()
{
const string deviceToken = "test-device-token";
var bxml = WebRtcTransfer.GenerateBxml(deviceToken);
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, null);

const string expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response><Transfer><SipUri uui=\"test-device-token;encoding=jwt\">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer></Response>";

Expand All @@ -21,7 +21,7 @@ public void GenerateBxmlWithCustomSipUri()
{
const string deviceToken = "test-device-token";
const string sipUri = "sip:sipx.acme.com:6112";
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, sipUri);
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, null, sipUri);

const string expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response><Transfer><SipUri uui=\"test-device-token;encoding=jwt\">sip:sipx.acme.com:6112</SipUri></Transfer></Response>";

Expand All @@ -33,7 +33,7 @@ public void GenerateBxmlVoiceCallId()
{
const string deviceToken = "test-device-token";
const string voiceCallId = "c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4";
var bxml = WebRtcTransfer.GenerateBxmlVoiceCallId(deviceToken, voiceCallId);
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, voiceCallId);

const string expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response><Transfer><SipUri uui=\"93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,test-device-token;encoding=jwt\">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer></Response>";

Expand All @@ -46,7 +46,7 @@ public void GenerateBxmlVoiceCallIdWithCustomSipUri()
var deviceToken = "test-device-token";
var voiceCallId = "c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4";
var sipUri = "sip:sipx.acme.com:6112";
var bxml = WebRtcTransfer.GenerateBxmlVoiceCallId(deviceToken, voiceCallId, sipUri);
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, voiceCallId, sipUri);

const string expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response><Transfer><SipUri uui=\"93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,test-device-token;encoding=jwt\">sip:sipx.acme.com:6112</SipUri></Transfer></Response>";

Expand Down

0 comments on commit e543c1f

Please sign in to comment.