Skip to content

Commit 1460f93

Browse files
authored
Merge pull request #201 from opentok/screenshareType
adding screenshare types and tests
2 parents 387d4c6 + 2921d6e commit 1460f93

File tree

5 files changed

+296
-29
lines changed

5 files changed

+296
-29
lines changed

src/main/java/com/opentok/ArchiveLayout.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public class ArchiveLayout {
1919
private Type type;
2020
private String stylesheet;
21+
private ScreenShareLayoutType screenshareType;
2122

2223
/**
2324
* Do not call the <code>ArchiveLayout()</code> constructor. To set the layout of an
@@ -36,6 +37,16 @@ public ArchiveLayout(Type type) {
3637
this.type = type;
3738
}
3839

40+
/**
41+
* Do not call the <code>ArchiveLayout()</code> constructor. To set the layout of an
42+
* archive, call the {@link OpenTok#setArchiveLayout(String archiveId, ArchiveProperties properties)} method. See
43+
*/
44+
public ArchiveLayout(ScreenShareLayoutType screenShareType){
45+
this.screenshareType = screenShareType;
46+
this.type = Type.BESTFIT;
47+
this.stylesheet = null;
48+
}
49+
3950
/**
4051
* Enumerates <code>type</code> values for the layout.
4152
*/
@@ -101,4 +112,13 @@ public void setStylesheet(String stylesheet) {
101112
this.stylesheet = stylesheet;
102113
}
103114

115+
116+
public ScreenShareLayoutType getScreenshareType() {
117+
return screenshareType;
118+
}
119+
120+
public void setScreenshareType(ScreenShareLayoutType screenshareType) {
121+
this.screenshareType = screenshareType;
122+
}
123+
104124
}

