Skip to content

Commit 8682230

Browse files
committed
adds hasVideo and hasAudio properties to Archive
introduces an overloaded signature for OpenTok.startArchive() testing is just as incomplete as all other archive testing 😝
1 parent 9419f96 commit 8682230

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
*/
88
package com.opentok;
99

10-
import com.fasterxml.jackson.annotation.JsonCreator;
11-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
12-
import com.fasterxml.jackson.annotation.JsonProperty;
13-
import com.fasterxml.jackson.annotation.JsonValue;
10+
import com.fasterxml.jackson.annotation.*;
1411
import com.fasterxml.jackson.databind.ObjectMapper;
1512

1613
/**
@@ -70,6 +67,8 @@ public enum Status {
7067
@JsonProperty private int size = 0;
7168
@JsonProperty private Status status;
7269
@JsonProperty private String url;
70+
@JsonProperty private boolean hasVideo = true;
71+
@JsonProperty private boolean hasAudio = true;
7372

7473
protected Archive() {
7574
}
@@ -156,6 +155,20 @@ public String getUrl() {
156155
return url;
157156
}
158157

158+
/**
159+
* Whether the archive has an video track (<code>true</code>) or not (<code>false</code>).
160+
*/
161+
public boolean hasVideo() {
162+
return hasVideo;
163+
}
164+
165+
/**
166+
* Whether the archive has an audio track (<code>true</code>) or not (<code>false</code>).
167+
*/
168+
public boolean hasAudio() {
169+
return hasAudio;
170+
}
171+
159172
@Override
160173
public String toString() {
161174
try {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
368368
throw new RequestException("Exception mapping json: " + e.getMessage());
369369
}
370370
}
371-
371+
372+
public Archive startArchive(String sessionId, String name) throws OpenTokException {
373+
return startArchive(sessionId, name, true, true);
374+
}
375+
372376
/**
373377
* Starts archiving an OpenTok 2.0 session.
374378
*
@@ -386,12 +390,12 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
386390
*
387391
* @return The Archive object. This object includes properties defining the archive, including the archive ID.
388392
*/
389-
public Archive startArchive(String sessionId, String name) throws OpenTokException {
393+
public Archive startArchive(String sessionId, String name, boolean hasVideo, boolean hasAudio) throws OpenTokException {
390394
if (sessionId == null || sessionId == "") {
391395
throw new InvalidArgumentException("Session not valid");
392396
}
393397
// TODO: do validation on sessionId and name
394-
String archive = this.client.startArchive(sessionId, name);
398+
String archive = this.client.startArchive(sessionId, name, hasVideo, hasAudio);
395399
try {
396400
return archiveReader.readValue(archive);
397401
} catch (Exception e) {

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
import java.io.IOException;
1111
import java.util.Collection;
12-
import java.util.HashMap;
1312
import java.util.Map;
1413
import java.util.concurrent.ExecutionException;
1514
import java.util.concurrent.Future;
1615

1716
import com.fasterxml.jackson.core.JsonProcessingException;
1817
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
19+
import com.fasterxml.jackson.databind.node.ObjectNode;
1920
import com.ning.http.client.*;
2021
import com.ning.http.client.filter.FilterContext;
2122
import com.ning.http.client.filter.FilterException;
@@ -161,21 +162,25 @@ public String getArchives(int offset, int count) throws RequestException {
161162
return responseString;
162163
}
163164

164-
public String startArchive(String sessionId, String name) throws OpenTokException, RequestException {
165+
public String startArchive(String sessionId, String name, boolean hasVideo, boolean hasAudio)
166+
throws OpenTokException {
165167
String responseString = null;
166168
Future<Response> request = null;
167169
String requestBody = null;
168170
// TODO: maybe use a StringBuilder?
169171
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive";
170172

171-
ObjectMapper mapper = new ObjectMapper();
172-
HashMap<String, String> jsonBody = new HashMap<String, String>();
173-
jsonBody.put("sessionId", sessionId);
173+
JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
174+
ObjectNode requestJson = nodeFactory.objectNode();
175+
requestJson.put("sessionId", sessionId);
176+
requestJson.put("hasVideo", hasVideo);
177+
requestJson.put("hasAudio", hasAudio);
178+
174179
if (name != null) {
175-
jsonBody.put("name", name);
180+
requestJson.put("name", name);
176181
}
177182
try {
178-
requestBody = mapper.writeValueAsString(jsonBody);
183+
requestBody = new ObjectMapper().writeValueAsString(requestJson);
179184
} catch (JsonProcessingException e) {
180185
throw new OpenTokException("Could not start an OpenTok Archive. The JSON body encoding failed.", e);
181186
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,41 @@ public void testStartArchive() throws OpenTokException {
504504
.withHeader("User-Agent", matching(".*Opentok-Java-SDK/"+ Version.VERSION+".*")));
505505
}
506506

507+
@Test
508+
public void testStartVoiceOnlyArchive() throws OpenTokException {
509+
String sessionId = "SESSIONID";
510+
511+
stubFor(post(urlEqualTo("/v2/partner/"+this.apiKey+"/archive"))
512+
.willReturn(aResponse()
513+
.withStatus(200)
514+
.withHeader("Content-Type", "application/json")
515+
.withBody("{\n" +
516+
" \"createdAt\" : 1395183243556,\n" +
517+
" \"duration\" : 0,\n" +
518+
" \"id\" : \"30b3ebf1-ba36-4f5b-8def-6f70d9986fe9\",\n" +
519+
" \"name\" : \"\",\n" +
520+
" \"partnerId\" : 123456,\n" +
521+
" \"reason\" : \"\",\n" +
522+
" \"sessionId\" : \"SESSIONID\",\n" +
523+
" \"size\" : 0,\n" +
524+
" \"status\" : \"started\",\n" +
525+
" \"url\" : null,\n" +
526+
" \"hasVideo\" : false,\n" +
527+
" \"hasAudio\" : true\n" +
528+
" }")));
529+
530+
Archive archive = sdk.startArchive(sessionId, null, false, true);
531+
assertNotNull(archive);
532+
assertEquals(sessionId, archive.getSessionId());
533+
assertNotNull(archive.getId());
534+
535+
verify(postRequestedFor(urlMatching("/v2/partner/"+this.apiKey+"/archive"))
536+
// TODO: find a way to match JSON without caring about spacing
537+
//.withRequestBody(matching(".*"+".*"))
538+
.withHeader("X-TB-PARTNER-AUTH", matching(this.apiKey+":"+this.apiSecret))
539+
.withHeader("User-Agent", matching(".*Opentok-Java-SDK/"+ Version.VERSION+".*")));
540+
}
541+
507542
// TODO: test start archive with name
508543

509544
// TODO: test start archive failure scenarios

0 commit comments

Comments
 (0)