Skip to content

Commit

Permalink
Merge pull request #59 from Bandwidth/DX-2703
Browse files Browse the repository at this point in the history
DX-2703 Add `<StartStream>` and `<StopStream>` BXML Verbs
  • Loading branch information
ajrice6713 authored Aug 29, 2022
2 parents b8e6b89 + a04c648 commit a0ab6c0
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
88 changes: 88 additions & 0 deletions Bandwidth.Standard/Voice/Bxml/StartStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Bandwidth.Standard.Voice.Bxml
{
/// <summary>
/// The StartStream verb allows a segment of a call to be sent off to another destination for additional processing.
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/startStream" /></para>
/// </summary>
public class StartStream : IXmlSerializable, IVerb, IAudioProducer
{
/// <summary>
/// A websocket URI to send the stream to
/// </summary>
public string Destination { get; set; }

/// <summary>
/// A name to refer to this stream by
/// </summary>
public string Name { get; set; }

/// <summary>
/// The part of the call to send a stream from. `inbound`, `outbound` or `both`.
/// </summary>
public string Tracks { get; set; }

/// <summary>
/// URL to send the associated Webhook events to during this stream's lifetime
/// </summary>
public string StreamEventUrl { get; set; }

/// <summary>
/// The HTTP method to use for the request to `streamEventUrl`
/// </summary>
public string StreamEventMethod { get; set; }

/// <summary>
/// The username to send in the HTTP request to `streamEventUrl`
/// </summary>
public string Username { get; set; }

/// <summary>
/// The password to send in the HTTP request to `streamEventUrl`
/// </summary>
public string Password { get; set; }

XmlSchema IXmlSerializable.GetSchema()
{
return null;
}

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

void IXmlSerializable.WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("destination", Destination);
if (!string.IsNullOrEmpty(Name))
{
writer.WriteAttributeString("name", Name);
}
if (!string.IsNullOrEmpty(Tracks))
{
writer.WriteAttributeString("tracks", Tracks);
}
if (!string.IsNullOrEmpty(StreamEventUrl))
{
writer.WriteAttributeString("streamEventUrl", StreamEventUrl);
}
if (!string.IsNullOrEmpty(StreamEventMethod))
{
writer.WriteAttributeString("streamEventMethod", StreamEventMethod);
}
if (!string.IsNullOrEmpty(Username))
{
writer.WriteAttributeString("username", Username);
}
if (!string.IsNullOrEmpty(Password))
{
writer.WriteAttributeString("password", Password);
}
}
}
}
34 changes: 34 additions & 0 deletions Bandwidth.Standard/Voice/Bxml/StopStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Bandwidth.Standard.Voice.Bxml
{
/// <summary>
/// The StopStream verb is used to stop a stream that was started with a previous `<StartStream>` verb.
/// <para><seealso href="https://dev.bandwidth.com/voice/bxml/stopStream" /></para>
/// </summary>
public class StopStream : IXmlSerializable, IVerb, IAudioProducer
{
/// <summary>
/// The name of the stream to stop
/// </summary>
public string Name { get; set; }

XmlSchema IXmlSerializable.GetSchema()
{
return null;
}

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

void IXmlSerializable.WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("name", Name);
}
}
}
41 changes: 41 additions & 0 deletions Bandwidth.StandardTests/Voice/Bxml/StreamTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Bandwidth.Standard.Voice.Bxml;
using Xunit;

namespace Bandwidth.StandardTests.Voice.Bxml
{
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 startStream = new StartStream();
startStream.Destination = "https://www.test.com/stream";
startStream.Name = "test_stream";
startStream.Tracks = "inbound";
startStream.StreamEventUrl = "https://www.test.com/event";
startStream.StreamEventMethod = "POST";
startStream.Username = "username";
startStream.Password = "password";

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

Assert.Equal(expected, actual);
}

[Fact]
public void StopStreamBxmlVerbTest()
{
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Response> <StopStream name=\"test_stream\" /></Response>";
var stopStream = new StopStream();
stopStream.Name = "test_stream";

var response = new Response(stopStream);
var actual = response.ToBXML();

Assert.Equal(expected, actual);
}
}
}

0 comments on commit a0ab6c0

Please sign in to comment.