Skip to content

Commit c705f48

Browse files
committed
DX-2703 Add <StartStream> and <StopStream> BXML Verbs
1 parent b8e6b89 commit c705f48

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 StartStream verb allows a segment of a call to be sent off to another destination for additional processing.
10+
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/startStream" /></para>
11+
/// </summary>
12+
public class StartStream : IXmlSerializable, IVerb, IAudioProducer
13+
{
14+
/// <summary>
15+
/// A websocket URI to send the stream to
16+
/// </summary>
17+
public string Destination { get; set; }
18+
19+
/// <summary>
20+
/// A name to refer to this stream by
21+
/// </summary>
22+
public string Name { get; set; }
23+
24+
/// <summary>
25+
/// URL to send the associated Webhook events to during this stream's lifetime
26+
/// </summary>
27+
public string StreamEventUrl { get; set; }
28+
29+
/// <summary>
30+
/// The HTTP method to use for the request to `streamEventUrl`
31+
/// </summary>
32+
public string StreamEventMethod { get; set; }
33+
34+
/// <summary>
35+
/// The username to send in the HTTP request to `streamEventUrl`
36+
/// </summary>
37+
public string Username { get; set; }
38+
39+
/// <summary>
40+
/// The password to send in the HTTP request to `streamEventUrl`
41+
/// </summary>
42+
public string Password { get; set; }
43+
44+
XmlSchema IXmlSerializable.GetSchema()
45+
{
46+
return null;
47+
}
48+
49+
void IXmlSerializable.ReadXml(XmlReader reader)
50+
{
51+
throw new NotImplementedException();
52+
}
53+
54+
void IXmlSerializable.WriteXml(XmlWriter writer)
55+
{
56+
writer.WriteAttributeString("destination", Destination);
57+
if (!string.IsNullOrEmpty(Name))
58+
{
59+
writer.WriteAttributeString("name", Name);
60+
}
61+
if (!string.IsNullOrEmpty(StreamEventUrl))
62+
{
63+
writer.WriteAttributeString("streamEventUrl", StreamEventUrl);
64+
}
65+
if (!string.IsNullOrEmpty(StreamEventMethod))
66+
{
67+
writer.WriteAttributeString("streamEventMethod", StreamEventMethod);
68+
}
69+
if (!string.IsNullOrEmpty(Username))
70+
{
71+
writer.WriteAttributeString("username", Username);
72+
}
73+
if (!string.IsNullOrEmpty(Password))
74+
{
75+
writer.WriteAttributeString("password", Password);
76+
}
77+
}
78+
}
79+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 StopStream verb is used to stop a stream that was started with a previous `<StartStream>` verb.
10+
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/stopStream" /></para>
11+
/// </summary>
12+
public class StopStream : IXmlSerializable, IVerb, IAudioProducer
13+
{
14+
/// <summary>
15+
/// The name of the stream to stop
16+
/// </summary>
17+
public string Name { get; set; }
18+
19+
XmlSchema IXmlSerializable.GetSchema()
20+
{
21+
return null;
22+
}
23+
24+
void IXmlSerializable.ReadXml(XmlReader reader)
25+
{
26+
throw new NotImplementedException();
27+
}
28+
29+
void IXmlSerializable.WriteXml(XmlWriter writer)
30+
{
31+
writer.WriteAttributeString("name", Name);
32+
}
33+
}
34+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Bandwidth.Standard.Voice.Bxml;
2+
using Xunit;
3+
4+
namespace Bandwidth.StandardTests.Voice.Bxml
5+
{
6+
public class StreamTests
7+
{
8+
9+
[Fact]
10+
public void StartStreamBxmlVerbTest()
11+
{
12+
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StartStream destination=\"https://www.test.com/stream\" name=\"test_stream\" streamEventUrl=\"https://www.test.com/event\" streamEventMethod=\"POST\" username=\"username\" password=\"password\" /></Response>";
13+
var startStream = new StartStream();
14+
startStream.Destination = "https://www.test.com/stream";
15+
startStream.Name = "test_stream";
16+
startStream.StreamEventUrl = "https://www.test.com/event";
17+
startStream.StreamEventMethod = "POST";
18+
startStream.Username = "username";
19+
startStream.Password = "password";
20+
21+
var response = new Response(startStream);
22+
var actual = response.ToBXML();
23+
24+
Assert.Equal(expected, actual);
25+
}
26+
27+
[Fact]
28+
public void StopStreamBxmlVerbTest()
29+
{
30+
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StopStream name=\"test_stream\" /></Response>";
31+
var stopStream = new StopStream();
32+
stopStream.Name = "test_stream";
33+
34+
var response = new Response(stopStream);
35+
var actual = response.ToBXML();
36+
37+
Assert.Equal(expected, actual);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)