Skip to content

Commit a0ab6c0

Browse files
authored
Merge pull request #59 from Bandwidth/DX-2703
DX-2703 Add `<StartStream>` and `<StopStream>` BXML Verbs
2 parents b8e6b89 + a04c648 commit a0ab6c0

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
/// The part of the call to send a stream from. `inbound`, `outbound` or `both`.
26+
/// </summary>
27+
public string Tracks { get; set; }
28+
29+
/// <summary>
30+
/// URL to send the associated Webhook events to during this stream's lifetime
31+
/// </summary>
32+
public string StreamEventUrl { get; set; }
33+
34+
/// <summary>
35+
/// The HTTP method to use for the request to `streamEventUrl`
36+
/// </summary>
37+
public string StreamEventMethod { get; set; }
38+
39+
/// <summary>
40+
/// The username to send in the HTTP request to `streamEventUrl`
41+
/// </summary>
42+
public string Username { get; set; }
43+
44+
/// <summary>
45+
/// The password to send in the HTTP request to `streamEventUrl`
46+
/// </summary>
47+
public string Password { get; set; }
48+
49+
XmlSchema IXmlSerializable.GetSchema()
50+
{
51+
return null;
52+
}
53+
54+
void IXmlSerializable.ReadXml(XmlReader reader)
55+
{
56+
throw new NotImplementedException();
57+
}
58+
59+
void IXmlSerializable.WriteXml(XmlWriter writer)
60+
{
61+
writer.WriteAttributeString("destination", Destination);
62+
if (!string.IsNullOrEmpty(Name))
63+
{
64+
writer.WriteAttributeString("name", Name);
65+
}
66+
if (!string.IsNullOrEmpty(Tracks))
67+
{
68+
writer.WriteAttributeString("tracks", Tracks);
69+
}
70+
if (!string.IsNullOrEmpty(StreamEventUrl))
71+
{
72+
writer.WriteAttributeString("streamEventUrl", StreamEventUrl);
73+
}
74+
if (!string.IsNullOrEmpty(StreamEventMethod))
75+
{
76+
writer.WriteAttributeString("streamEventMethod", StreamEventMethod);
77+
}
78+
if (!string.IsNullOrEmpty(Username))
79+
{
80+
writer.WriteAttributeString("username", Username);
81+
}
82+
if (!string.IsNullOrEmpty(Password))
83+
{
84+
writer.WriteAttributeString("password", Password);
85+
}
86+
}
87+
}
88+
}
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\" tracks=\"inbound\" 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.Tracks = "inbound";
17+
startStream.StreamEventUrl = "https://www.test.com/event";
18+
startStream.StreamEventMethod = "POST";
19+
startStream.Username = "username";
20+
startStream.Password = "password";
21+
22+
var response = new Response(startStream);
23+
var actual = response.ToBXML();
24+
25+
Assert.Equal(expected, actual);
26+
}
27+
28+
[Fact]
29+
public void StopStreamBxmlVerbTest()
30+
{
31+
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StopStream name=\"test_stream\" /></Response>";
32+
var stopStream = new StopStream();
33+
stopStream.Name = "test_stream";
34+
35+
var response = new Response(stopStream);
36+
var actual = response.ToBXML();
37+
38+
Assert.Equal(expected, actual);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)