Skip to content

Commit edf766f

Browse files
SMadanijeffswartz
andcommitted
Added support for MultiBroadcastTag and MultiArchiveTag (#226)
* Added multiArchiveTag * Added multiBroadcastTag * Updated docs * Removed getMulti*Tag from responses * Revert "Removed getMulti*Tag from responses" This reverts commit 6e7f123. * Docs edits re multiArchive/BroadcastTag. Co-authored-by: Jeff Swartz <jeff.swartz@vonage.com>
1 parent 63c6886 commit edf766f

File tree

8 files changed

+103
-22
lines changed

8 files changed

+103
-22
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
implementation 'commons-lang:commons-lang:2.6'
2626
implementation 'commons-validator:commons-validator:1.7'
2727
implementation 'org.asynchttpclient:async-http-client:2.12.3'
28-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
28+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
2929
implementation 'commons-codec:commons-codec:1.15'
3030
implementation 'org.bitbucket.b_c:jose4j:0.7.12'
3131
}
@@ -150,8 +150,8 @@ publishing {
150150
}
151151

152152
signing {
153-
def signingKey = System.getenv("signingKey")
154-
def signingPassword = System.getenv("signingPassword")
153+
def signingKey = findProperty("signingKey")
154+
def signingPassword = findProperty("signingPassword")
155155
useInMemoryPgpKeys(signingKey, signingPassword)
156156
sign publishing.publications.mavenJava
157157
}

