Skip to content

Commit b31cd1d

Browse files
DX-2700
1 parent b0a258c commit b31cd1d

File tree

5 files changed

+168
-4
lines changed

5 files changed

+168
-4
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3-
org.eclipse.jdt.core.compiler.compliance=1.5
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
45
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5-
org.eclipse.jdt.core.compiler.source=1.5
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.processAnnotations=enabled
8+
org.eclipse.jdt.core.compiler.release=disabled
9+
org.eclipse.jdt.core.compiler.source=1.8

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

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 = "StartRecording";
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import lombok.Builder;
5+
6+
import javax.xml.bind.annotation.XmlType;
7+
8+
/**
9+
* The StopStream verb is used to stop a stream previously started by a `<StartStream>` verb.
10+
*/
11+
@Builder
12+
@XmlType(name = StopStream.TYPE_NAME)
13+
public class StopStream implements Verb {
14+
public static final String TYPE_NAME = "StopStream";
15+
16+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,38 @@ 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+
.streamEventUrl("https://url.com")
464+
.build();
465+
466+
String response = new Response()
467+
.add(startStream)
468+
.toBXML();
469+
470+
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartStream destination=\"https://url.com\" streamEventMethod=\"POST\" username=\"user\" password=\"pass\" name=\"test\" streamEventUrl=\"https://url.com\"/></Response>";
471+
472+
assertEquals("BXML strings not equal", expected, response);
473+
}
474+
@Test
475+
public void testStopStream() {
476+
StopStream stopStream = StopStream.builder().build();
477+
478+
String response = new Response()
479+
.add(stopStream)
480+
.toBXML();
481+
482+
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopRecording/></Response>";
483+
484+
assertEquals("BXML strings not equal", expected, response);
485+
}
486+
455487
@Test
456488
public void testRing() {
457489
Ring ring = Ring.builder()

0 commit comments

Comments
 (0)