Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX-2100 webrtc standalone transfer verb #28

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions Bandwidth.Standard/WebRtc/Utils/WebRtcTransfer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
using System.ComponentModel;

namespace Bandwidth.Standard.WebRtc.Utils
{
public static class WebRtcTransfer {
public static string generateBxml(string deviceToken) {
return WebRtcTransfer.generateBxml(deviceToken, "sip:sipx.webrtc.bandwidth.com:5060");
private const string SipUri = "sip:sipx.webrtc.bandwidth.com:5060";

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

public static string GenerateBxmlVoiceCallId(string deviceToken, string voiceCallId, string sipUri = SipUri)
hamermike marked this conversation as resolved.
Show resolved Hide resolved
{
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)
{
voiceCallId = voiceCallId.Substring(1).Replace("-", "");
return $"<Transfer><SipUri uui=\"{voiceCallId};encoding=base64,{deviceToken};encoding=jwt\">{sipUri}</SipUri></Transfer>";
}

public static string generateBxml(string deviceToken, string sipUri) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<Response><Transfer>\n"
+ "\t<SipUri uui=\"" + deviceToken + ";encoding=jwt\">" + sipUri + "</SipUri>\n"
+ "</Transfer></Response>\n";
private static string GenerateBxml(string response)
{
return $"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response>{response}</Response>";
}
}
}
56 changes: 56 additions & 0 deletions Bandwidth.StandardTests/WebRtc/BxmlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Bandwidth.Standard.WebRtc.Utils;
using Xunit;

namespace Bandwidth.StandardTests.WebRtc
{
public class BxmlTests
{
[Fact]
public void GenerateBxml()
{
const string deviceToken = "test-device-token";
var bxml = WebRtcTransfer.GenerateBxml(deviceToken);

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>";

Assert.Equal(expected, bxml);
}

[Fact]
public void GenerateBxmlWithCustomSipUri()
{
const string deviceToken = "test-device-token";
const string sipUri = "sip:sipx.acme.com:6112";
var bxml = WebRtcTransfer.GenerateBxml(deviceToken, 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>";

Assert.Equal(expected, bxml);
}

[Fact]
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);

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>";

Assert.Equal(expected, bxml);
}

[Fact]
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);

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>";

Assert.Equal(expected, bxml);
}
}
}