Skip to content

Commit e0bc90a

Browse files
authored
Add missing Broadcast & SIP fields (#244)
* Added missing fields to Broadcast * Added SIP stream selection * Bump version: v4.11.0 → v4.12.0
1 parent 8199113 commit e0bc90a

File tree

11 files changed

+167
-46
lines changed

11 files changed

+167
-46
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
commit = True
33
tag = False
4-
current_version = v4.11.0
4+
current_version = v4.12.0
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
66
serialize =
77
{major}.{minor}.{patch}-{release}{build}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ When you use Maven as your build tool, you can manage dependencies in the `pom.x
3434
<dependency>
3535
<groupId>com.tokbox</groupId>
3636
<artifactId>opentok-server-sdk</artifactId>
37-
<version>4.11.0</version>
37+
<version>4.12.0</version>
3838
</dependency>
3939
```
4040

@@ -44,7 +44,7 @@ When you use Gradle as your build tool, you can manage dependencies in the `buil
4444

4545
```groovy
4646
dependencies {
47-
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.11.0'
47+
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.12.0'
4848
}
4949
```
5050

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111

1212
group = 'com.tokbox'
1313
archivesBaseName = 'opentok-server-sdk'
14-
version = '4.11.0'
14+
version = '4.12.0'
1515
sourceCompatibility = "1.8"
1616
targetCompatibility = "1.8"
1717

@@ -30,8 +30,8 @@ dependencies {
3030

3131
implementation 'commons-lang:commons-lang:2.6'
3232
implementation 'commons-codec:commons-codec:1.16.0'
33-
implementation 'io.netty:netty-codec-http:4.1.94.Final'
34-
implementation 'io.netty:netty-handler:4.1.94.Final'
33+
implementation 'io.netty:netty-codec-http:4.1.96.Final'
34+
implementation 'io.netty:netty-handler:4.1.96.Final'
3535
implementation 'org.asynchttpclient:async-http-client:2.12.3'
3636
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
3737
implementation 'org.bitbucket.b_c:jose4j:0.9.3'

src/main/java/com/opentok/Broadcast.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ public String toString() {
5252
@JsonProperty private int projectId;
5353
@JsonProperty private long createdAt;
5454
@JsonProperty private long updatedAt;
55+
@JsonProperty private int maxDuration;
56+
@JsonProperty private int maxBitrate;
5557
@JsonProperty private String resolution;
5658
@JsonProperty private String status;
59+
@JsonProperty private String hlsStatus;
5760
@JsonProperty private String multiBroadcastTag;
5861
@JsonProperty private boolean hasAudio = true;
5962
@JsonProperty private boolean hasVideo = true;
@@ -112,6 +115,24 @@ public long getUpdatedAt() {
112115
return updatedAt;
113116
}
114117

118+
/**
119+
* The maximum duration of the broadcast in seconds.
120+
*
121+
* @return The maximum duration.
122+
*/
123+
public int getMaxDuration() {
124+
return maxDuration;
125+
}
126+
127+
/**
128+
* Maximum bitrate (bits per second) is an optional value allowed for the broadcast composing.
129+
*
130+
* @return The maximum bitrate.
131+
*/
132+
public int getMaxBitrate() {
133+
return maxBitrate;
134+
}
135+
115136
/**
116137
* The broadcast resolution.
117138
*/
@@ -145,13 +166,15 @@ public String getMultiBroadcastTag() {
145166
private void unpack(Map<String,Object> broadcastUrls) {
146167
if (broadcastUrls == null) return;
147168
hls = (String) broadcastUrls.get("hls");
169+
hlsStatus = (String) broadcastUrls.get("hlsStatus");
148170
Iterable<Map<String,String>> rtmpResponse = (Iterable<Map<String,String>>)broadcastUrls.get("rtmp");
149171
if (rtmpResponse == null) return;
150172
for (Map<String,String> element : rtmpResponse) {
151173
Rtmp rtmp = new Rtmp();
152174
rtmp.setId(element.get("id"));
153175
rtmp.setServerUrl(element.get("serverUrl"));
154176
rtmp.setStreamName(element.get("streamName"));
177+
rtmp.setStatus(element.get("status"));
155178
this.rtmpList.add(rtmp);
156179
}
157180
}
@@ -163,6 +186,15 @@ public String getHls() {
163186
return hls;
164187
}
165188

189+
/**
190+
* The HLS status of the broadcast if known. One of: "connecting", "ready", "live", "ended", "error".
191+
*
192+
* @return The HLS status as a string (if applicable).
193+
*/
194+
public String getHlsStatus() {
195+
return hlsStatus;
196+
}
197+
166198
/**
167199
* A list of RTMP URLs (if there are any) of the broadcast.
168200
*/

src/main/java/com/opentok/BroadcastProperties.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public class BroadcastProperties {
2222
private final BroadcastLayout layout;
2323
private final int maxDuration;
24+
private final int maxBitrate;
2425
private final boolean hasHls;
2526
private final boolean hasAudio;
2627
private final boolean hasVideo;
@@ -31,16 +32,17 @@ public class BroadcastProperties {
3132
private final Hls hls;
3233

3334
private BroadcastProperties(Builder builder) {
34-
this.layout = builder.layout;
35-
this.maxDuration = builder.maxDuration;
36-
this.hasHls = builder.hasHls;
37-
this.hasAudio = builder.hasAudio;
38-
this.hasVideo = builder.hasVideo;
39-
this.hls = builder.hls;
40-
this.rtmpList = builder.rtmpList;
41-
this.resolution = builder.resolution;
42-
this.streamMode = builder.streamMode;
43-
this.multiBroadcastTag = builder.multiBroadcastTag;
35+
layout = builder.layout;
36+
maxDuration = builder.maxDuration;
37+
maxBitrate = builder.maxBitrate;
38+
hasHls = builder.hasHls;
39+
hasAudio = builder.hasAudio;
40+
hasVideo = builder.hasVideo;
41+
hls = builder.hls;
42+
rtmpList = builder.rtmpList;
43+
resolution = builder.resolution;
44+
streamMode = builder.streamMode;
45+
multiBroadcastTag = builder.multiBroadcastTag;
4446
}
4547

4648
/**
@@ -51,6 +53,7 @@ private BroadcastProperties(Builder builder) {
5153
public static class Builder {
5254
private BroadcastLayout layout = new BroadcastLayout(BroadcastLayout.Type.BESTFIT);
5355
private int maxDuration = 7200;
56+
private int maxBitrate = 2_000_000;
5457
private boolean hasHls = false;
5558
private boolean hasAudio = true;
5659
private boolean hasVideo = true;
@@ -67,7 +70,7 @@ public static class Builder {
6770
*
6871
* @return The BroadcastProperties.Builder object with the layout setting.
6972
*/
70-
public Builder layout(BroadcastLayout layout){
73+
public Builder layout(BroadcastLayout layout) {
7174
this.layout = layout;
7275
return this;
7376
}
@@ -82,14 +85,31 @@ public Builder layout(BroadcastLayout layout){
8285
*
8386
* @return The BroadcastProperties.Builder object with the maxDuration setting.
8487
*/
85-
public Builder maxDuration(int maxDuration) throws InvalidArgumentException {
86-
if (maxDuration < 60 || maxDuration > 36000) {
88+
public Builder maxDuration(int maxDuration) throws InvalidArgumentException {
89+
if (maxDuration < 60 || maxDuration > 36_000) {
8790
throw new InvalidArgumentException("maxDuration value must be between 60 and 36000 (inclusive).");
8891
}
8992
this.maxDuration = maxDuration;
9093
return this;
9194
}
9295

96+
/**
97+
* Sets the maximum bitrate in bits per second for broadcast composing.
98+
*
99+
* @param maxBitrate The maximum bitrate in bits per second.
100+
*
101+
* @return The BroadcastProperties.Builder object with the maxBitrate setting.
102+
*
103+
* @throws InvalidArgumentException If the bitrate is out of bounds.
104+
*/
105+
public Builder maxBitrate(int maxBitrate) throws InvalidArgumentException {
106+
if (maxBitrate < 100_000 || maxBitrate > 6_000_000) {
107+
throw new InvalidArgumentException("maxBitrate value must be between 100_000 and 6_000_000.");
108+
}
109+
this.maxBitrate = maxBitrate;
110+
return this;
111+
}
112+
93113
/**
94114
* Call this method to include an HLS broadcast (<code>true</code>) or not <code>false</code>).
95115
*
@@ -229,6 +249,13 @@ public int maxDuration() {
229249
return maxDuration;
230250
}
231251

252+
/**
253+
* The maximum bitrate in bits per second of the broadcast.
254+
*/
255+
public int maxBitrate() {
256+
return maxBitrate;
257+
}
258+
232259
/**
233260
* Whether the broadcast has HLS (<code>true</code>) or not (<code>false</code>).
234261
*/

src/main/java/com/opentok/OpenTok.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.IOException;
2424
import java.io.UnsupportedEncodingException;
2525
import java.net.Proxy;
26-
import java.util.Collection;
2726
import java.util.List;
2827
import java.util.Map;
2928

src/main/java/com/opentok/Rtmp.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* Represents an RTMP stream in an OpenTok session.
1414
*/
1515
@JsonIgnoreProperties(ignoreUnknown=true)
16-
1716
public class Rtmp {
1817
public String id;
1918
private String serverUrl;
2019
private String streamName;
20+
private String status;
2121

2222
/**
2323
* The stream ID.
@@ -28,6 +28,7 @@ public void setId(String id) {
2828
public String getId() {
2929
return id;
3030
}
31+
3132
/**
3233
* The RTMP server URL.
3334
*/
@@ -37,6 +38,7 @@ public void setServerUrl(String serverUrl) {
3738
public String getServerUrl() {
3839
return serverUrl;
3940
}
41+
4042
/**
4143
* The stream name.
4244
*/
@@ -46,5 +48,15 @@ public void setStreamName(String streamName) {
4648
public String getStreamName() {
4749
return streamName;
4850
}
51+
52+
/**
53+
* @return The RTMP status.
54+
*/
55+
public String getStatus() {
56+
return status;
57+
}
58+
public void setStatus(String status) {
59+
this.status = status;
60+
}
4961
}
5062

src/main/java/com/opentok/SipProperties.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
package com.opentok;
99

10+
import java.util.Arrays;
11+
import java.util.List;
12+
1013
/**
1114
* Defines values for the <code>properties</code> parameter of the
1215
* {@link OpenTok#dial(String, String, SipProperties)} method.
@@ -22,16 +25,18 @@ public class SipProperties {
2225
private Boolean secure;
2326
private Boolean video;
2427
private Boolean observeForceMute;
28+
private String[] streams;
2529

2630
private SipProperties(Builder builder) {
27-
this.sipUri = builder.sipUri;
28-
this.from = builder.from;
29-
this.userName = builder.userName;
30-
this.password = builder.password;
31-
this.headersJsonStartingWithXDash = builder.headersJsonStartingWithXDash;
32-
this.secure = builder.secure;
33-
this.video = builder.video;
34-
this.observeForceMute = builder.observeForceMute;
31+
sipUri = builder.sipUri;
32+
from = builder.from;
33+
userName = builder.userName;
34+
password = builder.password;
35+
headersJsonStartingWithXDash = builder.headersJsonStartingWithXDash;
36+
secure = builder.secure;
37+
video = builder.video;
38+
observeForceMute = builder.observeForceMute;
39+
streams = builder.streams;
3540
}
3641

3742
/**
@@ -48,7 +53,7 @@ public static class Builder {
4853
private boolean secure = false;
4954
private boolean video = false;
5055
private boolean observeForceMute = false;
51-
56+
private String[] streams = null;
5257

5358
/**
5459
* Call this method to set the SIP URI.
@@ -167,6 +172,19 @@ public Builder observeForceMute(boolean observeForceMute) {
167172
return this;
168173
}
169174

175+
/**
176+
* The stream IDs of the participants' which will be subscribed by the SIP participant.
177+
* If not provided, all streams in session will be selected.
178+
*
179+
* @param streams Stream IDs to select.
180+
*
181+
* @return The SipProperties.Builder object with the streams setting.
182+
*/
183+
public Builder streams(String... streams) {
184+
this.streams = streams;
185+
return this;
186+
}
187+
170188
/**
171189
* Builds the SipProperties object.
172190
*
@@ -222,10 +240,23 @@ public boolean secure() {
222240
/**
223241
* Return the video value (<code>true</code> or <code>false</code>).
224242
*/
225-
public boolean video() { return video; }
243+
public boolean video() {
244+
return video;
245+
}
226246

227247
/**
228248
* Returns the observeForceMute value (<code>true</code> or <code>false</code>).
229249
*/
230-
public boolean observeForceMute() { return observeForceMute; }
250+
public boolean observeForceMute() {
251+
return observeForceMute;
252+
}
253+
254+
/**
255+
* Returns the subscribed stream IDs.
256+
*
257+
* @return The selected stream IDs as an array.
258+
*/
259+
public String[] streams() {
260+
return streams;
261+
}
231262
}

src/main/java/com/opentok/constants/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
package com.opentok.constants;
99

1010
public class Version {
11-
public static final String VERSION = "4.11.0";
11+
public static final String VERSION = "4.12.0";
1212
}

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
513513
if (properties.maxDuration() > 0) {
514514
requestJson.put("maxDuration", properties.maxDuration());
515515
}
516+
if (properties.maxBitrate() > 0) {
517+
requestJson.put("maxBitrate", properties.maxBitrate());
518+
}
516519
if (properties.resolution() != null) {
517520
requestJson.put("resolution", properties.resolution());
518521
}
@@ -822,6 +825,15 @@ public String sipDial(String sessionId, String token, SipProperties props) throw
822825
jGenerator.writeFieldName("observeForceMute");
823826
jGenerator.writeBoolean(props.observeForceMute());
824827

828+
String[] streams = props.streams();
829+
if (streams != null && streams.length > 0) {
830+
jGenerator.writeArrayFieldStart("streams");
831+
for (String streamId : streams) {
832+
jGenerator.writeString(streamId);
833+
}
834+
jGenerator.writeEndArray();
835+
}
836+
825837
jGenerator.writeEndObject(); // end sip
826838
jGenerator.writeEndObject(); // end main object
827839
jGenerator.close();

0 commit comments

Comments
 (0)