src/main/java/com/opentok/BroadcastLayout.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public BroadcastLayout(Type type, String stylesheet) {
2727
public BroadcastLayout(Type type) {
2828
super(type);
2929
}
30+
31+
/**
32+
* Do not call the <code>BroadcastLayout()</code> constructor. To set the layout of
33+
* a live streaming broadcast, call the {@link OpenTok#setBroadcastLayout(String broadcastId, BroadcastProperties properties)} method.
34+
*/
35+
public BroadcastLayout(ScreenShareLayoutType screenshareType) { super(screenshareType); }
3036
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* OpenTok Java SDK
3+
* Copyright (C) 2021 Vonage.
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.fasterxml.jackson.annotation.JsonValue;
11+
12+
/**
13+
* Enumerates <code>type</code> values for the layout.
14+
*/
15+
public enum ScreenShareLayoutType {
16+
17+
/**
18+
* Represents the picture-in-picture (pip) layout type.
19+
*/
20+
PIP("pip"),
21+
/**
22+
* Represents the picture-in-picture (pip) layout type.
23+
*/
24+
BESTFIT("bestFit"),
25+
/**
26+
* Represents the vertical presentation layout type.
27+
*/
28+
VERTICAL("verticalPresentation"),
29+
/**
30+
* Represents the horizontal presentation layout type.
31+
*/
32+
HORIZONTAL("horizontalPresentation");
33+
34+
private String serialized;
35+
36+
private ScreenShareLayoutType(String s) {
37+
serialized = s;
38+
}
39+
40+
@JsonValue
41+
public String toString() {
42+
return serialized;
43+
}
44+
45+
}

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
import com.opentok.exception.OpenTokException;
2222
import com.opentok.exception.RequestException;
2323
import org.apache.commons.lang.StringUtils;
24-
import org.asynchttpclient.AsyncHttpClientConfig;
25-
import org.asynchttpclient.DefaultAsyncHttpClient;
26-
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
27-
import org.asynchttpclient.Realm;
24+
import org.asynchttpclient.*;
2825
import org.asynchttpclient.Realm.AuthScheme;
29-
import org.asynchttpclient.RequestBuilder;
30-
import org.asynchttpclient.Response;
3126
import org.asynchttpclient.filter.FilterContext;
3227
import org.asynchttpclient.filter.FilterException;
3328
import org.asynchttpclient.filter.RequestFilter;
@@ -223,7 +218,15 @@ public String startArchive(String sessionId, ArchiveProperties properties)
223218
if(properties.layout() != null) {
224219
ObjectNode layout = requestJson.putObject("layout");
225220
layout.put("type", properties.layout().getType().toString());
226-
layout.put("stylesheet", properties.layout().getStylesheet());
221+
if(properties.layout().getScreenshareType() != null){
222+
if (properties.layout().getType() != ArchiveLayout.Type.BESTFIT){
223+
throw new InvalidArgumentException("Could not start Archive. When screenshareType is set in the layout, type must be bestFit");
224+
}
225+
layout.put("screenshareType", properties.layout().getScreenshareType().toString());
226+
}
227+
if(!(properties.layout().getStylesheet() == null)){
228+
layout.put("stylesheet", properties.layout().getStylesheet());
229+
}
227230
}
228231
if (properties.name() != null) {
229232
requestJson.put("name", properties.name());
@@ -340,13 +343,20 @@ public String setArchiveLayout(String archiveId, ArchiveProperties properties) t
340343
}
341344
String type = properties.layout().getType().toString();
342345
String stylesheet = properties.layout().getStylesheet();
346+
String screenshareType = null;
343347
if(StringUtils.isEmpty(type)) {
344348
throw new RequestException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
345349
}
346350
if ((type.equals(ArchiveLayout.Type.CUSTOM.toString()) && StringUtils.isEmpty(stylesheet)) ||
347351
(!type.equals(ArchiveLayout.Type.CUSTOM.toString()) && !StringUtils.isEmpty(stylesheet))) {
348352
throw new RequestException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
349353
}
354+
if(properties.layout().getScreenshareType() != null){
355+
if (properties.layout().getType() != ArchiveLayout.Type.BESTFIT){
356+
throw new InvalidArgumentException("Could not set the Archive layout. When screenshareType is set, type must be bestFit");
357+
}
358+
screenshareType = properties.layout().getScreenshareType().toString();
359+
}
350360
String responseString = null;
351361
String requestBody = null;
352362
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/archive/" + archiveId + "/layout";
@@ -356,6 +366,9 @@ public String setArchiveLayout(String archiveId, ArchiveProperties properties) t
356366
if(type.equals(ArchiveLayout.Type.CUSTOM.toString())) {
357367
requestJson.put("stylesheet", properties.layout().getStylesheet());
358368
}
369+
if(screenshareType!=null){
370+
requestJson.put("screenshareType",screenshareType);
371+
}
359372

360373
try {
361374
requestBody = new ObjectMapper().writeValueAsString(requestJson);
@@ -451,6 +464,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties)
451464
throws OpenTokException {
452465
String responseString = null;
453466
String requestBody = null;
467+
ScreenShareLayoutType screenshareType = null;
454468

455469
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast";
456470

@@ -459,8 +473,15 @@ public String startBroadcast(String sessionId, BroadcastProperties properties)
459473
requestJson.put("sessionId", sessionId);
460474
if(properties.layout() != null) {
461475
ObjectNode layout = requestJson.putObject("layout");
476+
screenshareType = properties.layout().getScreenshareType();
462477
String type = properties.layout().getType().toString();
463478
layout.put("type", type);
479+
if (screenshareType != null && !type.equals(ArchiveLayout.Type.BESTFIT.toString())){
480+
throw new InvalidArgumentException("Could not start OpenTok Broadcast, Layout Type must be bestfit when screenshareType is set.");
481+
}
482+
if(screenshareType!=null){
483+
layout.put("screenshareType", screenshareType.toString());
484+
}
464485
if(type.equals(BroadcastLayout.Type.CUSTOM.toString())) {
465486
layout.put("stylesheet", properties.layout().getStylesheet());
466487
}
@@ -591,13 +612,20 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
591612
}
592613
String type = properties.layout().getType().toString();
593614
String stylesheet = properties.layout().getStylesheet();
615+
String screenshareLayout = null;
594616
if(StringUtils.isEmpty(type)) {
595617
throw new RequestException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
596618
}
597619
if ((type.equals(BroadcastLayout.Type.CUSTOM.toString()) && StringUtils.isEmpty(stylesheet)) ||
598620
(!type.equals(BroadcastLayout.Type.CUSTOM.toString()) && !StringUtils.isEmpty(stylesheet))) {
599621
throw new RequestException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
600622
}
623+
if(properties.layout().getScreenshareType()!=null){
624+
if(properties.layout().getType()!= ArchiveLayout.Type.BESTFIT){
625+
throw new InvalidArgumentException("Could not set layout. Type must be bestfit when screenshareLayout is set.");
626+
}
627+
screenshareLayout = properties.layout().getScreenshareType().toString();
628+
}
601629
String responseString = null;
602630
String requestBody = null;
603631
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast/" + broadcastId + "/layout";
@@ -607,6 +635,10 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
607635
if(type.equals(BroadcastLayout.Type.CUSTOM.toString())) {
608636
requestJson.put("stylesheet", properties.layout().getStylesheet());
609637
}
638+
if(screenshareLayout!=null){
639+
requestJson.put("screenshareType", screenshareLayout);
640+
}
641+
610642

611643
try {
612644
requestBody = new ObjectMapper().writeValueAsString(requestJson);

0 commit comments

Comments
 (0)