Skip to content

Commit c9c29fa

Browse files
committed
Merge pull request #69 from jcague/feature/archiving_outputmode
Added support to outputMode
2 parents 8682230 + 56c7123 commit c9c29fa

File tree

10 files changed

+384
-20
lines changed

10 files changed

+384
-20
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ jdk:
77
notifications:
88
slack:
99
secure: fGRoClN1IQiZvokEiqmKOrF7EeaNQDHDHqUMaT4n7d3qW2fMe3N8ZLxlIDlzgJ2pv09VWqK7rmPgdhJR8yVG7OE4QQ5kzR59xD8ePN0j0jf6W6eOBPq3a9UUarnny21LFsShvRMZ/BaXcvTox1zMVltpMGFw2K4ijH8+ZvdkNz8=
10+
before_script:
11+
- echo $JAVA_OPTS
12+
- export JAVA_OPTS="$JAVA_OPTS -Xmx1024m"

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,7 @@ uploadArchives {
119119
}
120120
}
121121
}
122+
123+
test {
124+
maxHeapSize = "1024m"
125+
}

sample/Archiving/public/js/host.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,33 @@ session.on('archiveStarted', function(event) {
1818
console.log("ARCHIVE STARTED");
1919
$(".start").hide();
2020
$(".stop").show();
21+
disableForm();
2122
});
2223

2324
session.on('archiveStopped', function(event) {
2425
archiveID = null;
2526
console.log("ARCHIVE STOPPED");
2627
$(".start").show();
2728
$(".stop").hide();
29+
enableForm();
2830
});
2931

3032
$(document).ready(function() {
31-
$(".start").click(function(event){
32-
$.get("start");
33+
$(".start").click(function (event) {
34+
var options = $(".archive-options").serialize();
35+
disableForm();
36+
$.post("/start", options).fail(enableForm);
3337
}).show();
3438
$(".stop").click(function(event){
3539
$.get("stop/" + archiveID);
3640
}).hide();
37-
});
41+
});
42+
43+
44+
function disableForm() {
45+
$(".archive-options-fields").attr('disabled', 'disabled');
46+
}
47+
48+
function enableForm() {
49+
$(".archive-options-fields").removeAttr('disabled');
50+
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import static spark.Spark.*;
44

55
import com.opentok.*;
6+
import com.opentok.Archive.OutputMode;
7+
68
import spark.*;
79

810
import java.util.Map;
911
import java.util.HashMap;
1012
import java.util.List;
1113

14+
import javax.servlet.http.HttpServletRequest;
15+
1216
import com.opentok.exception.OpenTokException;
1317

1418
public class ArchivingServer {
@@ -137,13 +141,25 @@ public Object handle(Request request, Response response) {
137141
}
138142
});
139143

140-
get(new Route("/start") {
144+
post(new Route("/start") {
141145
@Override
142146
public Object handle(Request request, Response response) {
143147

144148
Archive archive = null;
149+
HttpServletRequest req = request.raw();
150+
boolean hasAudio = req.getParameterMap().containsKey("hasAudio");
151+
boolean hasVideo = req.getParameterMap().containsKey("hasVideo");
152+
OutputMode outputMode = OutputMode.COMPOSED;
153+
if (req.getParameter("outputMode").equals("individual")) {
154+
outputMode = OutputMode.INDIVIDUAL;
155+
}
145156
try {
146-
archive = opentok.startArchive(sessionId, "Java Archiving Sample App");
157+
ArchiveProperties properties = new ArchiveProperties.Builder()
158+
.name("Java Archiving Sample App")
159+
.hasAudio(hasAudio)
160+
.hasVideo(hasVideo)
161+
.outputMode(outputMode).build();
162+
archive = opentok.startArchive(sessionId, properties);
147163
} catch (OpenTokException e) {
148164
e.printStackTrace();
149165
return null;

sample/Archiving/src/main/resources/com/example/freemarker/host.ftl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
<div id="subscribers"><div id="publisher"></div></div>
1515
</div>
1616
<div class="panel-footer">
17+
<form class="archive-options">
18+
<fieldset class="archive-options-fields">
19+
<div class="form-group">
20+
<p class="help-block">Archive Options:</p>
21+
<label class="checkbox-inline">
22+
<input type="checkbox" name="hasAudio" checked> Audio
23+
</label>
24+
<label class="checkbox-inline">
25+
<input type="checkbox" name="hasVideo" checked> Video
26+
</label>
27+
</div>
28+
29+
<div class="form-group">
30+
<p class="help-block">Output Mode:</p>
31+
<label class="radio-inline">
32+
<input type="radio" name="outputMode" value="composed" checked> Composed
33+
</label>
34+
<label class="radio-inline">
35+
<input type="radio" name="outputMode" value="individual"> Individual
36+
</label>
37+
</div>
38+
</fieldset>
39+
</form>
1740
<button class="btn btn-danger start">Start archiving</button>
1841
<button class="btn btn-success stop">Stop archiving</button>
1942
</div>

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,13 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
369369
}
370370
}
371371

372+
public Archive startArchive(String sessionId) throws OpenTokException {
373+
return startArchive(sessionId, new ArchiveProperties.Builder().build());
374+
}
375+
372376
public Archive startArchive(String sessionId, String name) throws OpenTokException {
373-
return startArchive(sessionId, name, true, true);
377+
ArchiveProperties properties = new ArchiveProperties.Builder().name(name).build();
378+
return startArchive(sessionId, properties);
374379
}
375380

376381
/**
@@ -385,17 +390,16 @@ public Archive startArchive(String sessionId, String name) throws OpenTokExcepti
385390
* set to routed); you cannot archive sessions with the media mode set to relayed.
386391
*
387392
* @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.
393+
* @param properties This ArchiveProperties object defines options for the archive.
390394
*
391395
* @return The Archive object. This object includes properties defining the archive, including the archive ID.
392396
*/
393-
public Archive startArchive(String sessionId, String name, boolean hasVideo, boolean hasAudio) throws OpenTokException {
397+
public Archive startArchive(String sessionId, ArchiveProperties properties) throws OpenTokException {
394398
if (sessionId == null || sessionId == "") {
395399
throw new InvalidArgumentException("Session not valid");
396400
}
397401
// TODO: do validation on sessionId and name
398-
String archive = this.client.startArchive(sessionId, name, hasVideo, hasAudio);
402+
String archive = this.client.startArchive(sessionId, properties);
399403
try {
400404
return archiveReader.readValue(archive);
401405
} catch (Exception e) {

0 commit comments

Comments
 (0)