opentok 2.4.0.beta.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -1
  4. data/README.md +8 -11
  5. data/lib/opentok.rb +1 -1
  6. data/lib/opentok/archive.rb +2 -3
  7. data/lib/opentok/archives.rb +4 -2
  8. data/lib/opentok/client.rb +37 -12
  9. data/lib/opentok/constants.rb +1 -0
  10. data/lib/opentok/opentok.rb +1 -1
  11. data/lib/opentok/session.rb +1 -1
  12. data/lib/opentok/token_generator.rb +0 -9
  13. data/lib/opentok/version.rb +1 -1
  14. data/opentok.gemspec +3 -2
  15. data/sample/Archiving/public/js/host.js +18 -7
  16. data/sample/Archiving/public/js/participant.js +18 -7
  17. data/sample/Archiving/views/host.erb +1 -1
  18. data/sample/Archiving/views/participant.erb +1 -1
  19. data/sample/HelloWorld/public/js/helloworld.js +26 -6
  20. data/sample/HelloWorld/views/index.erb +1 -1
  21. data/spec/cassettes/OpenTok_Archives/should_create_archives.yml +3 -3
  22. data/spec/cassettes/OpenTok_Archives/should_create_audio_only_archives.yml +3 -3
  23. data/spec/cassettes/OpenTok_Archives/should_create_individual_archives.yml +3 -3
  24. data/spec/cassettes/OpenTok_Archives/should_create_named_archives.yml +3 -3
  25. data/spec/cassettes/OpenTok_Archives/should_delete_an_archive_by_id.yml +3 -3
  26. data/spec/cassettes/OpenTok_Archives/should_find_archives_by_id.yml +3 -3
  27. data/spec/cassettes/OpenTok_Archives/should_find_archives_with_unknown_properties.yml +3 -3
  28. data/spec/cassettes/OpenTok_Archives/should_find_expired_archives.yml +3 -3
  29. data/spec/cassettes/OpenTok_Archives/should_find_paused_archives_by_id.yml +3 -3
  30. data/spec/cassettes/OpenTok_Archives/should_stop_archives.yml +3 -3
  31. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_all_archives.yml +3 -3
  32. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_archives_with_an_offset.yml +4 -4
  33. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_count_number_of_archives.yml +4 -4
  34. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_part_of_the_archives_when_using_offset_and_count.yml +4 -4
  35. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_session_archives.yml +71 -0
  36. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml +2 -2
  37. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_default_sessions.yml +2 -2
  38. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions.yml +2 -2
  39. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_for_invalid_media_modes.yml +2 -2
  40. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_with_a_location_hint.yml +2 -2
  41. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions.yml +2 -2
  42. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_with_a_location_hint.yml +2 -2
  43. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_sessions_with_a_location_hint.yml +2 -2
  44. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/with_an_addendum_to_the_user_agent_string/should_append_the_addendum_to_the_user_agent_header.yml +2 -2
  45. data/spec/matchers/token.rb +1 -2
  46. data/spec/opentok/archives_spec.rb +16 -0
  47. data/spec/opentok/opentok_spec.rb +5 -0
  48. data/spec/opentok/session_spec.rb +5 -0
  49. data/spec/shared/opentok_generates_tokens.rb +5 -25
  50. data/spec/shared/session_generates_tokens.rb +5 -0
  51. metadata +49 -84
  52. data/doc/OpenTok.html +0 -418
  53. data/doc/OpenTok/Archive.html +0 -1607
  54. data/doc/OpenTok/ArchiveList.html +0 -216
  55. data/doc/OpenTok/Archives.html +0 -1101
  56. data/doc/OpenTok/Client.html +0 -695
  57. data/doc/OpenTok/HashExtensions.html +0 -184
  58. data/doc/OpenTok/OpenTok.html +0 -1083
  59. data/doc/OpenTok/OpenTokArchiveError.html +0 -142
  60. data/doc/OpenTok/OpenTokAuthenticationError.html +0 -143
  61. data/doc/OpenTok/OpenTokError.html +0 -138
  62. data/doc/OpenTok/Session.html +0 -757
  63. data/doc/OpenTok/TokenGenerator.html +0 -204
  64. data/doc/OpenTok/TokenGenerator/ClassMethods.html +0 -187
  65. data/doc/README.md +0 -15
  66. data/doc/_index.html +0 -197
  67. data/doc/class_list.html +0 -58
  68. data/doc/css/common.css +0 -1
  69. data/doc/css/full_list.css +0 -57
  70. data/doc/css/style.css +0 -339
  71. data/doc/file.README.html +0 -87
  72. data/doc/file_list.html +0 -60
  73. data/doc/frames.html +0 -26
  74. data/doc/index.html +0 -87
  75. data/doc/js/app.js +0 -219
  76. data/doc/js/full_list.js +0 -181
  77. data/doc/js/jquery.js +0 -4
  78. data/doc/method_list.html +0 -261
  79. data/doc/top-level-namespace.html +0 -112
