Skip to content

Commit

Permalink
Merge pull request #60 from Bandwidth/DX-2863
Browse files Browse the repository at this point in the history
DX-2863 add `StreamParams` verb
  • Loading branch information
ajrice6713 committed Sep 19, 2022
2 parents a0ab6c0 + 932e0ab commit 852b1b2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
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

0 comments on commit 852b1b2

Please sign in to comment.