Skip to content

Commit 6206e88

Browse files
committed
Added support to outputMode
1 parent 8682230 commit 6206e88

File tree

6 files changed

+284
-17
lines changed

6 files changed

+284
-17
lines changed

sample/Archiving/src/main/java/com/example/ArchivingServer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ public Object handle(Request request, Response response) {
143143

144144
Archive archive = null;
145145
try {
146-
archive = opentok.startArchive(sessionId, "Java Archiving Sample App");
146+
ArchiveProperties properties = new ArchiveProperties.Builder()
147+
.name("Java Archiving Sample App").build();
148+
archive = opentok.startArchive(sessionId, properties);
147149
} catch (OpenTokException e) {
148150
e.printStackTrace();
149151
return null;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ public enum Status {
5757
}
5858
}
5959

60+
/**
61+
* Defines values returned by the {@link Archive#getOutputMode} method.
62+
*/
63+
public enum OutputMode {
64+
/**
65+
* The archive file is available for download from the OpenTok cloud. You can get the URL of
66+
* the download file by calling the {@link Archive#getUrl} method.
67+
*/
68+
COMPOSED,
69+
/**
70+
* The archive file has been deleted.
71+
*/
72+
INDIVIDUAL;
73+
74+
@JsonValue public String toString() {
75+
return super.toString().toLowerCase();
76+
}
77+
}
78+
6079
@JsonProperty private long createdAt;
6180
@JsonProperty private int duration = 0;
6281
@JsonProperty private String id;
@@ -69,6 +88,7 @@ public enum Status {
6988
@JsonProperty private String url;
7089
@JsonProperty private boolean hasVideo = true;
7190
@JsonProperty private boolean hasAudio = true;
91+
@JsonProperty private OutputMode outputMode = OutputMode.COMPOSED;
7292

7393
protected Archive() {
7494
}
@@ -169,6 +189,13 @@ public boolean hasAudio() {
169189
return hasAudio;
170190
}
171191

192+
/**
193+
* The output mode to be generated for this archive: <code>composed</code> or <code>individual</code>.
194+
*/
195+
public OutputMode getOutputMode() {
196+
return outputMode;
197+
}
198+
172199
@Override
173200
public String toString() {
174201
try {
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
* OpenTok Java SDK
3+
* Copyright (C) 2015 TokBox, Inc.
4+
* http://www.tokbox.com
5+
*
6+
* Licensed under The MIT License (MIT). See LICENSE file for more information.
7+
*/
8+
package com.opentok;
9+
10+
import com.opentok.Archive.OutputMode;
11+
12+
import java.util.ArrayList;
13+
import java.util.Collection;
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
17+
18+
/**
19+
* Defines values for the <code>properties</code> parameter of the
20+
* {@link OpenTok#createSession(SessionProperties)} method.
21+
*
22+
* @see OpenTok#createSession(com.opentok.SessionProperties properties)
23+
*/
24+
public class ArchiveProperties {
25+
26+
27+
private String name = null;
28+
private boolean hasAudio;
29+
private boolean hasVideo;
30+
private OutputMode outputMode;
31+
32+
private ArchiveProperties(Builder builder) {
33+
this.name = builder.name;
34+
this.hasAudio = builder.hasAudio;
35+
this.hasVideo = builder.hasVideo;
36+
this.outputMode = builder.outputMode;
37+
}
38+
39+
/**
40+
* Use this class to create a SessionProperties object.
41+
*
42+
* @see SessionProperties
43+
*/
44+
public static class Builder {
45+
private String name = null;
46+
private boolean hasAudio = true;
47+
private boolean hasVideo = true;
48+
private OutputMode outputMode = OutputMode.COMPOSED;
49+
50+
51+
/**
52+
* Call this method to set a name to the archive.
53+
*
54+
* @param name The name of the archive. You can use this name to identify the archive. It is a property
55+
* of the Archive object, and it is a property of archive-related events in the OpenTok JavaScript SDK.
56+
*
57+
* @return The ArchiveProperties.Builder object with the name setting.
58+
*/
59+
public Builder name(String name) {
60+
this.name = name;
61+
return this;
62+
}
63+
64+
/**
65+
* Call this method to include an audio track (<code>true</code>) or not <code>false</code>).
66+
*
67+
* @param hasAudio Whether the archive will include an audio track.
68+
*
69+
* @return The ArchiveProperties.Builder object with the hasAudio setting.
70+
*/
71+
public Builder hasAudio(boolean hasAudio) {
72+
this.hasAudio = hasAudio;
73+
return this;
74+
}
75+
76+
/**
77+
* Call this method to include an video track (<code>true</code>) or not <code>false</code>).
78+
*
79+
* @param hasVideo Whether the archive will include an video track.
80+
*
81+
* @return The ArchiveProperties.Builder object with the hasVideo setting.
82+
*/
83+
public Builder hasVideo(boolean hasVideo) {
84+
this.hasVideo = hasVideo;
85+
return this;
86+
}
87+
88+
/**
89+
* Call this method to choose the output mode to be generated for this archive.
90+
*
91+
* @param outputMode Set to a value defined in the {@link Archive.OutputMode} enum.
92+
*
93+
* @return The ArchiveProperties.Builder object with the output mode setting.
94+
*/
95+
public Builder outputMode(OutputMode outputMode) {
96+
this.outputMode = outputMode;
97+
return this;
98+
}
99+
100+
/**
101+
* Builds the ArchiveProperties object.
102+
*
103+
* @return The ArchiveProperties object.
104+
*/
105+
public ArchiveProperties build() {
106+
return new ArchiveProperties(this);
107+
}
108+
}
109+
/**
110+
* Returns the name of the archive, which you can use to identify the archive
111+
*/
112+
public String name() {
113+
return name;
114+
}
115+
/**
116+
* Whether the archive has a video track (<code>true</code>) or not (<code>false</code>).
117+
*/
118+
public boolean hasVideo() {
119+
return hasVideo;
120+
}
121+
122+
/**
123+
* Whether the archive has an audio track (<code>true</code>) or not (<code>false</code>).
124+
*/
125+
public boolean hasAudio() {
126+
return hasAudio;
127+
}
128+
129+
/**
130+
* The output mode of the archive.
131+
*/
132+
public OutputMode outputMode() {
133+
return outputMode;
134+
}
135+
136+
/**
137+
* Returns the archive properties as a Map.
138+
*/
139+
public Map<String, Collection<String>> toMap() {
140+
Map<String, Collection<String>> params = new HashMap<String, Collection<String>>();
141+
if (null != name) {
142+
ArrayList<String> valueList = new ArrayList<String>();
143+
valueList.add(name);
144+
params.put("name", valueList);
145+
}
146+
ArrayList<String> valueList = new ArrayList<String>();
147+
valueList.add(Boolean.toString(hasAudio));
148+
params.put("hasAudio", valueList);
149+
150+
valueList = new ArrayList<String>();
151+
valueList.add(Boolean.toString(hasVideo));
152+
params.put("hasVideo", valueList);
153+
154+
valueList = new ArrayList<String>();
155+
valueList.add(outputMode.toString());
156+
params.put("outputMode", valueList);
157+
158+
return params;
159+
}
160+
161+
};

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
369369
}
370370
}
371371

372-
public Archive startArchive(String sessionId, String name) throws OpenTokException {
373-
return startArchive(sessionId, name, true, true);
372+
public Archive startArchive(String sessionId) throws OpenTokException {
373+
return startArchive(sessionId, new ArchiveProperties.Builder().build());
374374
}
375375

376376
/**
@@ -385,17 +385,16 @@ public Archive startArchive(String sessionId, String name) throws OpenTokExcepti
385385
* set to routed); you cannot archive sessions with the media mode set to relayed.
386386
*
387387
* @param sessionId The session ID of the OpenTok session to archive.
388-
* @param name The name of the archive. You can use this name to identify the archive. It is a property
389-
* of the Archive object, and it is a property of archive-related events in the OpenTok JavaScript SDK.
388+
* @param properties This ArchiveProperties object defines options for the archive.
390389
*
391390
* @return The Archive object. This object includes properties defining the archive, including the archive ID.
392391
*/
393-
public Archive startArchive(String sessionId, String name, boolean hasVideo, boolean hasAudio) throws OpenTokException {
392+
public Archive startArchive(String sessionId, ArchiveProperties properties) throws OpenTokException {
394393
if (sessionId == null || sessionId == "") {
395394
throw new InvalidArgumentException("Session not valid");
396395
}
397396
// TODO: do validation on sessionId and name
398-
String archive = this.client.startArchive(sessionId, name, hasVideo, hasAudio);
397+
String archive = this.client.startArchive(sessionId, properties);
399398
try {
400399
return archiveReader.readValue(archive);
401400
} catch (Exception e) {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.ning.http.client.filter.FilterContext;
2222
import com.ning.http.client.filter.FilterException;
2323
import com.ning.http.client.filter.RequestFilter;
24-
24+
import com.opentok.ArchiveProperties;
2525
import com.opentok.constants.Version;
2626
import com.opentok.exception.OpenTokException;
2727
import com.opentok.exception.RequestException;
@@ -162,7 +162,7 @@ public String getArchives(int offset, int count) throws RequestException {
162162
return responseString;
163163
}
164164

165-
public String startArchive(String sessionId, String name, boolean hasVideo, boolean hasAudio)
165+
public String startArchive(String sessionId, ArchiveProperties properties)
166166
throws OpenTokException {
167167
String responseString = null;
168168
Future<Response> request = null;
@@ -173,11 +173,12 @@ public String startArchive(String sessionId, String name, boolean hasVideo, bool
173173
JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
174174
ObjectNode requestJson = nodeFactory.objectNode();
175175
requestJson.put("sessionId", sessionId);
176-
requestJson.put("hasVideo", hasVideo);
177-
requestJson.put("hasAudio", hasAudio);
176+
requestJson.put("hasVideo", properties.hasVideo());
177+
requestJson.put("hasAudio", properties.hasAudio());
178+
requestJson.put("outputMode", properties.outputMode().toString());
178179

179-
if (name != null) {
180-
requestJson.put("name", name);
180+
if (properties.name() != null) {
181+
requestJson.put("name", properties.name());
181182
}
182183
try {
183184
requestBody = new ObjectMapper().writeValueAsString(requestJson);

0 commit comments

Comments
 (0)