Skip to content

Commit

Permalink
Add missing Broadcast & SIP fields (#244)
Browse files Browse the repository at this point in the history
* Added missing fields to Broadcast

* Added SIP stream selection

* Bump version: v4.11.0 → v4.12.0
  • Loading branch information
SMadani authored Aug 22, 2023
1 parent 8199113 commit e0bc90a
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = False
current_version = v4.11.0
current_version = v4.12.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ When you use Maven as your build tool, you can manage dependencies in the `pom.x
<dependency>
<groupId>com.tokbox</groupId>
<artifactId>opentok-server-sdk</artifactId>
<version>4.11.0</version>
<version>4.12.0</version>
</dependency>
```

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

```groovy
dependencies {
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.11.0'
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.12.0'
}
```

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

group = 'com.tokbox'
archivesBaseName = 'opentok-server-sdk'
version = '4.11.0'
version = '4.12.0'
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand All @@ -30,8 +30,8 @@ dependencies {

implementation 'commons-lang:commons-lang:2.6'
implementation 'commons-codec:commons-codec:1.16.0'
implementation 'io.netty:netty-codec-http:4.1.94.Final'
implementation 'io.netty:netty-handler:4.1.94.Final'
implementation 'io.netty:netty-codec-http:4.1.96.Final'
implementation 'io.netty:netty-handler:4.1.96.Final'
implementation 'org.asynchttpclient:async-http-client:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
implementation 'org.bitbucket.b_c:jose4j:0.9.3'
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/opentok/Broadcast.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ public String toString() {
@JsonProperty private int projectId;
@JsonProperty private long createdAt;
@JsonProperty private long updatedAt;
@JsonProperty private int maxDuration;
@JsonProperty private int maxBitrate;
@JsonProperty private String resolution;
@JsonProperty private String status;
@JsonProperty private String hlsStatus;
@JsonProperty private String multiBroadcastTag;
@JsonProperty private boolean hasAudio = true;
@JsonProperty private boolean hasVideo = true;
Expand Down Expand Up @@ -112,6 +115,24 @@ public long getUpdatedAt() {
return updatedAt;
}

/**
* The maximum duration of the broadcast in seconds.
*
* @return The maximum duration.
*/
public int getMaxDuration() {
return maxDuration;
}

/**
* Maximum bitrate (bits per second) is an optional value allowed for the broadcast composing.
*
* @return The maximum bitrate.
*/
public int getMaxBitrate() {
return maxBitrate;
}

/**
* The broadcast resolution.
*/
Expand Down Expand Up @@ -145,13 +166,15 @@ public String getMultiBroadcastTag() {
private void unpack(Map<String,Object> broadcastUrls) {
if (broadcastUrls == null) return;
hls = (String) broadcastUrls.get("hls");
hlsStatus = (String) broadcastUrls.get("hlsStatus");
Iterable<Map<String,String>> rtmpResponse = (Iterable<Map<String,String>>)broadcastUrls.get("rtmp");
if (rtmpResponse == null) return;
for (Map<String,String> element : rtmpResponse) {
Rtmp rtmp = new Rtmp();
rtmp.setId(element.get("id"));
rtmp.setServerUrl(element.get("serverUrl"));
rtmp.setStreamName(element.get("streamName"));
rtmp.setStatus(element.get("status"));
this.rtmpList.add(rtmp);
}
}
Expand All @@ -163,6 +186,15 @@ public String getHls() {
return hls;
}

/**
* The HLS status of the broadcast if known. One of: "connecting", "ready", "live", "ended", "error".
*
* @return The HLS status as a string (if applicable).
*/
public String getHlsStatus() {
return hlsStatus;
}

/**
* A list of RTMP URLs (if there are any) of the broadcast.
*/
Expand Down
53 changes: 40 additions & 13 deletions src/main/java/com/opentok/BroadcastProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class BroadcastProperties {
private final BroadcastLayout layout;
private final int maxDuration;
private final int maxBitrate;
private final boolean hasHls;
private final boolean hasAudio;
private final boolean hasVideo;
Expand All @@ -31,16 +32,17 @@ public class BroadcastProperties {
private final Hls hls;

private BroadcastProperties(Builder builder) {
this.layout = builder.layout;
this.maxDuration = builder.maxDuration;
this.hasHls = builder.hasHls;
this.hasAudio = builder.hasAudio;
this.hasVideo = builder.hasVideo;
this.hls = builder.hls;
this.rtmpList = builder.rtmpList;
this.resolution = builder.resolution;
this.streamMode = builder.streamMode;
this.multiBroadcastTag = builder.multiBroadcastTag;
layout = builder.layout;
maxDuration = builder.maxDuration;
maxBitrate = builder.maxBitrate;
hasHls = builder.hasHls;
hasAudio = builder.hasAudio;
hasVideo = builder.hasVideo;
hls = builder.hls;
rtmpList = builder.rtmpList;
resolution = builder.resolution;
streamMode = builder.streamMode;
multiBroadcastTag = builder.multiBroadcastTag;
}

/**
Expand All @@ -51,6 +53,7 @@ private BroadcastProperties(Builder builder) {
public static class Builder {
private BroadcastLayout layout = new BroadcastLayout(BroadcastLayout.Type.BESTFIT);
private int maxDuration = 7200;
private int maxBitrate = 2_000_000;
private boolean hasHls = false;
private boolean hasAudio = true;
private boolean hasVideo = true;
Expand All @@ -67,7 +70,7 @@ public static class Builder {
*
* @return The BroadcastProperties.Builder object with the layout setting.
*/
public Builder layout(BroadcastLayout layout){
public Builder layout(BroadcastLayout layout) {
this.layout = layout;
return this;
}
Expand All @@ -82,14 +85,31 @@ public Builder layout(BroadcastLayout layout){
*
* @return The BroadcastProperties.Builder object with the maxDuration setting.
*/
public Builder maxDuration(int maxDuration) throws InvalidArgumentException {
if (maxDuration < 60 || maxDuration > 36000) {
public Builder maxDuration(int maxDuration) throws InvalidArgumentException {
if (maxDuration < 60 || maxDuration > 36_000) {
throw new InvalidArgumentException("maxDuration value must be between 60 and 36000 (inclusive).");
}
this.maxDuration = maxDuration;
return this;
}

/**
* Sets the maximum bitrate in bits per second for broadcast composing.
*
* @param maxBitrate The maximum bitrate in bits per second.
*
* @return The BroadcastProperties.Builder object with the maxBitrate setting.
*
* @throws InvalidArgumentException If the bitrate is out of bounds.
*/
public Builder maxBitrate(int maxBitrate) throws InvalidArgumentException {
if (maxBitrate < 100_000 || maxBitrate > 6_000_000) {
throw new InvalidArgumentException("maxBitrate value must be between 100_000 and 6_000_000.");
}
this.maxBitrate = maxBitrate;
return this;
}

/**
* Call this method to include an HLS broadcast (<code>true</code>) or not <code>false</code>).
*
Expand Down Expand Up @@ -229,6 +249,13 @@ public int maxDuration() {
return maxDuration;
}

/**
* The maximum bitrate in bits per second of the broadcast.
*/
public int maxBitrate() {
return maxBitrate;
}

/**
* Whether the broadcast has HLS (<code>true</code>) or not (<code>false</code>).
*/
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/opentok/OpenTok.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/opentok/Rtmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* Represents an RTMP stream in an OpenTok session.
*/
@JsonIgnoreProperties(ignoreUnknown=true)

public class Rtmp {
public String id;
private String serverUrl;
private String streamName;
private String status;

/**
* The stream ID.
Expand All @@ -28,6 +28,7 @@ public void setId(String id) {
public String getId() {
return id;
}

/**
* The RTMP server URL.
*/
Expand All @@ -37,6 +38,7 @@ public void setServerUrl(String serverUrl) {
public String getServerUrl() {
return serverUrl;
}

/**
* The stream name.
*/
Expand All @@ -46,5 +48,15 @@ public void setStreamName(String streamName) {
public String getStreamName() {
return streamName;
}

/**
* @return The RTMP status.
*/
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

53 changes: 42 additions & 11 deletions src/main/java/com/opentok/SipProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
package com.opentok;

import java.util.Arrays;
import java.util.List;

/**
* Defines values for the <code>properties</code> parameter of the
* {@link OpenTok#dial(String, String, SipProperties)} method.
Expand All @@ -22,16 +25,18 @@ public class SipProperties {
private Boolean secure;
private Boolean video;
private Boolean observeForceMute;
private String[] streams;

private SipProperties(Builder builder) {
this.sipUri = builder.sipUri;
this.from = builder.from;
this.userName = builder.userName;
this.password = builder.password;
this.headersJsonStartingWithXDash = builder.headersJsonStartingWithXDash;
this.secure = builder.secure;
this.video = builder.video;
this.observeForceMute = builder.observeForceMute;
sipUri = builder.sipUri;
from = builder.from;
userName = builder.userName;
password = builder.password;
headersJsonStartingWithXDash = builder.headersJsonStartingWithXDash;
secure = builder.secure;
video = builder.video;
observeForceMute = builder.observeForceMute;
streams = builder.streams;
}

/**
Expand All @@ -48,7 +53,7 @@ public static class Builder {
private boolean secure = false;
private boolean video = false;
private boolean observeForceMute = false;

private String[] streams = null;

/**
* Call this method to set the SIP URI.
Expand Down Expand Up @@ -167,6 +172,19 @@ public Builder observeForceMute(boolean observeForceMute) {
return this;
}

/**
* The stream IDs of the participants' which will be subscribed by the SIP participant.
* If not provided, all streams in session will be selected.
*
* @param streams Stream IDs to select.
*
* @return The SipProperties.Builder object with the streams setting.
*/
public Builder streams(String... streams) {
this.streams = streams;
return this;
}

/**
* Builds the SipProperties object.
*
Expand Down Expand Up @@ -222,10 +240,23 @@ public boolean secure() {
/**
* Return the video value (<code>true</code> or <code>false</code>).
*/
public boolean video() { return video; }
public boolean video() {
return video;
}

/**
* Returns the observeForceMute value (<code>true</code> or <code>false</code>).
*/
public boolean observeForceMute() { return observeForceMute; }
public boolean observeForceMute() {
return observeForceMute;
}

/**
* Returns the subscribed stream IDs.
*
* @return The selected stream IDs as an array.
*/
public String[] streams() {
return streams;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/opentok/constants/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
package com.opentok.constants;

public class Version {
public static final String VERSION = "4.11.0";
public static final String VERSION = "4.12.0";
}
12 changes: 12 additions & 0 deletions src/main/java/com/opentok/util/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
if (properties.maxDuration() > 0) {
requestJson.put("maxDuration", properties.maxDuration());
}
if (properties.maxBitrate() > 0) {
requestJson.put("maxBitrate", properties.maxBitrate());
}
if (properties.resolution() != null) {
requestJson.put("resolution", properties.resolution());
}
Expand Down Expand Up @@ -822,6 +825,15 @@ public String sipDial(String sessionId, String token, SipProperties props) throw
jGenerator.writeFieldName("observeForceMute");
jGenerator.writeBoolean(props.observeForceMute());

String[] streams = props.streams();
if (streams != null && streams.length > 0) {
jGenerator.writeArrayFieldStart("streams");
for (String streamId : streams) {
jGenerator.writeString(streamId);
}
jGenerator.writeEndArray();
}

jGenerator.writeEndObject(); // end sip
jGenerator.writeEndObject(); // end main object
jGenerator.close();
Expand Down
Loading

0 comments on commit e0bc90a

Please sign in to comment.