Skip to content

Commit 852b1b2

Browse files
authored
Merge pull request #60 from Bandwidth/DX-2863
DX-2863 add `StreamParams` verb
2 parents a0ab6c0 + 932e0ab commit 852b1b2

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

Bandwidth.Standard/Voice/Bxml/StartStream.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Xml;
34
using System.Xml.Schema;
45
using System.Xml.Serialization;
@@ -11,6 +12,14 @@ namespace Bandwidth.Standard.Voice.Bxml
1112
/// </summary>
1213
public class StartStream : IXmlSerializable, IVerb, IAudioProducer
1314
{
15+
/// <summary>
16+
/// Initialize the StreamParams list
17+
/// </summary>
18+
public StartStream()
19+
{
20+
StreamParams = new List<StreamParam>();
21+
}
22+
1423
/// <summary>
1524
/// A websocket URI to send the stream to
1625
/// </summary>
@@ -45,6 +54,11 @@ public class StartStream : IXmlSerializable, IVerb, IAudioProducer
4554
/// The password to send in the HTTP request to `streamEventUrl`
4655
/// </summary>
4756
public string Password { get; set; }
57+
58+
/// <summary>
59+
/// List of StreamParam verbs
60+
/// </summary>
61+
public List<StreamParam> StreamParams { get; set; }
4862

4963
XmlSchema IXmlSerializable.GetSchema()
5064
{
@@ -83,6 +97,18 @@ void IXmlSerializable.WriteXml(XmlWriter writer)
8397
{
8498
writer.WriteAttributeString("password", Password);
8599
}
100+
if (StreamParams != null && StreamParams.Count > 0)
101+
{
102+
var ns = new XmlSerializerNamespaces();
103+
ns.Add("", "");
104+
105+
foreach (var verb in StreamParams)
106+
{
107+
Console.WriteLine(verb.Name);
108+
var serializer = new XmlSerializer(verb.GetType(), "");
109+
serializer.Serialize(writer, verb, ns);
110+
}
111+
}
86112
}
87113
}
88114
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Xml;
3+
using System.Xml.Schema;
4+
using System.Xml.Serialization;
5+
6+
namespace Bandwidth.Standard.Voice.Bxml
7+
{
8+
/// <summary>
9+
/// The StreamParam verb defines optional user specified parameters that will be sent to the destination URL when the stream is first started.
10+
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/startStream" /></para>
11+
/// </summary>
12+
public class StreamParam : IXmlSerializable, IVerb
13+
{
14+
/// <summary>
15+
/// The name of this parameter, up to 256 characters
16+
/// </summary>
17+
public string Name { get; set; }
18+
19+
/// <summary>
20+
/// The value of this parameter, up to 2048 characters
21+
/// </summary>
22+
public string Value { get; set; }
23+
24+
XmlSchema IXmlSerializable.GetSchema()
25+
{
26+
return null;
27+
}
28+
29+
void IXmlSerializable.ReadXml(XmlReader reader)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
34+
void IXmlSerializable.WriteXml(XmlWriter writer)
35+
{
36+
writer.WriteAttributeString("name", Name);
37+
writer.WriteAttributeString("value", Value);
38+
}
39+
}
40+
}

Bandwidth.StandardTests/Voice/Bxml/StreamTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using Bandwidth.Standard.Voice.Bxml;
23
using Xunit;
34

@@ -9,7 +10,16 @@ public class StreamTests
910
[Fact]
1011
public void StartStreamBxmlVerbTest()
1112
{
12-
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>";
13+
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>";
14+
15+
var streamParam1 = new StreamParam();
16+
streamParam1.Name = "name1";
17+
streamParam1.Value = "value1";
18+
19+
var streamParam2 = new StreamParam();
20+
streamParam2.Name = "name2";
21+
streamParam2.Value = "value2";
22+
1323
var startStream = new StartStream();
1424
startStream.Destination = "https://www.test.com/stream";
1525
startStream.Name = "test_stream";
@@ -18,6 +28,8 @@ public void StartStreamBxmlVerbTest()
1828
startStream.StreamEventMethod = "POST";
1929
startStream.Username = "username";
2030
startStream.Password = "password";
31+
startStream.StreamParams.Add(streamParam1);
32+
startStream.StreamParams.Add(streamParam2);
2133

2234
var response = new Response(startStream);
2335
var actual = response.ToBXML();

0 commit comments

Comments
 (0)