Skip to content

Commit 6519dee

Browse files
committed
Docs updates for the advanced options in OpenTok.Builder
1 parent b0d641f commit 6519dee

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,39 @@ String apiSecret = "YOUR API SECRET";
6969
OpenTok opentok = new OpenTok(apiKey, apiSecret)
7070
```
7171

72-
#### Additional Configurations
73-
`.requestTimeout(int)` - Change the default HTTP request timeout, default is 60 seconds.
74-
`.apiUrl(String)` - Change the domain that the SDK points to. Useful when needing to select a specific datacenter or point to a mock version of the API for testing.
75-
`.proxy(Proxy)` - Using a `Proxy` object, you can configure a proxy server that the http client should use when accessing the OpenTok URLs.
72+
#### Advanced configuration options
7673

74+
You can use `OpenTok.Builder` to set advanced options. This class
75+
includes the following methods:
7776

78-
And make sure you call `close` when you are done to prevent leaked file descriptors.
77+
- `.requestTimeout(int)` -- Call this to specify the timeout for HTTP requests
78+
(in seconds). The default timeout is 60 seconds.
79+
80+
- `.proxy(Proxy)` -- Using a `java.net.Proxy` object, you can configure a proxy server
81+
that the HTTP client will use when call the OpenTok REST API.
82+
83+
Call the `OpenTok.Builder()` constructor, passing in your API key and secret,
84+
to instantiate an `OpenTok.Builder` object. Then call the `requestTimeout()`
85+
or `proxy()` methods (or both). Then call the `build()` method to return an
86+
OpenTok object.
87+
88+
For example, the following code instantiates an OpenTok object, with the
89+
default timeout set to 10 seconds:
90+
91+
```java
92+
int apiKey = 12345; // YOUR API KEY
93+
String apiSecret = "YOUR API SECRET";
94+
int timeout = 10;
95+
96+
OpenTok opentok = new OpenTok.Builder(apiKey, apiSecret)
97+
.requestTimeout(timeout)
98+
.build();
99+
```
100+
101+
#### The close() method
102+
103+
Make sure you call the `OpenTok.close()` method when you are done,
104+
to prevent leaked file descriptors:
79105

80106
```java
81107
opentok.close();

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,14 @@ public Sip dial(String sessionId, String token, SipProperties properties) throws
699699
throw new RequestException("Exception mapping json: " + e.getMessage());
700700
}
701701
}
702+
703+
/**
704+
* Used to create an OpenTok object with advanced settings. You can set
705+
* the request timeout for API calls and a proxy to use for API calls.
706+
* <p>
707+
* If you do not need to set these advanced settings, you can use the
708+
* {@link OpenTok OpenTok()} constructor to build the OpenTok object.
709+
*/
702710
public static class Builder {
703711
private int apiKey;
704712
private String apiSecret;
@@ -708,22 +716,42 @@ public static class Builder {
708716
private String principal;
709717
private String password;
710718
private int requestTimeout;
711-
719+
720+
/**
721+
* Constructs a new OpenTok.Builder object.
722+
*
723+
* @param apiKey The API key for your OpenTok project.
724+
*
725+
* @param apiSecret The API secret for your OpenTok project. You can obtain
726+
* your API key and secret from your <a href="https://tokbox.com/account">Video API account</a>.
727+
* Do not publicly share your API secret.
728+
*/
712729
public Builder(int apiKey, String apiSecret) {
713730
this.apiKey = apiKey;
714731
this.apiSecret = apiSecret;
715732
}
716-
733+
734+
/**
735+
* Do not use. This method is used by Vonage for testing.
736+
*/
717737
public Builder apiUrl(String apiUrl) {
718738
this.apiUrl = apiUrl;
719739
return this;
720740
}
721-
741+
742+
/**
743+
* Sets a proxy server that the HTTP client will use when making calls to
744+
* the OpenTok REST API.
745+
*/
722746
public Builder proxy(Proxy proxy) {
723747
proxy(proxy, null, null, null);
724748
return this;
725749
}
726750

751+
/**
752+
* Specify the timeout for HTTP requests (in seconds). The default
753+
* timeout is 60 seconds.
754+
*/
727755
public Builder requestTimeout(int requestTimeout) {
728756
this.requestTimeout = requestTimeout * 1000;
729757
return this;
@@ -736,7 +764,13 @@ public Builder proxy(Proxy proxy, ProxyAuthScheme proxyAuthScheme, String princi
736764
this.password = password;
737765
return this;
738766
}
739-
767+
768+
/**
769+
* Builds the OpenTok object with the settings provided to this
770+
* Builder object.
771+
*
772+
* @return The OpenTok object.
773+
*/
740774
public OpenTok build() {
741775
HttpClient.Builder clientBuilder = new HttpClient.Builder(apiKey, apiSecret);
742776

@@ -754,6 +788,10 @@ public OpenTok build() {
754788
}
755789
}
756790

791+
/**
792+
* Call this method when you are done using the OpenTok object,
793+
* to prevent leaked file descriptors.
794+
*/
757795
public void close() {
758796
client.close();
759797
}

0 commit comments

Comments
 (0)