@@ -55,8 +55,8 @@ public class OpenTok {
55
55
/**
56
56
* Creates an OpenTokSDK object.
57
57
*
58
- * @param apiKey Your OpenTok API key. (See the <a href="https://dashboard.tokbox.com">OpenTok dashboard</a>
59
- * page)
58
+ * @param apiKey Your OpenTok API key. (See the <a href="https://dashboard.tokbox.com">OpenTok
59
+ * dashboard</a> page. )
60
60
* @param apiSecret Your OpenTok API secret. (See the <a href="https://dashboard.tokbox.com">OpenTok dashboard</a>
61
61
* page)
62
62
*/
@@ -73,33 +73,15 @@ public OpenTok(int apiKey, String apiSecret, String apiUrl) {
73
73
}
74
74
75
75
/**
76
- * Creates a token for connecting to an OpenTok session. In order to authenticate a user connecting to an OpenTok session
77
- * that user must pass an authentication token along with the API key.
78
- * The following Java code example shows how to obtain a token:
79
- * <p>
80
- * <pre>
81
- * import com.opentok.api.OpenTokSDK;
82
- *
83
- * class Test {
84
- * public static void main(String argv[]) throws OpenTokException {
85
- * int API_KEY = 0; // Replace with your OpenTok API key (see http://dashboard.tokbox.com).
86
- * String API_SECRET = ""; // Replace with your OpenTok API secret.
87
- * OpenTokSDK sdk = new OpenTokSDK(API_KEY, API_SECRET);
88
- *
89
- * //Generate a basic session. Or you could use an existing session ID.
90
- * String sessionId = System.out.println(sdk.createSession());
91
- *
92
- * String token = sdk.generateToken(sessionId);
93
- * System.out.println(token);
94
- * }
95
- * }
96
- * </pre>
76
+ * Creates a token for connecting to an OpenTok session. In order to authenticate a user
77
+ * connecting to an OpenTok session, the client passes a token when connecting to the session.
97
78
* <p>
98
- * The following Java code example shows how to obtain a token that has a role of "subscriber" and that has
99
- * a connection metadata string:
79
+ * The following example shows how to obtain a token that has a role of "subscriber" and
80
+ * that has a connection metadata string:
100
81
* <p>
101
82
* <pre>
102
83
* import com.opentok.Role;
84
+ * import com.opentok.TokenOptions;
103
85
*
104
86
* class Test {
105
87
* public static void main(String argv[]) throws OpenTokException {
@@ -116,37 +98,27 @@ public OpenTok(int apiKey, String apiSecret, String apiUrl) {
116
98
* // Use the Role value appropriate for the user.
117
99
* String role = Role.SUBSCRIBER;
118
100
*
119
- * // Generate a token.
120
- * String token = sdk.generateToken(sessionId, Role.PUBLISHER, null, connectionMetadata);
101
+ * // Generate a token:
102
+ * TokenOptions options = new TokenOptions.Buider().role(role).data(connectionMetadata).build();
103
+ * String token = sdk.generateToken(sessionId, options);
121
104
* System.out.println(token);
122
105
* }
123
106
* }
124
107
* </pre>
125
108
* <p>
126
- * For testing, you can also use the <a href="https://dashboard.tokbox.com/projects">OpenTok dashboard</a>
127
- * page to generate test tokens.
109
+ * For testing, you can also use the <a href="https://dashboard.tokbox.com/projects">OpenTok
110
+ * dashboard</a> page to generate test tokens.
128
111
*
129
112
* @param sessionId The session ID corresponding to the session to which the user will connect.
130
113
*
131
- * @param role Each role defines a set of permissions granted to the token.
132
- * Valid values are defined in the Role class:
133
- *
134
- * * `SUBSCRIBER` — A subscriber can only subscribe to streams.</li>
135
- *
136
- * * `PUBLISHER` — A publisher can publish streams, subscribe to streams, and signal.
137
- * (This is the default value if you do not specify a value for the `role` parameter.)</li>
138
- *
139
- * * `MODERATOR` — In addition to the privileges granted to a publisher, a moderator
140
- * can call the `forceUnpublish()` and `forceDisconnect()` method of the
141
- * Session object.</li>
142
- *
143
- * @param expireTime The expiration time, in seconds, since the UNIX epoch. Pass in 0 to use
144
- * the default expiration time of 24 hours after the token creation time. The maximum expiration
145
- * time is 30 days after the creation time.
114
+ * @param tokenOptions This TokenOptions object defines options for the token.
115
+ * These include the following:
146
116
*
147
- * @param connectionData A string containing metadata describing the end-user. For example, you can pass the
148
- * user ID, name, or other data describing the end-user. The length of the string is limited to 1000 characters.
149
- * This data cannot be updated once it is set.
117
+ * <ul>
118
+ * <li>The role of the token (subscriber, publisher, or moderator)</li>
119
+ * <li>The expiration time of the token</li>
120
+ * <li>Connection data describing the end-user</li>
121
+ * </ul>
150
122
*
151
123
* @return The token string.
152
124
*/
@@ -170,49 +142,68 @@ public String generateToken(String sessionId, TokenOptions tokenOptions) throws
170
142
return session .generateToken (tokenOptions );
171
143
}
172
144
173
- public String generateToken (String sessionId ) throws OpenTokException {
174
- return generateToken (sessionId , new TokenOptions .Builder ().build ());
175
- }
176
-
177
145
/**
178
- * Creates a new OpenTok session and returns the session ID, which uniquely identifies the session.
179
- * <p>
180
- * For example, when using the OpenTok JavaScript library,
181
- * use the session ID in JavaScript on the page that you serve to the client. The JavaScript will use this
182
- * value when calling the <a href="http://tokbox.com/opentok/libraries/client/js/reference/Session.html#connect">connect()</a>
183
- * method of the Session object (to connect a user to an OpenTok session).
184
- * <p>
185
- * OpenTok sessions do not expire. However, authentication tokens do expire (see the
186
- * {@link #generateToken(String, String, long, String)} method).
187
- * Also note that sessions cannot explicitly be destroyed.
188
- * <p>
189
- * A session ID string can be up to 255 characters long.
146
+ * Creates a token for connecting to an OpenTok session, using the default settings. The default
147
+ * settings are the following:
148
+ *
149
+ * <ul>
150
+ * <li>The token is assigned the role of publisher.</li>
151
+ * <li>The token expires 24 hours after it is created.</li>
152
+ * <li>The token includes no connection data.</li>
153
+ * </ul>
154
+ *
190
155
* <p>
191
- * Calling this method results in an {@link com.opentok.exception.OpenTokException} in the event of an error. Check
192
- * the error message for details.
156
+ * The following example shows how to generate a token that has the default settings:
193
157
* <p>
194
- * The following code creates a session that uses the OpenTok Media Router:
195
- *
196
158
* <pre>
197
- * import com.opentok.api.OpenTokSDK;
198
- * import com.opentok.SessionProperties;
159
+ * import com.opentok.OpenTokSDK;
199
160
*
200
161
* class Test {
201
162
* public static void main(String argv[]) throws OpenTokException {
202
- * int API_KEY = 0; // Replace with your OpenTok API key.
163
+ * int API_KEY = 0; // Replace with your OpenTok API key (see http://dashboard.tokbox.com) .
203
164
* String API_SECRET = ""; // Replace with your OpenTok API secret.
204
165
* OpenTokSDK sdk = new OpenTokSDK(API_KEY, API_SECRET);
205
166
*
206
- * String sessionId = sdk.createSession();
207
- * System.out.println(sessionId);
167
+ * //Generate a basic session. Or you could use an existing session ID.
168
+ * String sessionId = System.out.println(sdk.createSession().getSessionId());
169
+ *
170
+ * String token = sdk.generateToken(sessionId);
171
+ * System.out.println(token);
208
172
* }
209
173
* }
210
174
* </pre>
175
+ * @param sessionId The session ID corresponding to the session to which the user will connect.
176
+ *
177
+ * @return The token string.
211
178
*
179
+ * @see #generateToken(String, TokenOptions)
180
+ */
181
+ public String generateToken (String sessionId ) throws OpenTokException {
182
+ return generateToken (sessionId , new TokenOptions .Builder ().build ());
183
+ }
184
+
185
+ /**
186
+ * Creates a new OpenTok session and returns the session ID, which uniquely identifies
187
+ * the session.
188
+ * <p>
189
+ * For example, when using the OpenTok JavaScript library, use the session ID when calling the
190
+ * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
191
+ * OT.initSession()</a> method (to initialize an OpenTok session).
192
+ * <p>
193
+ * OpenTok sessions do not expire. However, authentication tokens do expire (see the
194
+ * {@link #generateToken(String, TokenOptions)} method). Also note that sessions cannot
195
+ * explicitly be destroyed.
196
+ * <p>
197
+ * A session ID string can be up to 255 characters long.
198
+ * <p>
199
+ * Calling this method results in an {@link com.opentok.exception.OpenTokException} in
200
+ * the event of an error. Check the error message for details.
201
+ * <p>
212
202
* The following code creates a peer-to-peer session:
213
203
*
214
204
* <pre>
215
- * import com.opentok.api.OpenTokSDK;
205
+ * import com.opentok.OpenTokSDK;
206
+ * import com.opentok.Session;
216
207
* import com.opentok.SessionProperties;
217
208
*
218
209
* class Test {
@@ -221,41 +212,25 @@ public String generateToken(String sessionId) throws OpenTokException {
221
212
* String API_SECRET = ""; // Replace with your OpenTok API secret.
222
213
* OpenTokSDK sdk = new OpenTokSDK(API_KEY, API_SECRET);
223
214
*
224
- * SessionProperties sp = new SessionProperties();
225
- * sp.p2p_preference = "enabled";
215
+ * SessionProperties sp = new SessionProperties().Builder().p2p(true).build();
226
216
*
227
- * String sessionId = sdk.createSession(null, sp);
228
- * System.out.println(sessionId );
217
+ * Session session = sdk.createSession(sp);
218
+ * System.out.println(session.getSessionId() );
229
219
* }
230
220
* }
231
221
* </pre>
232
222
*
233
223
* You can also create a session using the <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
234
224
* REST API</a> or the <a href="https://dashboard.tokbox.com/projects">OpenTok dashboard</a>.
235
225
*
236
- * @param properties Defines whether the session's streams will be transmitted directly between peers or
237
- * using the OpenTok media server. You can set the following possible values :
238
- * <p>
226
+ * @param properties This SessionProperties object defines options for the session.
227
+ * These include the following:
228
+ *
239
229
* <ul>
240
- * <li>
241
- * "disabled" (the default) — The session's streams will all be relayed using the OpenTok media server.
242
- * <br><br>
243
- * <i>In OpenTok v2:</i> The <a href="http://www.tokbox.com/blog/mantis-next-generation-cloud-technology-for-webrtc/">OpenTok
244
- * media server</a> provides benefits not AVAILABLE in peer-to-peer sessions. For example, the OpenTok media server can
245
- * decrease bandwidth usage in multiparty sessions. Also, the OpenTok server can improve the quality of the user experience
246
- * through <a href="http://www.tokbox.com/blog/quality-of-experience-and-traffic-shaping-the-next-step-with-mantis/">dynamic
247
- * traffic shaping</a>. For information on pricing, see the <a href="http://www.tokbox.com/pricing">OpenTok pricing page</a>.
248
- * <br><br>
249
- * </li>
250
- * <li>
251
- * "enabled" — The session will attempt to transmit streams directly between clients.
252
- * <br><br>
253
- * <i>In OpenTok v1:</i> Peer-to-peer streaming decreases latency and improves quality. If peer-to-peer streaming
254
- * fails (either when streams are initially published or during the course of a session), the session falls back to using
255
- * the OpenTok media server to relaying streams. (Peer-to-peer streaming uses UDP, which may be blocked by a firewall.)
256
- * For a session created with peer-to-peer streaming enabled, only two clients can connect to the session at a time.
257
- * If an additional client attempts to connect, the client dispatches an exception event.
258
- * </li>
230
+ * <li>Whether the session's streams will be transmitted directly between peers or
231
+ * using the OpenTok Media Router.</li>
232
+ *
233
+ * <li>A location hint for the location of the OpenTok server to use for the session.</li>
259
234
* </ul>
260
235
*
261
236
* @return A session ID for the new session. For example, when using the OpenTok JavaScript library, use this session ID
@@ -289,9 +264,32 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
289
264
}
290
265
291
266
/**
292
- * Creates an OpenTok session and returns the session ID, with the default properties. The
293
- * session uses the OpenTok media server. And the session uses the first client connecting
294
- * to determine the location of OpenTok server to use.
267
+ * Creates an OpenTok session with the default settings:
268
+ *
269
+ * <ul>
270
+ * <li>The session uses the OpenTok media server.
271
+ * <li>The session uses the first client connecting to determine the location of the
272
+ * OpenTok server to use.</li>
273
+ * </ul>
274
+ *
275
+ * <p>
276
+ * The following example creates a session that uses the default settings:
277
+ *
278
+ * <pre>
279
+ * import com.opentok.OpenTokSDK;
280
+ * import com.opentok.SessionProperties;
281
+ *
282
+ * class Test {
283
+ * public static void main(String argv[]) throws OpenTokException {
284
+ * int API_KEY = 0; // Replace with your OpenTok API key.
285
+ * String API_SECRET = ""; // Replace with your OpenTok API secret.
286
+ * OpenTokSDK sdk = new OpenTokSDK(API_KEY, API_SECRET);
287
+ *
288
+ * String sessionId = sdk.createSession();
289
+ * System.out.println(sessionId);
290
+ * }
291
+ * }
292
+ * </pre>
295
293
*
296
294
* @see #createSession(SessionProperties)
297
295
*/
0 commit comments