Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/com/bandwidth/voice/bxml/verbs/Bxml.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class Bxml {
@XmlElement(name = Tag.TYPE_NAME, type = Tag.class),
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class),
@XmlElement(name = StartStream.TYPE_NAME, type = StartStream.class),
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class)
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class),
@XmlElement(name = StreamParam.TYPE_NAME, type = StreamParam.class)
})
private final List<Verb> verbs = new ArrayList<>();

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/bandwidth/voice/bxml/verbs/StartStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import lombok.Builder;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;


/**
* The StartStream verb allows a segment of a call to be streamed to an external destination.
Expand All @@ -15,6 +21,11 @@
public class StartStream implements Verb {
public static final String TYPE_NAME = "StartStream";

/**
* You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.
*/
@XmlElement(name = StreamParam.TYPE_NAME)
private final List<StreamParam> streamParams;

/**
* <i>(optional)</i> A name to refer to this stream by. Used when sending [`<StopStream>`][1]. If not provided, a random name will be generated and sent in the [`Media Stream Started`][2] webook.
Expand Down Expand Up @@ -105,6 +116,22 @@ public StartStreamBuilder streamEventMethod(Method method){
public StartStreamBuilder streamEventMethod(String method){
return streamEventMethod(Method.fromValue(method));
}

/**
* <i>(optional)</i> You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.
*/
public StartStreamBuilder streamParams(StreamParam ... streamParams){
this.streamParams = Arrays.asList(streamParams);
return this;
}

/**
* <i>(optional)</i> You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.
*/
public StartStreamBuilder streamParams(List<StreamParam> streamParams){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale behind supporting two methods to set StreamParams?

this.streamParams = streamParams;
return this;
}
}

}
29 changes: 29 additions & 0 deletions src/main/java/com/bandwidth/voice/bxml/verbs/StreamParam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package com.bandwidth.voice.bxml.verbs;

import lombok.Builder;


import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

/**
* Object representation of a StreamParam
*/
@Builder
@XmlType(name = StreamParam.TYPE_NAME)
public class StreamParam {
public static final String TYPE_NAME = "StreamParam";

/**
* <i>(required)</i> The name of this parameter, up to 256 characters.
*/
@XmlAttribute
private String name;

/**
* <i>(required)</i> The value of this parameter, up to 2048 characters.
*/
@XmlAttribute
private String value;
}
14 changes: 13 additions & 1 deletion src/test/java/com/bandwidth/BxmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ public void testStopRecording() {

@Test
public void testStartStream() {
StreamParam streamParam1 = StreamParam.builder()
.name("name1")
.value("value1")
.build();
StreamParam streamParam2 = StreamParam.builder()
.name("name2")
.value("value2")
.build();
ArrayList<StreamParam> streamParams = new ArrayList<StreamParam>();
streamParams.add(streamParam1);
streamParams.add(streamParam2);
StartStream startStream = StartStream.builder()
.destination("https://url.com")
.streamEventMethod("POST")
Expand All @@ -462,13 +473,14 @@ public void testStartStream() {
.name("test")
.tracks("inbound")
.streamEventUrl("https://url.com")
.streamParams(streamParams)
.build();

String response = new Response()
.add(startStream)
.toBXML();

String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartStream name=\"test\" tracks=\"inbound\" destination=\"https://url.com\" streamEventUrl=\"https://url.com\" streamEventMethod=\"POST\" username=\"user\" password=\"pass\"/></Response>";
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartStream name=\"test\" tracks=\"inbound\" destination=\"https://url.com\" streamEventUrl=\"https://url.com\" streamEventMethod=\"POST\" username=\"user\" password=\"pass\"><StreamParam name=\"name1\" value=\"value1\"/><StreamParam name=\"name2\" value=\"value2\"/></StartStream></Response>";

assertEquals("BXML strings not equal", expected, response);
}
Expand Down