Skip to content

Commit

Permalink
feat: add StandardHeaders to SipEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Aug 8, 2024
1 parent b04ac43 commit b858c59
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"uri": "sip:rebekka@sip.example.com",
"headers": {
"Bar": "foo"
},
"standard_headers": {
"User-to-User": "UserToUser"
},
"type": "sip"
}
48 changes: 32 additions & 16 deletions Vonage.Test/NccoTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.Generic;
#region
using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json;
using Vonage.Serialization;
using Vonage.Voice;
using Vonage.Voice.Nccos;
using Vonage.Voice.Nccos.Endpoints;
using Xunit;
#endregion

namespace Vonage.Test;

Expand All @@ -23,7 +25,7 @@ public void TestAppEndpoint()
Assert.Equal(expectedJson,
JsonConvert.SerializeObject(endpoint, VonageSerialization.SerializerSettings));
}

[Fact]
public void TestConnect()
{
Expand Down Expand Up @@ -56,7 +58,7 @@ public void TestConnect()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestConnectWithAdvancedMachineDetection()
{
Expand Down Expand Up @@ -89,7 +91,7 @@ public void TestConnectWithAdvancedMachineDetection()
};
Assert.Equal(this.GetRequestJson(), new Ncco(connectAction).ToString());
}

[Fact]
public void TestConversation()
{
Expand All @@ -108,7 +110,7 @@ public void TestConversation()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestConversationAllTrue()
{
Expand All @@ -127,11 +129,11 @@ public void TestConversationAllTrue()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void ConversationAction_StartOnEnter_ShouldBeTrue_GivenDefault() =>
new ConversationAction().StartOnEnter.Should().BeTrue();

[Fact]
public void TestNotify()
{
Expand All @@ -149,7 +151,7 @@ public void TestNotify()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Theory]
[InlineData(RecordAction.AudioFormat.Mp3)]
[InlineData(RecordAction.AudioFormat.Wav)]
Expand All @@ -175,7 +177,7 @@ public void TestRecord(RecordAction.AudioFormat audioFormat)
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestRecordMinimalist()
{
Expand All @@ -185,7 +187,7 @@ public void TestRecordMinimalist()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestSipEndpoint()
{
Expand All @@ -198,7 +200,21 @@ public void TestSipEndpoint()
Assert.Equal(expectedJson,
JsonConvert.SerializeObject(endpoint, VonageSerialization.SerializerSettings));
}


[Fact]
public void TestSipEndpointWithStandardHeaders()
{
var expectedJson = this.GetRequestJson();
var endpoint = new SipEndpoint
{
Uri = "sip:rebekka@sip.example.com",
Headers = new TestClass {Bar = "foo"},
StandardHeaders = new SipEndpoint.StandardHeader("UserToUser"),
};
Assert.Equal(expectedJson,
JsonConvert.SerializeObject(endpoint, VonageSerialization.SerializerSettings));
}

[Fact]
public void TestStream()
{
Expand All @@ -214,7 +230,7 @@ public void TestStream()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestTalk()
{
Expand All @@ -232,7 +248,7 @@ public void TestTalk()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestTalkBareBones()
{
Expand All @@ -245,7 +261,7 @@ public void TestTalkBareBones()
var actualJson = ncco.ToString();
Assert.Equal(expectedJson, actualJson);
}

[Fact]
public void TestVbcEndpoint()
{
Expand All @@ -257,7 +273,7 @@ public void TestVbcEndpoint()
Assert.Equal(expectedJson,
JsonConvert.SerializeObject(endpoint, VonageSerialization.SerializerSettings));
}

[Fact]
public void TestWebsocketEndpoint()
{
Expand All @@ -271,7 +287,7 @@ public void TestWebsocketEndpoint()
Assert.Equal(expectedJson,
JsonConvert.SerializeObject(endpoint, VonageSerialization.SerializerSettings));
}

private class TestClass
{
public string Bar { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions Vonage.Test/Vonage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@
<None Update="Messages\Sms\Data\SendSmsAsyncReturnsOkWithSettings-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\NccoTests\TestSipEndpointWithStandardHeaders-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
24 changes: 18 additions & 6 deletions Vonage/Voice/Nccos/Endpoints/SipEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Newtonsoft.Json;
using System.Collections.Generic;
#region
using Newtonsoft.Json;
#endregion

namespace Vonage.Voice.Nccos.Endpoints;

public class SipEndpoint : Endpoint
{
public SipEndpoint() => this.Type = EndpointType.Sip;

/// <summary>
/// the SIP URI to the endpoint you are connecting to in the format sip:rebekka@sip.example.com.
/// </summary>
Expand All @@ -18,8 +21,17 @@ public class SipEndpoint : Endpoint
[JsonProperty("headers")]
public object Headers { get; set; }

public SipEndpoint()
{
this.Type = EndpointType.Sip;
}
/// <summary>
/// Standard SIP INVITE headers. Unlike the headers property, these are not prepended with X-.
/// </summary>
[JsonProperty("standard_headers")]
public StandardHeader StandardHeaders { get; set; }

/// <summary>
/// Standard SIP INVITE headers. Unlike the headers property, these are not prepended with X-.
/// </summary>
/// <param name="UserToUser">Transmit user-to-user information if supported by the CC / PBX vendor, as per RFC 7433.</param>
public record StandardHeader(
[property: JsonProperty("User-to-User")]
string UserToUser);
}

0 comments on commit b858c59

Please sign in to comment.