@@ -134,7 +134,7 @@ public String generateToken(String sessionId, TokenOptions tokenOptions) throws
134
134
} catch (UnsupportedEncodingException e ) {
135
135
throw new InvalidArgumentException ("Session ID was not valid" );
136
136
}
137
- if (!sessionIdParts .contains (Integer .toString (this . apiKey ))) {
137
+ if (!sessionIdParts .contains (Integer .toString (apiKey ))) {
138
138
throw new InvalidArgumentException ("Session ID was not valid" );
139
139
}
140
140
@@ -244,7 +244,7 @@ public String generateToken(String sessionId) throws OpenTokException {
244
244
public Session createSession (SessionProperties properties ) throws OpenTokException {
245
245
final SessionProperties _properties = properties != null ? properties : new SessionProperties .Builder ().build ();
246
246
final Map <String , Collection <String >> params = _properties .toMap ();
247
- final String response = this . client .createSession (params );
247
+ final String response = client .createSession (params );
248
248
249
249
try {
250
250
CreatedSession [] sessions = createdSessionReader .readValue (response );
@@ -306,7 +306,7 @@ public void signal(String sessionId, SignalProperties props) throws OpenTokExcep
306
306
throw new InvalidArgumentException ("Session string null or empty" );
307
307
}
308
308
try {
309
- this . client .signal (sessionId ,null ,props );
309
+ client .signal (sessionId ,null ,props );
310
310
311
311
} catch (Exception e )
312
312
{
@@ -321,7 +321,7 @@ public void signal(String sessionId, String connectionId, SignalProperties props
321
321
throw new InvalidArgumentException ("Session or Connection string null or empty" );
322
322
}
323
323
try {
324
- this . client .signal (sessionId , connectionId , props );
324
+ client .signal (sessionId , connectionId , props );
325
325
326
326
} catch (Exception e )
327
327
{
@@ -336,7 +336,7 @@ public void signal(String sessionId, String connectionId, SignalProperties props
336
336
* @return The {@link Archive} object.
337
337
*/
338
338
public Archive getArchive (String archiveId ) throws OpenTokException {
339
- String archive = this . client .getArchive (archiveId );
339
+ String archive = client .getArchive (archiveId );
340
340
try {
341
341
return archiveReader .readValue (archive );
342
342
} catch (Exception e ) {
@@ -401,7 +401,7 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
401
401
* @return A List of {@link Archive} objects.
402
402
*/
403
403
public ArchiveList listArchives (String sessionId , int offset , int count ) throws OpenTokException {
404
- String archives = this . client .getArchives (sessionId , offset , count );
404
+ String archives = client .getArchives (sessionId , offset , count );
405
405
try {
406
406
return archiveListReader .readValue (archives );
407
407
} catch (JsonProcessingException e ) {
@@ -442,7 +442,7 @@ public Archive startArchive(String sessionId, ArchiveProperties properties) thro
442
442
throw new InvalidArgumentException ("The resolution cannot be specified for individual output mode." );
443
443
}
444
444
// TODO: do validation on sessionId and name
445
- String archive = this . client .startArchive (sessionId , properties );
445
+ String archive = client .startArchive (sessionId , properties );
446
446
try {
447
447
return archiveReader .readValue (archive );
448
448
} catch (Exception e ) {
@@ -470,7 +470,7 @@ public Archive startArchive(String sessionId, String name) throws OpenTokExcepti
470
470
*/
471
471
public Archive stopArchive (String archiveId ) throws OpenTokException {
472
472
473
- String archive = this . client .stopArchive (archiveId );
473
+ String archive = client .stopArchive (archiveId );
474
474
try {
475
475
return archiveReader .readValue (archive );
476
476
} catch (Exception e ) {
@@ -488,7 +488,7 @@ public Archive stopArchive(String archiveId) throws OpenTokException {
488
488
* @param archiveId The archive ID of the archive you want to delete.
489
489
*/
490
490
public void deleteArchive (String archiveId ) throws OpenTokException {
491
- this . client .deleteArchive (archiveId );
491
+ client .deleteArchive (archiveId );
492
492
}
493
493
/**
494
494
* Sets the layout type for a composed archive. For a description of layout types, see
@@ -503,7 +503,7 @@ public void setArchiveLayout(String archiveId, ArchiveProperties properties) thr
503
503
if (StringUtils .isEmpty (archiveId ) || properties == null ) {
504
504
throw new InvalidArgumentException ("ArchiveId is not valid or properties are null" );
505
505
}
506
- this . client .setArchiveLayout (archiveId , properties );
506
+ client .setArchiveLayout (archiveId , properties );
507
507
}
508
508
/**
509
509
* Use this method to start a live streaming for an OpenTok session.
@@ -533,7 +533,7 @@ public Broadcast startBroadcast(String sessionId, BroadcastProperties properties
533
533
throw new InvalidArgumentException ("Session not valid or broadcast properties is null" );
534
534
}
535
535
536
- String broadcast = this . client .startBroadcast (sessionId , properties );
536
+ String broadcast = client .startBroadcast (sessionId , properties );
537
537
try {
538
538
return broadcastReader .readValue (
539
539
broadcast );
@@ -557,7 +557,7 @@ public Broadcast stopBroadcast(String broadcastId) throws OpenTokException {
557
557
if (StringUtils .isEmpty (broadcastId )) {
558
558
throw new InvalidArgumentException ("Broadcast id is null or empty" );
559
559
}
560
- String broadcast = this . client .stopBroadcast (broadcastId );
560
+ String broadcast = client .stopBroadcast (broadcastId );
561
561
try {
562
562
return broadcastReader .readValue (broadcast );
563
563
} catch (Exception e ) {
@@ -575,7 +575,7 @@ public Broadcast getBroadcast(String broadcastId) throws OpenTokException {
575
575
if (StringUtils .isEmpty (broadcastId )) {
576
576
throw new InvalidArgumentException ("Broadcast id is null or empty" );
577
577
}
578
- String stream = this . client .getBroadcast (broadcastId );
578
+ String stream = client .getBroadcast (broadcastId );
579
579
try {
580
580
return broadcastReader .readValue (stream );
581
581
} catch (Exception e ) {
@@ -596,7 +596,7 @@ public void setBroadcastLayout(String broadcastId, BroadcastProperties propertie
596
596
if (StringUtils .isEmpty (broadcastId ) || properties == null ) {
597
597
throw new InvalidArgumentException ("BroadcastId is not valid or properties are null" );
598
598
}
599
- this . client .setBroadcastLayout (broadcastId , properties );
599
+ client .setBroadcastLayout (broadcastId , properties );
600
600
}
601
601
/**
602
602
* Sets the layout class list for streams in a session. Layout classes are used in
@@ -619,7 +619,7 @@ public void setStreamLayouts(String sessionId, StreamListProperties properties)
619
619
if (StringUtils .isEmpty (sessionId ) || properties == null ) {
620
620
throw new InvalidArgumentException ("SessionId is not valid or properties are null" );
621
621
}
622
- this . client .setStreamLayouts (sessionId , properties );
622
+ client .setStreamLayouts (sessionId , properties );
623
623
}
624
624
625
625
/**
@@ -635,7 +635,7 @@ public void forceDisconnect(String sessionId, String connectionId) throws OpenTo
635
635
throw new InvalidArgumentException ("Session or Connection string null or empty" );
636
636
}
637
637
try {
638
- this . client .forceDisconnect (sessionId , connectionId );
638
+ client .forceDisconnect (sessionId , connectionId );
639
639
640
640
} catch (Exception e )
641
641
{
@@ -652,7 +652,7 @@ public void forceDisconnect(String sessionId, String connectionId) throws OpenTo
652
652
* @return The {@link Stream} object.
653
653
*/
654
654
public Stream getStream (String sessionId , String streamId ) throws OpenTokException {
655
- String stream = this . client .getStream (sessionId , streamId );
655
+ String stream = client .getStream (sessionId , streamId );
656
656
try {
657
657
return streamReader .readValue (stream );
658
658
} catch (Exception e ) {
@@ -668,7 +668,7 @@ public Stream getStream(String sessionId, String streamId) throws OpenTokExcepti
668
668
* @return The list of {@link Stream} objects.
669
669
*/
670
670
public StreamList listStreams (String sessionId ) throws OpenTokException {
671
- String streams = this . client .listStreams (sessionId );
671
+ String streams = client .listStreams (sessionId );
672
672
try {
673
673
return streamListReader .readValue (streams );
674
674
} catch (JsonProcessingException e ) {
@@ -690,7 +690,7 @@ public Sip dial(String sessionId, String token, SipProperties properties) throws
690
690
if ((StringUtils .isEmpty (sessionId ) || StringUtils .isEmpty (token ) || properties == null || StringUtils .isEmpty (properties .sipUri ()))) {
691
691
throw new InvalidArgumentException ("Session id or token is null or empty or sip properties is null or sip uri empty or null." );
692
692
}
693
- String sip = this . client .sipDial (sessionId ,token ,properties );
693
+ String sip = client .sipDial (sessionId ,token ,properties );
694
694
try {
695
695
return sipReader .readValue (sip );
696
696
} catch (JsonProcessingException e ) {
@@ -707,6 +707,7 @@ public static class Builder {
707
707
private ProxyAuthScheme proxyAuthScheme ;
708
708
private String principal ;
709
709
private String password ;
710
+ private int requestTimeout ;
710
711
711
712
public Builder (int apiKey , String apiSecret ) {
712
713
this .apiKey = apiKey ;
@@ -722,6 +723,11 @@ public Builder proxy(Proxy proxy) {
722
723
proxy (proxy , null , null , null );
723
724
return this ;
724
725
}
726
+
727
+ public Builder requestTimeout (int requestTimeout ) {
728
+ this .requestTimeout = requestTimeout * 1000 ;
729
+ return this ;
730
+ }
725
731
726
732
public Builder proxy (Proxy proxy , ProxyAuthScheme proxyAuthScheme , String principal , String password ) {
727
733
this .proxy = proxy ;
@@ -734,18 +740,21 @@ public Builder proxy(Proxy proxy, ProxyAuthScheme proxyAuthScheme, String princi
734
740
public OpenTok build () {
735
741
HttpClient .Builder clientBuilder = new HttpClient .Builder (apiKey , apiSecret );
736
742
737
- if (this .apiUrl != null ) {
738
- clientBuilder .apiUrl (this .apiUrl );
743
+ if (apiUrl != null ) {
744
+ clientBuilder .apiUrl (apiUrl );
745
+ }
746
+ if (proxy != null ) {
747
+ clientBuilder .proxy (proxy , proxyAuthScheme , principal , password );
739
748
}
740
- if ( this . proxy != null ) {
741
- clientBuilder .proxy ( this . proxy , proxyAuthScheme , principal , password );
749
+ if ( requestTimeout !=0 ) {
750
+ clientBuilder .requestTimeoutMS ( requestTimeout );
742
751
}
743
752
744
- return new OpenTok (this . apiKey , this . apiSecret , clientBuilder .build ());
753
+ return new OpenTok (apiKey , apiSecret , clientBuilder .build ());
745
754
}
746
755
}
747
756
748
757
public void close () {
749
- this . client .close ();
758
+ client .close ();
750
759
}
751
760
}
0 commit comments