@@ -1,184 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Module: OpenTok::HashExtensions
8
-
9
- &mdash; Documentation by YARD 0.8.7.6
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../';
20
- framesUrl = "../frames.html#!OpenTok/HashExtensions.html";
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../_index.html">Index (H)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../OpenTok.html" title="OpenTok (module)">OpenTok</a></span></span>
36
- &raquo;
37
- <span class="title">HashExtensions</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Module: OpenTok::HashExtensions
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
- <dt class="r1 last">Defined in:</dt>
82
- <dd class="r1 last">lib/extensions/hash.rb</dd>
83
-
84
- </dl>
85
- <div class="clear"></div>
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
- <h2>
96
- Instance Method Summary
97
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
98
- </h2>
99
-
100
- <ul class="summary">
101
-
102
- <li class="public ">
103
- <span class="summary_signature">
104
-
105
- <a href="#camelize_keys%21-instance_method" title="#camelize_keys! (instance method)">- (Object) <strong>camelize_keys!</strong> </a>
106
-
107
-
108
-
109
- </span>
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
- <span class="summary_desc"><div class='inline'></div></span>
120
-
121
- </li>
122
-
123
-
124
- </ul>
125
-
126
-
127
-
128
-
129
- <div id="instance_method_details" class="method_details_list">
130
- <h2>Instance Method Details</h2>
131
-
132
-
133
- <div class="method_details first">
134
- <h3 class="signature first" id="camelize_keys!-instance_method">
135
-
136
- - (<tt>Object</tt>) <strong>camelize_keys!</strong>
137
-
138
-
139
-
140
-
141
-
142
- </h3><table class="source_code">
143
- <tr>
144
- <td>
145
- <pre class="lines">
146
-
147
-
148
- 3
149
- 4
150
- 5
151
- 6
152
- 7
153
- 8
154
- 9
155
- 10</pre>
156
- </td>
157
- <td>
158
- <pre class="code"><span class="info file"># File 'lib/extensions/hash.rb', line 3</span>
159
-
160
- <span class='kw'>def</span> <span class='id identifier rubyid_camelize_keys!'>camelize_keys!</span>
161
- <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='op'>|</span>
162
- <span class='id identifier rubyid_new_key'>new_key</span> <span class='op'>=</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_camelize'>camelize</span><span class='lparen'>(</span><span class='symbol'>:lower</span><span class='rparen'>)</span>
163
- <span class='id identifier rubyid_new_key'>new_key</span> <span class='op'>=</span> <span class='id identifier rubyid_new_key'>new_key</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='kw'>if</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Symbol</span>
164
- <span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_new_key'>new_key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='rparen'>)</span>
165
- <span class='kw'>end</span>
166
- <span class='kw'>self</span>
167
- <span class='kw'>end</span></pre>
168
- </td>
169
- </tr>
170
- </table>
171
- </div>
172
-
173
- </div>
174
-
175
- </div>
176
-
177
- <div id="footer">
178
- Generated on Mon May 25 15:52:46 2015 by
179
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
180
- 0.8.7.6 (ruby-1.9.3).
181
- </div>
182
-
183
- </body>
184
- </html>
@@ -1,1083 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Class: OpenTok::OpenTok
8
-
9
- &mdash; Documentation by YARD 0.8.7.6
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../';
20
- framesUrl = "../frames.html#!OpenTok/OpenTok.html";
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../_index.html">Index (O)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../OpenTok.html" title="OpenTok (module)">OpenTok</a></span></span>
36
- &raquo;
37
- <span class="title">OpenTok</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Class: OpenTok::OpenTok
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
- <dt class="r1">Inherits:</dt>
75
- <dd class="r1">
76
- <span class="inheritName">Object</span>
77
-
78
- <ul class="fullTree">
79
- <li>Object</li>
80
-
81
- <li class="next">OpenTok::OpenTok</li>
82
-
83
- </ul>
84
- <a href="#" class="inheritanceTree">show all</a>
85
-
86
- </dd>
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
- <dt class="r2 last">Defined in:</dt>
97
- <dd class="r2 last">lib/opentok/opentok.rb</dd>
98
-
99
- </dl>
100
- <div class="clear"></div>
101
-
102
- <h2>Overview</h2><div class="docstring">
103
- <div class="discussion">
104
-
105
- <p>Contains methods for creating OpenTok sessions, generating tokens, and
106
- working with archives.</p>
107
-
108
- <p>To create a new OpenTok object, call the OpenTok constructor with your
109
- OpenTok API key and the API secret from the OpenTok dashboard (<a
110
- href="https://dashboard.tokbox.com">dashboard.tokbox.com</a>). Do not
111
- publicly share your API secret. You will use it with the OpenTok
112
- constructor (only on your web server) to create OpenTok sessions.</p>
113
-
114
-
115
- </div>
116
- </div>
117
- <div class="tags">
118
-
119
-
120
- </div>
121
- <h2>Constant Summary</h2>
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
- <h2>
132
- Instance Method Summary
133
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
134
- </h2>
135
-
136
- <ul class="summary">
137
-
138
- <li class="public ">
139
- <span class="summary_signature">
140
-
141
- <a href="#archives-instance_method" title="#archives (instance method)">- (Object) <strong>archives</strong> </a>
142
-
143
-
144
-
145
- </span>
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
- <span class="summary_desc"><div class='inline'>
156
- <p>An Archives object, which lets you work with OpenTok archives.</p>
157
- </div></span>
158
-
159
- </li>
160
-
161
-
162
- <li class="public ">
163
- <span class="summary_signature">
164
-
165
- <a href="#create_session-instance_method" title="#create_session (instance method)">- (Session) <strong>create_session</strong>(opts = {}) </a>
166
-
167
-
168
-
169
- </span>
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
- <span class="summary_desc"><div class='inline'>
180
- <p>Creates a new OpenTok session and returns the session ID, which uniquely
181
- identifies the session.</p>
182
- </div></span>
183
-
184
- </li>
185
-
186
-
187
- <li class="public ">
188
- <span class="summary_signature">
189
-
190
- <a href="#generate_token-instance_method" title="#generate_token (instance method)">- (String) <strong>generate_token</strong>(options) </a>
191
-
192
-
193
-
194
- </span>
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
- <span class="summary_desc"><div class='inline'>
205
- <p>Generates a token for a given session.</p>
206
- </div></span>
207
-
208
- </li>
209
-
210
-
211
- <li class="public ">
212
- <span class="summary_signature">
213
-
214
- <a href="#initialize-instance_method" title="#initialize (instance method)">- (OpenTok) <strong>initialize</strong>(api_key, api_secret, api_url = ::OpenTok::API_URL) </a>
215
-
216
-
217
-
218
- </span>
219
-
220
-
221
- <span class="note title constructor">constructor</span>
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
- <span class="summary_desc"><div class='inline'>
231
- <p>Create a new OpenTok object.</p>
232
- </div></span>
233
-
234
- </li>
235
-
236
-
237
- </ul>
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
- <div id="constructor_details" class="method_details_list">
247
- <h2>Constructor Details</h2>
248
-
249
- <div class="method_details first">
250
- <h3 class="signature first" id="initialize-instance_method">
251
-
252
- - (<tt><span class='object_link'><a href="" title="OpenTok::OpenTok (class)">OpenTok</a></span></tt>) <strong>initialize</strong>(api_key, api_secret, api_url = ::OpenTok::API_URL)
253
-
254
-
255
-
256
-
257
-
258
- </h3><div class="docstring">
259
- <div class="discussion">
260
-
261
- <p>Create a new OpenTok object.</p>
262
-
263
-
264
- </div>
265
- </div>
266
- <div class="tags">
267
- <p class="tag_title">Parameters:</p>
268
- <ul class="param">
269
-
270
- <li>
271
-
272
- <span class='name'>api_key</span>
273
-
274
-
275
- <span class='type'>(<tt>String</tt>)</span>
276
-
277
-
278
-
279
- &mdash;
280
- <div class='inline'>
281
- <p>Your OpenTok API key. See the OpenTok dashboard (<a
282
- href="https://dashboard.tokbox.com">dashboard.tokbox.com</a>).</p>
283
- </div>
284
-
285
- </li>
286
-
287
- <li>
288
-
289
- <span class='name'>api_secret</span>
290
-
291
-
292
- <span class='type'>(<tt>String</tt>)</span>
293
-
294
-
295
-
296
- &mdash;
297
- <div class='inline'>
298
- <p>Your OpenTok API key.</p>
299
- </div>
300
-
301
- </li>
302
-
303
- <li>
304
-
305
- <span class='name'>api_url</span>
306
-
307
-
308
- <span class='type'>(<tt>String</tt>)</span>
309
-
310
-
311
- <em class="default">(defaults to: <tt>::OpenTok::API_URL</tt>)</em>
312
-
313
-
314
- &mdash;
315
- <div class='inline'>
316
- <p>Do not set this parameter. It is for internal use by TokBox.</p>
317
- </div>
318
-
319
- </li>
320
-
321
- </ul>
322
-
323
-
324
- </div><table class="source_code">
325
- <tr>
326
- <td>
327
- <pre class="lines">
328
-
329
-
330
- 68
331
- 69
332
- 70
333
- 71
334
- 72
335
- 73
336
- 74</pre>
337
- </td>
338
- <td>
339
- <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 68</span>
340
-
341
- <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span><span class='op'>=</span><span class='op'>::</span><span class='const'>OpenTok</span><span class='op'>::</span><span class='const'>API_URL</span><span class='rparen'>)</span>
342
- <span class='ivar'>@api_key</span> <span class='op'>=</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='rparen'>)</span>
343
- <span class='ivar'>@api_secret</span> <span class='op'>=</span> <span class='id identifier rubyid_api_secret'>api_secret</span>
344
- <span class='comment'># TODO: do we really need a copy of this in the instance or should we overwrite the module
345
- </span> <span class='comment'># constant so that other objects can access the same copy?
346
- </span> <span class='ivar'>@api_url</span> <span class='op'>=</span> <span class='id identifier rubyid_api_url'>api_url</span>
347
- <span class='kw'>end</span></pre>
348
- </td>
349
- </tr>
350
- </table>
351
- </div>
352
-
353
- </div>
354
-
355
-
356
- <div id="instance_method_details" class="method_details_list">
357
- <h2>Instance Method Details</h2>
358
-
359
-
360
- <div class="method_details first">
361
- <h3 class="signature first" id="archives-instance_method">
362
-
363
- - (<tt>Object</tt>) <strong>archives</strong>
364
-
365
-
366
-
367
-
368
-
369
- </h3><div class="docstring">
370
- <div class="discussion">
371
-
372
- <p>An Archives object, which lets you work with OpenTok archives.</p>
373
-
374
-
375
- </div>
376
- </div>
377
- <div class="tags">
378
-
379
-
380
- </div><table class="source_code">
381
- <tr>
382
- <td>
383
- <pre class="lines">
384
-
385
-
386
- 171
387
- 172
388
- 173</pre>
389
- </td>
390
- <td>
391
- <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 171</span>
392
-
393
- <span class='kw'>def</span> <span class='id identifier rubyid_archives'>archives</span>
394
- <span class='ivar'>@archives</span> <span class='op'>||=</span> <span class='const'>Archives</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_client'>client</span>
395
- <span class='kw'>end</span></pre>
396
- </td>
397
- </tr>
398
- </table>
399
- </div>
400
-
401
- <div class="method_details ">
402
- <h3 class="signature " id="create_session-instance_method">
403
-
404
- - (<tt><span class='object_link'><a href="Session.html" title="OpenTok::Session (class)">Session</a></span></tt>) <strong>create_session</strong>(opts = {})
405
-
406
-
407
-
408
-
409
-
410
- </h3><div class="docstring">
411
- <div class="discussion">
412
-
413
- <p>Creates a new OpenTok session and returns the session ID, which uniquely
414
- identifies the session.</p>
415
-
416
- <p>For example, when using the OpenTok JavaScript library, use the session ID
417
- when calling the OT.initSession()&lt;/a&gt; method (to initialize an
418
- OpenTok session).</p>
419
-
420
- <p>OpenTok sessions do not expire. However, authentication tokens do expire
421
- (see the generateToken() method). Also note that sessions cannot explicitly
422
- be destroyed.</p>
423
-
424
- <p>A session ID string can be up to 255 characters long.</p>
425
-
426
- <p>Calling this method results in an OpenTokException in the event of an
427
- error. Check the error message for details.</p>
428
-
429
- <p>You can also create a session using the OpenTok REST API (see <a
430
- href="http://www.tokbox.com/opentok/api/#session_id_production">www.tokbox.com/opentok/api/#session_id_production</a>)
431
- or the OpenTok dashboard (see <a
432
- href="https://dashboard.tokbox.com/projects">dashboard.tokbox.com/projects</a>).</p>
433
-
434
-
435
- </div>
436
- </div>
437
- <div class="tags">
438
- <p class="tag_title">Parameters:</p>
439
- <ul class="param">
440
-
441
- <li>
442
-
443
- <span class='name'>opts</span>
444
-
445
-
446
- <span class='type'>(<tt>Hash</tt>)</span>
447
-
448
-
449
- <em class="default">(defaults to: <tt>{}</tt>)</em>
450
-
451
-
452
- &mdash;
453
- <div class='inline'>
454
- <p>(Optional) This hash defines options for the session.</p>
455
- </div>
456
-
457
- </li>
458
-
459
- </ul>
460
-
461
-
462
-
463
-
464
- <p class="tag_title">Options Hash (<tt>opts</tt>):</p>
465
- <ul class="option">
466
-
467
- <li>
468
- <span class="name">:media_mode</span>
469
- <span class="type">(<tt>Symbol</tt>)</span>
470
- <span class="default">
471
-
472
- </span>
473
-
474
- &mdash; <div class='inline'>
475
- <p>Determines whether the session will transmit streams the using OpenTok
476
- Media Router (<tt>:routed</tt>) or not (<tt>:relayed</tt>). By default,
477
- this property is set to <tt>:relayed</tt>.</p>
478
-
479
- <p>With the <tt>media_mode</tt> property set to <tt>:relayed</tt>, the session
480
- will attempt to transmit streams directly between clients. If clients
481
- cannot connect due to firewall restrictions, the session uses the OpenTok
482
- TURN server to relay audio-video streams.</p>
483
-
484
- <p>With the <tt>media_mode</tt> property set to <tt>:routed</tt>, the session
485
- will use the
486
- <a href="https://tokbox.com/opentok/tutorials/create-session/#media-mode" target="_parent" title="OpenTok Media Router">OpenTok Media Router</a>. The OpenTok Media Router provides the following benefits:</p>
487
- <ul><li>
488
- <p>The OpenTok Media Router can decrease bandwidth usage in multiparty
489
- sessions. (When the <tt>media_mode</tt> property is set to
490
- <tt>:relayed</tt>, each client must send a separate audio-video stream to
491
- each client subscribing to it.)</p>
492
- </li><li>
493
- <p>The OpenTok Media Router can improve the quality of the user experience
494
- through <a href="https://tokbox.com/platform/fallback" target="_parent" title="audio fallback and video recovery">audio fallback and video recovery</a>. With these features, if a client’s connectivity degrades to a
495
- degree that it does not support video for a stream it’s subscribing to, the
496
- video is dropped on that client (without affecting other clients), and the
497
- client receives audio only. If the client’s connectivity improves, the
498
- video returns.</p>
499
- </li><li>
500
- <p>The OpenTok Media Router supports the
501
- <a href="https://tokbox.com/opentok/tutorials/archiving" target="_parent" title="archiving">archiving</a> feature, which
502
- lets you record, save, and retrieve OpenTok sessions.</p>
503
- </li></ul>
504
- </div>
505
-
506
- </li>
507
-
508
- <li>
509
- <span class="name">:location</span>
510
- <span class="type">(<tt>String</tt>)</span>
511
- <span class="default">
512
-
513
- </span>
514
-
515
- &mdash; <div class='inline'>
516
- <p>An IP address that the OpenTok servers will use to situate the session in
517
- its global network. If you do not set a location hint, the OpenTok servers
518
- will be based on the first client connecting to the session.</p>
519
- </div>
520
-
521
- </li>
522
-
523
- <li>
524
- <span class="name">:archive_mode</span>
525
- <span class="type">(<tt>Symbol</tt>)</span>
526
- <span class="default">
527
-
528
- </span>
529
-
530
- &mdash; <div class='inline'>
531
- <p>Determines whether the session will be archived automatically
532
- (<tt>:always</tt>) or not (<tt>:manual</tt>). When using automatic
533
- archiving, the session must use the <tt>:routed</tt> media mode.</p>
534
- </div>
535
-
536
- </li>
537
-
538
- </ul>
539
-
540
-
541
- <p class="tag_title">Returns:</p>
542
- <ul class="return">
543
-
544
- <li>
545
-
546
-
547
- <span class='type'>(<tt><span class='object_link'><a href="Session.html" title="OpenTok::Session (class)">Session</a></span></tt>)</span>
548
-
549
-
550
-
551
- &mdash;
552
- <div class='inline'>
553
- <p>The Session object. The session_id property of the object is the session
554
- ID.</p>
555
- </div>
556
-
557
- </li>
558
-
559
- </ul>
560
-
561
- </div><table class="source_code">
562
- <tr>
563
- <td>
564
- <pre class="lines">
565
-
566
-
567
- 132
568
- 133
569
- 134
570
- 135
571
- 136
572
- 137
573
- 138
574
- 139
575
- 140
576
- 141
577
- 142
578
- 143
579
- 144
580
- 145
581
- 146
582
- 147
583
- 148
584
- 149
585
- 150
586
- 151
587
- 152
588
- 153
589
- 154
590
- 155
591
- 156
592
- 157
593
- 158
594
- 159
595
- 160
596
- 161
597
- 162
598
- 163
599
- 164
600
- 165
601
- 166
602
- 167
603
- 168</pre>
604
- </td>
605
- <td>
606
- <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 132</span>
607
-
608
- <span class='kw'>def</span> <span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
609
-
610
- <span class='comment'># normalize opts so all keys are symbols and only include valid_opts
611
- </span> <span class='id identifier rubyid_valid_opts'>valid_opts</span> <span class='op'>=</span> <span class='lbracket'>[</span> <span class='symbol'>:media_mode</span><span class='comma'>,</span> <span class='symbol'>:location</span><span class='comma'>,</span> <span class='symbol'>:archive_mode</span> <span class='rbracket'>]</span>
612
- <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_inject'>inject</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='comma'>,</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='op'>|</span>
613
- <span class='kw'>if</span> <span class='id identifier rubyid_valid_opts'>valid_opts</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
614
- <span class='id identifier rubyid_m'>m</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span>
615
- <span class='kw'>end</span>
616
- <span class='id identifier rubyid_m'>m</span>
617
- <span class='kw'>end</span>
618
-
619
- <span class='comment'># keep opts around for Session constructor, build REST params
620
- </span> <span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_clone'>clone</span>
621
-
622
- <span class='comment'># anything other than :relayed sets the REST param to &quot;disabled&quot;, in which case we force
623
- </span> <span class='comment'># opts to be :routed. if we were more strict we could raise an error when the value isn't
624
- </span> <span class='comment'># either :relayed or :routed
625
- </span> <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:media_mode</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='symbol'>:routed</span>
626
- <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>disabled</span><span class='tstring_end'>&quot;</span></span>
627
- <span class='kw'>else</span>
628
- <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>enabled</span><span class='tstring_end'>&quot;</span></span>
629
- <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='symbol'>:relayed</span>
630
- <span class='kw'>end</span>
631
- <span class='comment'># location is optional, but it has to be an IP address if specified at all
632
- </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
633
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>location must be an IPv4 address</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span> <span class='op'>=~</span> <span class='const'>Resolv</span><span class='op'>::</span><span class='const'>IPv4</span><span class='op'>::</span><span class='const'>Regex</span>
634
- <span class='kw'>end</span>
635
- <span class='comment'># archive mode is optional, but it has to be one of the valid values if present
636
- </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
637
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>archive mode must be either always or manual</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='const'>ARCHIVE_MODES</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
638
- <span class='kw'>end</span>
639
-
640
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>A session with always archive mode must also have the routed media mode.</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='symbol'>:always</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='symbol'>:relayed</span><span class='rparen'>)</span>
641
-
642
- <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
643
- <span class='const'>Session</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_response'>response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sessions</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Session</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>session_id</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span>
644
- <span class='kw'>end</span></pre>
645
- </td>
646
- </tr>
647
- </table>
648
- </div>
649
-
650
- <div class="method_details ">
651
- <h3 class="signature " id="generate_token-instance_method">
652
-
653
- - (<tt>String</tt>) <strong>generate_token</strong>(options)
654
-
655
-
656
-
657
-
658
-
659
- </h3><div class="docstring">
660
- <div class="discussion">
661
-
662
- <p>Generates a token for a given session.</p>
663
-
664
-
665
- </div>
666
- </div>
667
- <div class="tags">
668
- <p class="tag_title">Parameters:</p>
669
- <ul class="param">
670
-
671
- <li>
672
-
673
- <span class='name'>session_id</span>
674
-
675
-
676
- <span class='type'>(<tt>String</tt>)</span>
677
-
678
-
679
-
680
- &mdash;
681
- <div class='inline'>
682
- <p>The session ID of the session to be accessed by the client using the token.</p>
683
- </div>
684
-
685
- </li>
686
-
687
- <li>
688
-
689
- <span class='name'>options</span>
690
-
691
-
692
- <span class='type'>(<tt>Hash</tt>)</span>
693
-
694
-
695
-
696
- &mdash;
697
- <div class='inline'>
698
- <p>A hash defining options for the token.</p>
699
- </div>
700
-
701
- </li>
702
-
703
- </ul>
704
-
705
-
706
-
707
-
708
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
709
- <ul class="option">
710
-
711
- <li>
712
- <span class="name">:role</span>
713
- <span class="type">(<tt>Symbol</tt>)</span>
714
- <span class="default">
715
-
716
- </span>
717
-
718
- &mdash; <div class='inline'>
719
- <p>The role for the token. Set this to one of the following values:</p>
720
- <ul><li>
721
- <p><tt>:subscriber</tt> -- A subscriber can only subscribe to streams.</p>
722
- </li><li>
723
- <p><tt>:publisher</tt> -- A publisher can publish streams, subscribe to
724
- streams, and signal. (This is the default value if you do not specify a
725
- role.)</p>
726
- </li><li>
727
- <p><tt>:moderator</tt> -- In addition to the privileges granted to a
728
- publisher, in clients using the OpenTok.js 2.2 library, a moderator can
729
- call the <tt>forceUnpublish()</tt> and <tt>forceDisconnect()</tt> method of
730
- the Session object.</p>
731
- </li></ul>
732
- </div>
733
-
734
- </li>
735
-
736
- <li>
737
- <span class="name">:expire_time</span>
738
- <span class="type">(<tt>integer</tt>)</span>
739
- <span class="default">
740
-
741
- </span>
742
-
743
- &mdash; <div class='inline'>
744
- <p>The expiration time, in seconds since the UNIX epoch. Pass in 0 to use the
745
- default expiration time of 24 hours after the token creation time. The
746
- maximum expiration time is 30 days after the creation time.</p>
747
- </div>
748
-
749
- </li>
750
-
751
- <li>
752
- <span class="name">:data</span>
753
- <span class="type">(<tt>String</tt>)</span>
754
- <span class="default">
755
-
756
- </span>
757
-
758
- &mdash; <div class='inline'>
759
- <p>A string containing connection metadata describing the end-user. For
760
- example, you can pass the user ID, name, or other data describing the
761
- end-user. The length of the string is limited to 1000 characters. This data
762
- cannot be updated once it is set.</p>
763
- </div>
764
-
765
- </li>
766
-
767
- </ul>
768
-
769
-
770
- <p class="tag_title">Returns:</p>
771
- <ul class="return">
772
-
773
- <li>
774
-
775
-
776
- <span class='type'>(<tt>String</tt>)</span>
777
-
778
-
779
-
780
- &mdash;
781
- <div class='inline'>
782
- <p>The token string.</p>
783
- </div>
784
-
785
- </li>
786
-
787
- </ul>
788
-
789
- </div><table class="source_code">
790
- <tr>
791
- <td>
792
- <pre class="lines">
793
-
794
-
795
- 48
796
- 49
797
- 50
798
- 51
799
- 52
800
- 53
801
- 54
802
- 55
803
- 56
804
- 57
805
- 58
806
- 59
807
- 60
808
- 61
809
- 62
810
- 63
811
- 64
812
- 65
813
- 66
814
- 67
815
- 68
816
- 69
817
- 70
818
- 71
819
- 72
820
- 73
821
- 74
822
- 75
823
- 76
824
- 77
825
- 78
826
- 79
827
- 80
828
- 81
829
- 82
830
- 83
831
- 84
832
- 85
833
- 86
834
- 87
835
- 88
836
- 89
837
- 90
838
- 91
839
- 92
840
- 93
841
- 94
842
- 95
843
- 96
844
- 97
845
- 98
846
- 99
847
- 100
848
- 101
849
- 102
850
- 103
851
- 104
852
- 105
853
- 106
854
- 107
855
- 108
856
- 109
857
- 110
858
- 111
859
- 112
860
- 113
861
- 114
862
- 115
863
- 116
864
- 117
865
- 118
866
- 119
867
- 120
868
- 121
869
- 122
870
- 123
871
- 124
872
- 125
873
- 126
874
- 127
875
- 128
876
- 129
877
- 130
878
- 131
879
- 132
880
- 133
881
- 134
882
- 135
883
- 136
884
- 137
885
- 138
886
- 139
887
- 140
888
- 141
889
- 142
890
- 143
891
- 144
892
- 145
893
- 146
894
- 147
895
- 148
896
- 149
897
- 150
898
- 151
899
- 152
900
- 153
901
- 154
902
- 155
903
- 156
904
- 157
905
- 158
906
- 159
907
- 160
908
- 161
909
- 162
910
- 163
911
- 164
912
- 165
913
- 166
914
- 167
915
- 168
916
- 169
917
- 170
918
- 171
919
- 172
920
- 173
921
- 174
922
- 175
923
- 176
924
- 177
925
- 178
926
- 179
927
- 180
928
- 181</pre>
929
- </td>
930
- <td>
931
- <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 48</span>
932
-
933
- <span class='kw'>class</span> <span class='const'>OpenTok</span>
934
-
935
- <span class='id identifier rubyid_include'>include</span> <span class='const'>TokenGenerator</span>
936
- <span class='id identifier rubyid_generates_tokens'>generates_tokens</span><span class='lparen'>(</span><span class='lbrace'>{</span>
937
- <span class='symbol'>:api_key</span> <span class='op'>=&gt;</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_instance'>instance</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_api_key'>api_key</span> <span class='rbrace'>}</span><span class='comma'>,</span>
938
- <span class='symbol'>:api_secret</span> <span class='op'>=&gt;</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_instance'>instance</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_api_secret'>api_secret</span> <span class='rbrace'>}</span>
939
- <span class='rbrace'>}</span><span class='rparen'>)</span>
940
-
941
- <span class='comment'># @private
942
- </span> <span class='comment'># don't want these to be mutable, may cause bugs related to inconsistency since these values are
943
- </span> <span class='comment'># cached in objects that this can create
944
- </span> <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:api_key</span><span class='comma'>,</span> <span class='symbol'>:api_secret</span><span class='comma'>,</span> <span class='symbol'>:api_url</span>
945
-
946
- <span class='comment'>##
947
- </span> <span class='comment'># Create a new OpenTok object.
948
- </span> <span class='comment'>#
949
- </span> <span class='comment'># @param [String] api_key Your OpenTok API key. See the OpenTok dashboard
950
- </span> <span class='comment'># (https://dashboard.tokbox.com).
951
- </span> <span class='comment'># @param [String] api_secret Your OpenTok API key.
952
- </span> <span class='comment'># @param [String] api_url Do not set this parameter. It is for internal use by TokBox.
953
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span><span class='op'>=</span><span class='op'>::</span><span class='const'>OpenTok</span><span class='op'>::</span><span class='const'>API_URL</span><span class='rparen'>)</span>
954
- <span class='ivar'>@api_key</span> <span class='op'>=</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='rparen'>)</span>
955
- <span class='ivar'>@api_secret</span> <span class='op'>=</span> <span class='id identifier rubyid_api_secret'>api_secret</span>
956
- <span class='comment'># TODO: do we really need a copy of this in the instance or should we overwrite the module
957
- </span> <span class='comment'># constant so that other objects can access the same copy?
958
- </span> <span class='ivar'>@api_url</span> <span class='op'>=</span> <span class='id identifier rubyid_api_url'>api_url</span>
959
- <span class='kw'>end</span>
960
-
961
- <span class='comment'># Creates a new OpenTok session and returns the session ID, which uniquely identifies
962
- </span> <span class='comment'># the session.
963
- </span> <span class='comment'>#
964
- </span> <span class='comment'># For example, when using the OpenTok JavaScript library, use the session ID when calling the
965
- </span> <span class='comment'># OT.initSession()&lt;/a&gt; method (to initialize an OpenTok session).
966
- </span> <span class='comment'>#
967
- </span> <span class='comment'># OpenTok sessions do not expire. However, authentication tokens do expire (see the
968
- </span> <span class='comment'># generateToken() method). Also note that sessions cannot explicitly be destroyed.
969
- </span> <span class='comment'>#
970
- </span> <span class='comment'># A session ID string can be up to 255 characters long.
971
- </span> <span class='comment'>#
972
- </span> <span class='comment'># Calling this method results in an OpenTokException in the event of an error.
973
- </span> <span class='comment'># Check the error message for details.
974
- </span> <span class='comment'>#
975
- </span> <span class='comment'># You can also create a session using the OpenTok REST API (see
976
- </span> <span class='comment'># http://www.tokbox.com/opentok/api/#session_id_production) or the OpenTok dashboard
977
- </span> <span class='comment'># (see https://dashboard.tokbox.com/projects).
978
- </span> <span class='comment'>#
979
- </span> <span class='comment'># @param [Hash] opts (Optional) This hash defines options for the session.
980
- </span> <span class='comment'>#
981
- </span> <span class='comment'># @option opts [Symbol] :media_mode Determines whether the session will transmit streams the
982
- </span> <span class='comment'># using OpenTok Media Router (&lt;code&gt;:routed&lt;/code&gt;) or not (&lt;code&gt;:relayed&lt;/code&gt;).
983
- </span> <span class='comment'># By default, this property is set to &lt;code&gt;:relayed&lt;/code&gt;.
984
- </span> <span class='comment'>#
985
- </span> <span class='comment'># With the &lt;code&gt;media_mode&lt;/code&gt; property set to &lt;code&gt;:relayed&lt;/code&gt;, the session
986
- </span> <span class='comment'># will attempt to transmit streams directly between clients. If clients cannot connect due to
987
- </span> <span class='comment'># firewall restrictions, the session uses the OpenTok TURN server to relay audio-video
988
- </span> <span class='comment'># streams.
989
- </span> <span class='comment'>#
990
- </span> <span class='comment'># With the &lt;code&gt;media_mode&lt;/code&gt; property set to &lt;code&gt;:routed&lt;/code&gt;, the session will use
991
- </span> <span class='comment'># the {https://tokbox.com/opentok/tutorials/create-session/#media-mode OpenTok Media Router}.
992
- </span> <span class='comment'># The OpenTok Media Router provides the following benefits:
993
- </span> <span class='comment'>#
994
- </span> <span class='comment'># * The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
995
- </span> <span class='comment'># (When the &lt;code&gt;media_mode&lt;/code&gt; property is set to &lt;code&gt;:relayed&lt;/code&gt;,
996
- </span> <span class='comment'># each client must send a separate audio-video stream to each client subscribing to
997
- </span> <span class='comment'># it.)
998
- </span> <span class='comment'># * The OpenTok Media Router can improve the quality of the user experience through
999
- </span> <span class='comment'># {https://tokbox.com/platform/fallback audio fallback and video recovery}. With
1000
- </span> <span class='comment'># these features, if a client's connectivity degrades to a degree that
1001
- </span> <span class='comment'># it does not support video for a stream it's subscribing to, the video is dropped on
1002
- </span> <span class='comment'># that client (without affecting other clients), and the client receives audio only.
1003
- </span> <span class='comment'># If the client's connectivity improves, the video returns.
1004
- </span> <span class='comment'># * The OpenTok Media Router supports the
1005
- </span> <span class='comment'># {https://tokbox.com/opentok/tutorials/archiving archiving}
1006
- </span> <span class='comment'># feature, which lets you record, save, and retrieve OpenTok sessions.
1007
- </span> <span class='comment'>#
1008
- </span> <span class='comment'># @option opts [String] :location An IP address that the OpenTok servers will use to
1009
- </span> <span class='comment'># situate the session in its global network. If you do not set a location hint,
1010
- </span> <span class='comment'># the OpenTok servers will be based on the first client connecting to the session.
1011
- </span> <span class='comment'>#
1012
- </span> <span class='comment'># @option opts [Symbol] :archive_mode Determines whether the session will be archived
1013
- </span> <span class='comment'># automatically (&lt;code&gt;:always&lt;/code&gt;) or not (&lt;code&gt;:manual&lt;/code&gt;). When using automatic
1014
- </span> <span class='comment'># archiving, the session must use the &lt;code&gt;:routed&lt;/code&gt; media mode.
1015
- </span> <span class='comment'>#
1016
- </span> <span class='comment'># @return [Session] The Session object. The session_id property of the object is the session ID.
1017
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1018
-
1019
- <span class='comment'># normalize opts so all keys are symbols and only include valid_opts
1020
- </span> <span class='id identifier rubyid_valid_opts'>valid_opts</span> <span class='op'>=</span> <span class='lbracket'>[</span> <span class='symbol'>:media_mode</span><span class='comma'>,</span> <span class='symbol'>:location</span><span class='comma'>,</span> <span class='symbol'>:archive_mode</span> <span class='rbracket'>]</span>
1021
- <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_inject'>inject</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='comma'>,</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='op'>|</span>
1022
- <span class='kw'>if</span> <span class='id identifier rubyid_valid_opts'>valid_opts</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
1023
- <span class='id identifier rubyid_m'>m</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span>
1024
- <span class='kw'>end</span>
1025
- <span class='id identifier rubyid_m'>m</span>
1026
- <span class='kw'>end</span>
1027
-
1028
- <span class='comment'># keep opts around for Session constructor, build REST params
1029
- </span> <span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_clone'>clone</span>
1030
-
1031
- <span class='comment'># anything other than :relayed sets the REST param to &quot;disabled&quot;, in which case we force
1032
- </span> <span class='comment'># opts to be :routed. if we were more strict we could raise an error when the value isn't
1033
- </span> <span class='comment'># either :relayed or :routed
1034
- </span> <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:media_mode</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='symbol'>:routed</span>
1035
- <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>disabled</span><span class='tstring_end'>&quot;</span></span>
1036
- <span class='kw'>else</span>
1037
- <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>enabled</span><span class='tstring_end'>&quot;</span></span>
1038
- <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='symbol'>:relayed</span>
1039
- <span class='kw'>end</span>
1040
- <span class='comment'># location is optional, but it has to be an IP address if specified at all
1041
- </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
1042
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>location must be an IPv4 address</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span> <span class='op'>=~</span> <span class='const'>Resolv</span><span class='op'>::</span><span class='const'>IPv4</span><span class='op'>::</span><span class='const'>Regex</span>
1043
- <span class='kw'>end</span>
1044
- <span class='comment'># archive mode is optional, but it has to be one of the valid values if present
1045
- </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
1046
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>archive mode must be either always or manual</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='const'>ARCHIVE_MODES</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
1047
- <span class='kw'>end</span>
1048
-
1049
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>A session with always archive mode must also have the routed media mode.</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:archive_mode</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='symbol'>:always</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='symbol'>:relayed</span><span class='rparen'>)</span>
1050
-
1051
- <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
1052
- <span class='const'>Session</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_response'>response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sessions</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Session</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>session_id</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span>
1053
- <span class='kw'>end</span>
1054
-
1055
- <span class='comment'># An Archives object, which lets you work with OpenTok archives.
1056
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_archives'>archives</span>
1057
- <span class='ivar'>@archives</span> <span class='op'>||=</span> <span class='const'>Archives</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_client'>client</span>
1058
- <span class='kw'>end</span>
1059
-
1060
- <span class='id identifier rubyid_protected'>protected</span>
1061
-
1062
- <span class='kw'>def</span> <span class='id identifier rubyid_client'>client</span>
1063
- <span class='ivar'>@client</span> <span class='op'>||=</span> <span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span>
1064
- <span class='kw'>end</span>
1065
-
1066
- <span class='kw'>end</span></pre>
1067
- </td>
1068
- </tr>
1069
- </table>
1070
- </div>
1071
-
1072
- </div>
1073
-
1074
- </div>
1075
-
1076
- <div id="footer">
1077
- Generated on Mon May 25 15:52:46 2015 by
1078
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1079
- 0.8.7.6 (ruby-1.9.3).
1080
- </div>
1081
-
1082
- </body>
1083
- </html>