src/main/java/com/opentok/Archive.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ public enum Status {
6363
*/
6464
EXPIRED;
6565

66-
@JsonValue public String toString() {
67-
return super.toString().toLowerCase();
66+
@JsonValue
67+
public String toString() {
68+
return name().toLowerCase();
6869
}
6970
}
7071

@@ -105,7 +106,10 @@ public enum StreamMode {
105106
*/
106107
MANUAL;
107108

108-
@JsonValue public String toString() { return super.toString().toLowerCase(); }
109+
@JsonValue
110+
public String toString() {
111+
return name().toLowerCase();
112+
}
109113
}
110114

111115
@JsonProperty private long createdAt;
@@ -124,6 +128,7 @@ public enum StreamMode {
124128
@JsonProperty private StreamMode streamMode = StreamMode.AUTO;
125129
@JsonProperty private String password;
126130
@JsonProperty private String resolution;
131+
@JsonProperty private String multiArchiveTag;
127132

128133
protected Archive() {
129134
}
@@ -252,6 +257,13 @@ public String getPassword() {
252257
return password;
253258
}
254259

260+
/**
261+
* Returns the multiArchiveTag if set for the Archive.
262+
*/
263+
public String getMultiArchiveTag() {
264+
return multiArchiveTag;
265+
}
266+
255267
@Override
256268
public String toString() {
257269
try {

src/main/java/com/opentok/ArchiveMode.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@ public enum ArchiveMode {
1717
* The session is not archived automatically. To archive the session, you can call the
1818
* OpenTok.StartArchive() method.
1919
*/
20-
MANUAL ("manual"),
20+
MANUAL,
2121

2222
/**
2323
* The session is archived automatically (as soon as there are clients connected
2424
* to the session).
2525
*/
26-
ALWAYS ("always");
27-
28-
private String serialized;
29-
30-
ArchiveMode(String s) {
31-
serialized = s;
32-
}
26+
ALWAYS;
3327

3428
@Override
3529
public String toString() {
36-
return serialized;
30+
return name().toLowerCase();
3731
}
3832
}

src/main/java/com/opentok/ArchiveProperties.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
* @see OpenTok#createSession(com.opentok.SessionProperties properties)
2424
*/
2525
public class ArchiveProperties {
26-
27-
2826
private String name;
2927
private String resolution;
28+
private String multiArchiveTag;
3029
private boolean hasAudio;
3130
private boolean hasVideo;
3231
private OutputMode outputMode;
@@ -41,6 +40,7 @@ private ArchiveProperties(Builder builder) {
4140
this.outputMode = builder.outputMode;
4241
this.streamMode = builder.streamMode;
4342
this.layout = builder.layout;
43+
this.multiArchiveTag = builder.multiArchiveTag;
4444
}
4545

4646
/**
@@ -51,6 +51,7 @@ private ArchiveProperties(Builder builder) {
5151
public static class Builder {
5252
private String name = null;
5353
private String resolution = null;
54+
private String multiArchiveTag = null;
5455
private boolean hasAudio = true;
5556
private boolean hasVideo = true;
5657
private OutputMode outputMode = OutputMode.COMPOSED;
@@ -125,7 +126,7 @@ public Builder outputMode(OutputMode outputMode) {
125126

126127
/**
127128
* Sets the stream mode for this archive.
128-
*
129+
* <p>
129130
* When streams are selected automatically (<code>StreamMode.AUTO</code>, the default), all
130131
* streams in the session can be included in the archive. When streams are selected manually
131132
* (<code>StreamMode.MANUAL</code>), you specify streams to be included based on calls
@@ -151,13 +152,30 @@ public Builder streamMode(StreamMode streamMode) {
151152
*
152153
* @param layout An object of type {@link ArchiveLayout} .
153154
*
154-
* @return The ArchiveProperties.Builder object with the output mode setting.
155+
* @return The ArchiveProperties.Builder object with the layout setting.
155156
*/
156157
public Builder layout(ArchiveLayout layout) {
157158
this.layout = layout;
158159
return this;
159160
}
160161

162+
/**
163+
* Set this to support recording multiple archives for the same session simultaneously.
164+
* Set this to a unique string for each simultaneous archive of an ongoing session. You must also set this
165+
* option when manually starting an archive that is automatically archived. If you do
166+
* not specify a unique multiArchiveTag, you can only record one archive at a time for a given session. See
167+
* <a href="https://tokbox.com/developer/guides/archiving/#simultaneous-archives">
168+
* Simultaneous Archives documentation</a>.
169+
*
170+
* @param multiArchiveTag A unique archive tag.
171+
*
172+
* @return The ArchiveProperties.Builder object with the MultiArchiveTag setting.
173+
*/
174+
public Builder multiArchiveTag(String multiArchiveTag) {
175+
this.multiArchiveTag = multiArchiveTag;
176+
return this;
177+
}
178+
161179
/**
162180
* Builds the ArchiveProperties object.
163181
*
@@ -182,6 +200,13 @@ public String resolution() {
182200
return resolution;
183201
}
184202

203+
/**
204+
* Returns the multiArchiveTag, if present.
205+
*/
206+
public String getMultiArchiveTag() {
207+
return multiArchiveTag;
208+
}
209+
185210
/**
186211
* Whether the archive has a video track (<code>true</code>) or not (<code>false</code>).
187212
*/
@@ -252,6 +277,12 @@ public Map<String, Collection<String>> toMap() {
252277
params.put("layout", valueList);
253278
}
254279

280+
if (multiArchiveTag != null) {
281+
valueList = new ArrayList<>();
282+
valueList.add(multiArchiveTag);
283+
params.put("multiArchiveTag", valueList);
284+
}
285+
255286
return params;
256287
}
257288

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public enum StreamMode {
5151
@JsonProperty private long updatedAt;
5252
@JsonProperty private String resolution;
5353
@JsonProperty private String status;
54+
@JsonProperty private String multiBroadcastTag;
5455
@JsonProperty private StreamMode streamMode = StreamMode.AUTO;
5556
private List<Rtmp> rtmpList = new ArrayList<>();
5657
private String hls;
@@ -120,6 +121,13 @@ public String getStatus() {
120121
return status;
121122
}
122123

124+
/**
125+
* Returns the multiBroadcastTag if set for the Broadcast.
126+
*/
127+
public String getMultiBroadcastTag() {
128+
return multiBroadcastTag;
129+
}
130+
123131
/**
124132
* Details on the HLS and RTMP broadcast streams. For an HLS stream, the URL is provided.
125133
* See the <a href="https://tokbox.com/developer/guides/broadcast/live-streaming/">OpenTok

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
* {@link OpenTok#startBroadcast(String sessionId, BroadcastProperties properties)} method.
2020
*/
2121
public class BroadcastProperties {
22-
2322
private BroadcastLayout layout;
2423
private int maxDuration;
2524
private boolean hasHls;
2625
private List<RtmpProperties> rtmpList;
2726
private String resolution;
27+
private String multiBroadcastTag;
2828
private StreamMode streamMode;
2929
private Hls hls;
3030

@@ -36,6 +36,7 @@ private BroadcastProperties(Builder builder) {
3636
this.rtmpList = builder.rtmpList;
3737
this.resolution = builder.resolution;
3838
this.streamMode = builder.streamMode;
39+
this.multiBroadcastTag = builder.multiBroadcastTag;
3940
}
4041

4142
/**
@@ -47,7 +48,7 @@ public static class Builder {
4748
private BroadcastLayout layout = new BroadcastLayout(BroadcastLayout.Type.BESTFIT);
4849
private int maxDuration = 7200;
4950
private boolean hasHls = false;
50-
51+
private String multiBroadcastTag;
5152
private Hls hls;
5253
private List<RtmpProperties> rtmpList = new ArrayList<>();
5354
private String resolution = "640x480";
@@ -64,6 +65,7 @@ public Builder layout(BroadcastLayout layout){
6465
this.layout = layout;
6566
return this;
6667
}
68+
6769
/**
6870
* Sets the maximum duration, in seconds, of the broadcast.
6971
* The broadcast will automatically stop when the maximum duration is reached.
@@ -157,6 +159,21 @@ public Builder streamMode(StreamMode streamMode) {
157159
return this;
158160
}
159161

162+
/**
163+
* Set this to support multiple broadcasts for the same session simultaneously.
164+
* Set this to a unique string for each simultaneous broadcast of an ongoing session. See
165+
* <a href="https://tokbox.com/developer/guides/broadcast/live-streaming#simultaneous-broadcasts">
166+
* Simultaneous Broadcasts documentation</a>.
167+
*
168+
* @param multiBroadcastTag A unique multi-broadcast tag.
169+
*
170+
* @return The BroadcastProperties.Builder object with the multiBroadcastTag setting.
171+
*/
172+
public Builder multiBroadcastTag(String multiBroadcastTag) {
173+
this.multiBroadcastTag = multiBroadcastTag;
174+
return this;
175+
}
176+
160177
/**
161178
* Builds the BroadcastProperties object.
162179
*
@@ -209,6 +226,13 @@ public String resolution() {
209226
return resolution;
210227
}
211228

229+
/**
230+
* Returns the multiBroadcastTag, if present.
231+
*/
232+
public String getMultiBroadcastTag() {
233+
return multiBroadcastTag;
234+
}
235+
212236
/**
213237
* The stream mode of the broadcast.
214238
*/

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ public String startArchive(String sessionId, ArchiveProperties properties) throw
215215
if (properties.resolution() != null) {
216216
requestJson.put("resolution", properties.resolution());
217217
}
218+
if (properties.getMultiArchiveTag() != null) {
219+
requestJson.put("multiArchiveTag", properties.getMultiArchiveTag());
220+
}
218221

219222
String requestBody;
220223
try {
@@ -519,6 +522,9 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
519522
if (properties.resolution() != null) {
520523
requestJson.put("resolution", properties.resolution());
521524
}
525+
if (properties.getMultiBroadcastTag() != null) {
526+
requestJson.put("multiBroadcastTag", properties.getMultiBroadcastTag());
527+
}
522528

523529
ObjectNode outputs = requestJson.putObject("outputs");
524530
if (properties.hasHls()) {

src/test/java/com/opentok/test/OpenTokTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ public void testListArchives() throws OpenTokException {
639639
" \"duration\" : 14,\n" +
640640
" \"id\" : \"5350f06f-0166-402e-bc27-09ba54948512\",\n" +
641641
" \"name\" : \"\",\n" +
642+
" \"multiArchiveTag\" : \"MyVideoArchiveTag\",\n" +
642643
" \"partnerId\" : 123456,\n" +
643644
" \"reason\" : \"\",\n" +
644645
" \"sessionId\" : \"SESSIONID\",\n" +
@@ -707,6 +708,7 @@ public void testListArchives() throws OpenTokException {
707708
assertEquals(60, archives.getTotalCount());
708709
assertNotNull(archives.get(0));
709710
assertEquals("ef546c5a-4fd7-4e59-ab3d-f1cfb4148d1d", archives.get(0).getId());
711+
assertEquals("MyVideoArchiveTag", archives.get(1).getMultiArchiveTag());
710712
verify(getRequestedFor(urlMatching(archivePath)));
711713
assertTrue(Helpers.verifyTokenAuth(apiKey, apiSecret,
712714
findAll(getRequestedFor(urlMatching(archivePath)))));
@@ -967,9 +969,10 @@ public void testStartArchive() throws OpenTokException {
967969
.outputMode(OutputMode.COMPOSED)
968970
.streamMode(Archive.StreamMode.AUTO)
969971
.resolution("1920x1080")
972+
.multiArchiveTag("MyArchiveTag")
970973
.build();
971974

972-
properties.toMap();
975+
assertNotNull(properties.toMap());
973976

974977
Archive archive = sdk.startArchive(sessionId, properties);
975978
assertNotNull(archive);
@@ -1711,6 +1714,7 @@ public void testStartBroadcast() throws OpenTokException {
17111714
" \"upDatedAt\" : 1437676551000,\n" +
17121715
" \"resolution\" : \"1280x720\",\n" +
17131716
" \"status\" : \"started\",\n" +
1717+
" \"multiBroadcastTag\" : \"MyVideoBroadcastTag\",\n" +
17141718
" \"broadcastUrls\" : {" +
17151719
" \"hls\" : \"http://server/fakepath/playlist.m3u8\"," +
17161720
" \"rtmp\" : [{" +
@@ -1737,6 +1741,7 @@ public void testStartBroadcast() throws OpenTokException {
17371741
.addRtmpProperties(rtmpNextProps)
17381742
.maxDuration(1000)
17391743
.resolution("640x480")
1744+
.multiBroadcastTag("MyVideoBroadcastTag")
17401745
.layout(layout)
17411746
.streamMode(Broadcast.StreamMode.AUTO)
17421747
.build();
@@ -1755,6 +1760,7 @@ public void testStartBroadcast() throws OpenTokException {
17551760
assertTrue(broadcast.getUpdatedAt() > -1);
17561761
assertTrue(broadcast.getProjectId() > -1);
17571762
assertEquals(sessionId, broadcast.getSessionId());
1763+
assertEquals("MyVideoBroadcastTag", broadcast.getMultiBroadcastTag());
17581764
assertEquals(Broadcast.StreamMode.AUTO, broadcast.getStreamMode());
17591765
assertNotNull(broadcast.getId());
17601766
verify(postRequestedFor(urlMatching(url)));

0 commit comments

Comments
 (0)