21
21
import com .opentok .exception .OpenTokException ;
22
22
import com .opentok .exception .RequestException ;
23
23
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 .*;
28
25
import org .asynchttpclient .Realm .AuthScheme ;
29
- import org .asynchttpclient .RequestBuilder ;
30
- import org .asynchttpclient .Response ;
31
26
import org .asynchttpclient .filter .FilterContext ;
32
27
import org .asynchttpclient .filter .FilterException ;
33
28
import org .asynchttpclient .filter .RequestFilter ;
@@ -223,7 +218,15 @@ public String startArchive(String sessionId, ArchiveProperties properties)
223
218
if (properties .layout () != null ) {
224
219
ObjectNode layout = requestJson .putObject ("layout" );
225
220
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
+ }
227
230
}
228
231
if (properties .name () != null ) {
229
232
requestJson .put ("name" , properties .name ());
@@ -340,13 +343,20 @@ public String setArchiveLayout(String archiveId, ArchiveProperties properties) t
340
343
}
341
344
String type = properties .layout ().getType ().toString ();
342
345
String stylesheet = properties .layout ().getStylesheet ();
346
+ String screenshareType = null ;
343
347
if (StringUtils .isEmpty (type )) {
344
348
throw new RequestException ("Could not set the layout. Either an invalid JSON or an invalid layout options." );
345
349
}
346
350
if ((type .equals (ArchiveLayout .Type .CUSTOM .toString ()) && StringUtils .isEmpty (stylesheet )) ||
347
351
(!type .equals (ArchiveLayout .Type .CUSTOM .toString ()) && !StringUtils .isEmpty (stylesheet ))) {
348
352
throw new RequestException ("Could not set the layout. Either an invalid JSON or an invalid layout options." );
349
353
}
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
+ }
350
360
String responseString = null ;
351
361
String requestBody = null ;
352
362
String url = this .apiUrl + "/v2/project/" + this .apiKey + "/archive/" + archiveId + "/layout" ;
@@ -356,6 +366,9 @@ public String setArchiveLayout(String archiveId, ArchiveProperties properties) t
356
366
if (type .equals (ArchiveLayout .Type .CUSTOM .toString ())) {
357
367
requestJson .put ("stylesheet" , properties .layout ().getStylesheet ());
358
368
}
369
+ if (screenshareType !=null ){
370
+ requestJson .put ("screenshareType" ,screenshareType );
371
+ }
359
372
360
373
try {
361
374
requestBody = new ObjectMapper ().writeValueAsString (requestJson );
@@ -451,6 +464,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties)
451
464
throws OpenTokException {
452
465
String responseString = null ;
453
466
String requestBody = null ;
467
+ ScreenShareLayoutType screenshareType = null ;
454
468
455
469
String url = this .apiUrl + "/v2/project/" + this .apiKey + "/broadcast" ;
456
470
@@ -459,8 +473,15 @@ public String startBroadcast(String sessionId, BroadcastProperties properties)
459
473
requestJson .put ("sessionId" , sessionId );
460
474
if (properties .layout () != null ) {
461
475
ObjectNode layout = requestJson .putObject ("layout" );
476
+ screenshareType = properties .layout ().getScreenshareType ();
462
477
String type = properties .layout ().getType ().toString ();
463
478
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
+ }
464
485
if (type .equals (BroadcastLayout .Type .CUSTOM .toString ())) {
465
486
layout .put ("stylesheet" , properties .layout ().getStylesheet ());
466
487
}
@@ -591,13 +612,20 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
591
612
}
592
613
String type = properties .layout ().getType ().toString ();
593
614
String stylesheet = properties .layout ().getStylesheet ();
615
+ String screenshareLayout = null ;
594
616
if (StringUtils .isEmpty (type )) {
595
617
throw new RequestException ("Could not set the layout. Either an invalid JSON or an invalid layout options." );
596
618
}
597
619
if ((type .equals (BroadcastLayout .Type .CUSTOM .toString ()) && StringUtils .isEmpty (stylesheet )) ||
598
620
(!type .equals (BroadcastLayout .Type .CUSTOM .toString ()) && !StringUtils .isEmpty (stylesheet ))) {
599
621
throw new RequestException ("Could not set the layout. Either an invalid JSON or an invalid layout options." );
600
622
}
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
+ }
601
629
String responseString = null ;
602
630
String requestBody = null ;
603
631
String url = this .apiUrl + "/v2/project/" + this .apiKey + "/broadcast/" + broadcastId + "/layout" ;
@@ -607,6 +635,10 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
607
635
if (type .equals (BroadcastLayout .Type .CUSTOM .toString ())) {
608
636
requestJson .put ("stylesheet" , properties .layout ().getStylesheet ());
609
637
}
638
+ if (screenshareLayout !=null ){
639
+ requestJson .put ("screenshareType" , screenshareLayout );
640
+ }
641
+
610
642
611
643
try {
612
644
requestBody = new ObjectMapper ().writeValueAsString (requestJson );
0 commit comments