Skip to content

Commit 9d51390

Browse files
Merge pull request #72 from Bandwidth/DX-2700
DX-2700 Adding StartStream/StopStream BXML Verbs
2 parents 05e93f0 + bf948c2 commit 9d51390

File tree

5 files changed

+173
-2
lines changed

5 files changed

+173
-2
lines changed

src/main/java/com/bandwidth/voice/bxml/verbs/Bxml.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public class Bxml {
4545
@XmlElement(name = StartGather.TYPE_NAME, type = StartGather.class),
4646
@XmlElement(name = StopGather.TYPE_NAME, type = StopGather.class),
4747
@XmlElement(name = Tag.TYPE_NAME, type = Tag.class),
48-
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class)
48+
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class),
49+
@XmlElement(name = StartStream.TYPE_NAME, type = StartStream.class),
50+
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class)
4951
})
5052
private final List<Verb> verbs = new ArrayList<>();
5153

src/main/java/com/bandwidth/voice/bxml/verbs/Response.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public class Response {
4545
@XmlElement(name = StartGather.TYPE_NAME, type = StartGather.class),
4646
@XmlElement(name = StopGather.TYPE_NAME, type = StopGather.class),
4747
@XmlElement(name = Tag.TYPE_NAME, type = Tag.class),
48-
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class)
48+
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class),
49+
@XmlElement(name = StartStream.TYPE_NAME, type = StartStream.class),
50+
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class)
4951
})
5052
private final List<Verb> verbs = new ArrayList<>();
5153

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import lombok.Builder;
5+
6+
import java.net.URI;
7+
import javax.xml.bind.annotation.XmlAttribute;
8+
import javax.xml.bind.annotation.XmlType;
9+
10+
/**
11+
* The StartStream verb allows a segment of a call to be streamed to an external destination.
12+
*/
13+
@Builder
14+
@XmlType(name = StartStream.TYPE_NAME)
15+
public class StartStream implements Verb {
16+
public static final String TYPE_NAME = "StartStream";
17+
18+
19+
/**
20+
* <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.
21+
*/
22+
@XmlAttribute
23+
private String name;
24+
25+
/**
26+
* <i>(optional)</i> The part of the call to send a stream from. `inbound`, `outbound` or `both`. Default is `inbound`.
27+
*/
28+
@XmlAttribute
29+
private String tracks;
30+
31+
/**
32+
* <i>(required)</i> A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL encoded as base64 encoded PCMU/G711 audio. See below for more details on the websocket packet format.
33+
*/
34+
@XmlAttribute
35+
private URI destination;
36+
37+
/**
38+
* <i>(optional)</i> URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL.
39+
*/
40+
@XmlAttribute
41+
private URI streamEventUrl;
42+
43+
/**
44+
* <i>(optional)</i> The HTTP method to use for the request to `streamEventUrl`. GET or POST. Default value is POST.
45+
*/
46+
@XmlAttribute
47+
private Method streamEventMethod;
48+
49+
/**
50+
* <i>(optional)</i> The username to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`).
51+
*/
52+
@XmlAttribute
53+
protected String username;
54+
55+
/**
56+
* <i>(optional)</i> The password to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`).
57+
*/
58+
@XmlAttribute
59+
protected String password;
60+
61+
62+
public static class StartStreamBuilder {
63+
64+
/**
65+
* <b>(optional)</b> URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL.
66+
*/
67+
public StartStreamBuilder streamEventUrl(URI uri ){
68+
this.streamEventUrl = uri;
69+
return this;
70+
}
71+
72+
/**
73+
* <b>(optional)</b> URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL.
74+
*/
75+
public StartStreamBuilder streamEventUrl(String uri ){
76+
return streamEventUrl(URI.create(uri));
77+
}
78+
79+
/**
80+
* <b>(required)</b> A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL encoded as base64 encoded PCMU/G711 audio. See below for more details on the websocket packet format.
81+
*/
82+
public StartStreamBuilder destination(URI uri ){
83+
this.destination = uri;
84+
return this;
85+
}
86+
87+
/**
88+
* <b>(optional)</b> A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL encoded as base64 encoded PCMU/G711 audio. See below for more details on the websocket packet format.
89+
*/
90+
public StartStreamBuilder destination(String uri ){
91+
return destination(URI.create(uri));
92+
}
93+
94+
/**
95+
* <i>(optional)</i> The HTTP method to use for the request to `streamEventUrl`. GET or POST. Default value is POST.
96+
*/
97+
public StartStreamBuilder streamEventMethod(Method method){
98+
this.streamEventMethod = method;
99+
return this;
100+
}
101+
102+
/**
103+
* <i>(optional)</i> The HTTP method to use for the request to `streamEventUrl`. GET or POST. Default value is POST.
104+
*/
105+
public StartStreamBuilder streamEventMethod(String method){
106+
return streamEventMethod(Method.fromValue(method));
107+
}
108+
}
109+
110+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import lombok.Builder;
5+
import javax.xml.bind.annotation.XmlAttribute;
6+
import javax.xml.bind.annotation.XmlType;
7+
8+
9+
/**
10+
* The StopStream verb is used to stop a stream previously started by a `<StartStream>` verb.
11+
*/
12+
@Builder
13+
@XmlType(name = StopStream.TYPE_NAME)
14+
public class StopStream implements Verb {
15+
public static final String TYPE_NAME = "StopStream";
16+
17+
/**
18+
* <i>(required)</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.
19+
*/
20+
@XmlAttribute
21+
private String name;
22+
}

src/test/java/com/bandwidth/BxmlTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,41 @@ public void testStopRecording() {
452452
assertEquals("BXML strings not equal", expected, response);
453453
}
454454

455+
@Test
456+
public void testStartStream() {
457+
StartStream startStream = StartStream.builder()
458+
.destination("https://url.com")
459+
.streamEventMethod("POST")
460+
.username("user")
461+
.password("pass")
462+
.name("test")
463+
.tracks("inbound")
464+
.streamEventUrl("https://url.com")
465+
.build();
466+
467+
String response = new Response()
468+
.add(startStream)
469+
.toBXML();
470+
471+
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>";
472+
473+
assertEquals("BXML strings not equal", expected, response);
474+
}
475+
@Test
476+
public void testStopStream() {
477+
StopStream stopStream = StopStream.builder()
478+
.name("test")
479+
.build();
480+
481+
String response = new Response()
482+
.add(stopStream)
483+
.toBXML();
484+
485+
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopStream name=\"test\"/></Response>";
486+
487+
assertEquals("BXML strings not equal", expected, response);
488+
}
489+
455490
@Test
456491
public void testRing() {
457492
Ring ring = Ring.builder()

0 commit comments

Comments
 (0)