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-2863 add StreamParams verb #60

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions Bandwidth.Standard/Voice/Bxml/StartStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
Expand All @@ -11,6 +12,14 @@ namespace Bandwidth.Standard.Voice.Bxml
/// </summary>
public class StartStream : IXmlSerializable, IVerb, IAudioProducer
{
/// <summary>
/// Initialize the StreamParams list
/// </summary>
public StartStream()
{
StreamParams = new List<StreamParam>();
}

/// <summary>
/// A websocket URI to send the stream to
/// </summary>
Expand Down Expand Up @@ -45,6 +54,11 @@ public class StartStream : IXmlSerializable, IVerb, IAudioProducer
/// The password to send in the HTTP request to `streamEventUrl`
/// </summary>
public string Password { get; set; }

/// <summary>
/// List of StreamParam verbs
/// </summary>
public List<StreamParam> StreamParams { get; set; }

XmlSchema IXmlSerializable.GetSchema()
{
Expand Down Expand Up @@ -83,6 +97,18 @@ void IXmlSerializable.WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("password", Password);
}
if (StreamParams != null && StreamParams.Count > 0)
{
var ns = new XmlSerializerNamespaces();
ns.Add("", "");

foreach (var verb in StreamParams)
{
Console.WriteLine(verb.Name);
var serializer = new XmlSerializer(verb.GetType(), "");
serializer.Serialize(writer, verb, ns);
}
}
}
}
}
40 changes: 40 additions & 0 deletions Bandwidth.Standard/Voice/Bxml/StreamParam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Bandwidth.Standard.Voice.Bxml
{
/// <summary>
/// The StreamParam verb defines optional user specified parameters that will be sent to the destination URL when the stream is first started.
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/startStream" /></para>
/// </summary>
public class StreamParam : IXmlSerializable, IVerb
{
/// <summary>
/// The name of this parameter, up to 256 characters
/// </summary>
public string Name { get; set; }

/// <summary>
/// The value of this parameter, up to 2048 characters
/// </summary>
public string Value { get; set; }

XmlSchema IXmlSerializable.GetSchema()
{
return null;
}

void IXmlSerializable.ReadXml(XmlReader reader)
{
throw new NotImplementedException();
}

void IXmlSerializable.WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("name", Name);
writer.WriteAttributeString("value", Value);
}
}
}
14 changes: 13 additions & 1 deletion Bandwidth.StandardTests/Voice/Bxml/StreamTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Bandwidth.Standard.Voice.Bxml;
using Xunit;

Expand All @@ -9,7 +10,16 @@ public class StreamTests
[Fact]
public void StartStreamBxmlVerbTest()
{
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StartStream destination=\"https://www.test.com/stream\" name=\"test_stream\" tracks=\"inbound\" streamEventUrl=\"https://www.test.com/event\" streamEventMethod=\"POST\" username=\"username\" password=\"password\" /></Response>";
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StartStream destination=\"https://www.test.com/stream\" name=\"test_stream\" tracks=\"inbound\" streamEventUrl=\"https://www.test.com/event\" streamEventMethod=\"POST\" username=\"username\" password=\"password\"> <StreamParam name=\"name1\" value=\"value1\" /> <StreamParam name=\"name2\" value=\"value2\" /> </StartStream></Response>";

var streamParam1 = new StreamParam();
streamParam1.Name = "name1";
streamParam1.Value = "value1";

var streamParam2 = new StreamParam();
streamParam2.Name = "name2";
streamParam2.Value = "value2";

var startStream = new StartStream();
startStream.Destination = "https://www.test.com/stream";
startStream.Name = "test_stream";
Expand All @@ -18,6 +28,8 @@ public void StartStreamBxmlVerbTest()
startStream.StreamEventMethod = "POST";
startStream.Username = "username";
startStream.Password = "password";
startStream.StreamParams.Add(streamParam1);
startStream.StreamParams.Add(streamParam2);

var response = new Response(startStream);
var actual = response.ToBXML();
Expand Down