opentok 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +249 -14
- data/lib/opentok/archive.rb +45 -4
- data/lib/opentok/archives.rb +62 -5
- data/lib/opentok/broadcast.rb +118 -0
- data/lib/opentok/broadcasts.rb +149 -0
- data/lib/opentok/client.rb +206 -3
- data/lib/opentok/connections.rb +28 -0
- data/lib/opentok/exceptions.rb +6 -0
- data/lib/opentok/opentok.rb +40 -8
- data/lib/opentok/session.rb +5 -0
- data/lib/opentok/signals.rb +47 -0
- data/lib/opentok/sip.rb +35 -0
- data/lib/opentok/stream.rb +46 -0
- data/lib/opentok/stream_list.rb +18 -0
- data/lib/opentok/streams.rb +79 -0
- data/lib/opentok/version.rb +1 -1
- data/spec/cassettes/OpenTok_Archives/calls_layout_on_archive_object.yml +45 -0
- data/spec/cassettes/OpenTok_Archives/changes_the_layout_of_an_archive.yml +36 -0
- data/spec/cassettes/OpenTok_Archives/should_create_hd_archives.yml +52 -0
- data/spec/cassettes/OpenTok_Broadcasts/calls_layout_on_broadcast_object.yml +55 -0
- data/spec/cassettes/OpenTok_Broadcasts/changes_the_layout_of_a_broadcast.yml +36 -0
- data/spec/cassettes/OpenTok_Broadcasts/fetches_a_hls_broadcast_url.yml +50 -0
- data/spec/cassettes/OpenTok_Broadcasts/finds_a_broadcast.yml +55 -0
- data/spec/cassettes/OpenTok_Broadcasts/starts_a_rtmp_broadcast.yml +59 -0
- data/spec/cassettes/OpenTok_Broadcasts/stops_a_broadcast.yml +45 -0
- data/spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml +36 -0
- data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_a_connection.yml +37 -0
- data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_all_connections.yml +37 -0
- data/spec/cassettes/OpenTok_Streams/get_all_streams_information.yml +53 -0
- data/spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml +42 -0
- data/spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml +36 -0
- data/spec/opentok/archives_spec.rb +73 -0
- data/spec/opentok/broadcasts_spec.rb +171 -0
- data/spec/opentok/connection_spec.rb +38 -0
- data/spec/opentok/signal_spec.rb +50 -0
- data/spec/opentok/streams_spec.rb +75 -0
- metadata +48 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4baddcff5e72cad62caf5c0046c8a2eb3cc375b3
|
4
|
+
data.tar.gz: 59b84a91a65d5841f76f4251a26ea99739386117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bdaf9b065a6e5449b9753d42e3fd906e9afa66635d71b74ae0f2965bc34e138de2a253f4707d0bbbe3fe972584db3f9f235129c55ec1dfb09b4669ef2de0eb1
|
7
|
+
data.tar.gz: ad070ca9e3e516b96c9cbd8aff45ccd9b1f593f657688f8b1c90894c1b72bcb5c9dc53ccea0d19c7ef7d813951645709a6daa3855362625bd3e976be87118f80
|
data/README.md
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
[](https://travis-ci.org/opentok/OpenTok-Ruby-SDK)
|
4
4
|
|
5
5
|
The OpenTok Ruby SDK lets you generate
|
6
|
-
[sessions](
|
7
|
-
[tokens](
|
8
|
-
[OpenTok](http://www.tokbox.com/) applications
|
9
|
-
[
|
6
|
+
[sessions](https://tokbox.com/developer/guides/create-session/) and
|
7
|
+
[tokens](https://tokbox.com/developer/guides/create-token/) for
|
8
|
+
[OpenTok](http://www.tokbox.com/) applications. It also includes methods for
|
9
|
+
working with OpenTok [archives](https://tokbox.com/developer/guides/archiving),
|
10
|
+
working with OpenTok [live streaming
|
11
|
+
broadcasts](https://tokbox.com/developer/guides/broadcast/live-streaming/),
|
12
|
+
working with OpenTok [SIP interconnect](https://tokbox.com/developer/guides/sip),
|
13
|
+
and [disconnecting clients from sessions](https://tokbox.com/developer/guides/moderation/rest/).
|
10
14
|
|
11
15
|
# Installation
|
12
16
|
|
@@ -17,7 +21,7 @@ Bundler helps manage dependencies for Ruby projects. Find more info here: <http:
|
|
17
21
|
Add this gem to your `Gemfile`:
|
18
22
|
|
19
23
|
```ruby
|
20
|
-
gem "opentok", "~> 3.0
|
24
|
+
gem "opentok", "~> 3.1.0"
|
21
25
|
```
|
22
26
|
|
23
27
|
Allow bundler to install the change.
|
@@ -47,11 +51,19 @@ opentok = OpenTok::OpenTok.new api_key, api_secret
|
|
47
51
|
|
48
52
|
## Creating Sessions
|
49
53
|
|
50
|
-
To create an OpenTok Session, use the `OpenTok#create_session(properties)` method.
|
51
|
-
`properties` parameter is an optional Hash used to specify
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
To create an OpenTok Session, use the `OpenTok#create_session(properties)` method.
|
55
|
+
The `properties` parameter is an optional Hash used to specify the following:
|
56
|
+
|
57
|
+
* Whether the session uses the [OpenTok Media
|
58
|
+
Router](https://tokbox.com/developer/guides/create-session/#media-mode),
|
59
|
+
which is required for some OpenTok features (such as archiving)
|
60
|
+
|
61
|
+
* A location hint for the OpenTok server.
|
62
|
+
|
63
|
+
* Whether the session is automatically archived.
|
64
|
+
|
65
|
+
The `session_id` method of the returned `OpenTok::Session` instance is useful to
|
66
|
+
get a sessionId that can be saved to a persistent store (such as a database).
|
55
67
|
|
56
68
|
```ruby
|
57
69
|
# Create a session that will attempt to transmit streams directly between clients.
|
@@ -96,8 +108,37 @@ token = session.generate_token({
|
|
96
108
|
});
|
97
109
|
```
|
98
110
|
|
111
|
+
## Working with Streams
|
112
|
+
|
113
|
+
Use this method to get information for an OpenTok stream or for all streams in a session.
|
114
|
+
For example, you can call this method to get information about layout classes used by an
|
115
|
+
OpenTok stream.
|
116
|
+
|
117
|
+
To get information of a specific stream in a session, call
|
118
|
+
`opentok.streams.find(session_id, stream_id)`. The return object is a `Stream` object and
|
119
|
+
you can access various stream properties as shown in the following example (using RSpec notations):
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
expect(stream).to be_an_instance_of OpenTok::Stream
|
123
|
+
expect(stream.videoType).to eq 'camera'
|
124
|
+
expect(stream.layoutClassList.count).to eq 1
|
125
|
+
expect(stream.layoutClassList.first).to eq "full"
|
126
|
+
```
|
127
|
+
|
128
|
+
To get information on all streams in a session, call `opentok.streams.all(session_id)`.
|
129
|
+
The return value is a `StreamList` object:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
expect(all_streams).to be_an_instance_of OpenTok::StreamList
|
133
|
+
expect(all_streams.total).to eq 2
|
134
|
+
expect(all_streams[0].layoutClassList[1]).to eq "focus"
|
135
|
+
```
|
136
|
+
|
99
137
|
## Working with Archives
|
100
138
|
|
139
|
+
You can only archive sessions that use the OpenTok Media Router
|
140
|
+
(sessions with the media mode set to routed).
|
141
|
+
|
101
142
|
You can start the recording of an OpenTok Session using the `opentok.archives.create(session_id,
|
102
143
|
options)` method. This will return an `OpenTok::Archive` instance. The parameter `options` is an
|
103
144
|
optional Hash used to set the `has_audio`, `has_video`, and `name` options. Note that you can
|
@@ -127,6 +168,19 @@ archive = opentok.archives.create session_id :output_mode => :individual
|
|
127
168
|
The `:output_mode => :composed` setting (the default) causes all streams in the archive to be
|
128
169
|
recorded to a single (composed) file.
|
129
170
|
|
171
|
+
For composed archives you can set the resolution of the archive, either "640x480" (SD, the default)
|
172
|
+
or "1280x720" (HD). The `resolution` parameter is optional and could be included in the options
|
173
|
+
hash (second argument) of the `opentok.archives.create()` method.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
opts = {
|
177
|
+
:output_mode => :composed,
|
178
|
+
:resolution => "1280x720"
|
179
|
+
}
|
180
|
+
|
181
|
+
archive = opentok.archives.create session_id, opts
|
182
|
+
```
|
183
|
+
|
130
184
|
You can stop the recording of a started Archive using the `opentok.archives.stop_by_id(archive_id)`
|
131
185
|
method. You can also do this using the `Archive#stop()` method.
|
132
186
|
|
@@ -175,14 +229,194 @@ Note that you can also create an automatically archived session, by passing in `
|
|
175
229
|
as the `:archive_mode` property of the `options` parameter passed into the
|
176
230
|
`OpenTok#create_session()` method (see "Creating Sessions," above).
|
177
231
|
|
232
|
+
You can set the [layout](https://tokbox.com/developer/rest/#change_composed_archive_layout) of an archive:
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
opts = { :type => "verticalPresentation" }
|
236
|
+
opentok.archives.layout(archive_id, opts)
|
237
|
+
```
|
238
|
+
|
239
|
+
The hash `opts` has two entries:
|
240
|
+
|
241
|
+
* The `type` is the layout type for the archive. Valid values are "bestFit" (best fit)
|
242
|
+
"custom" (custom), "horizontalPresentation" (horizontal presentation),
|
243
|
+
"pip" (picture-in-picture), and "verticalPresentation" (vertical presentation)).
|
244
|
+
|
245
|
+
* If you specify a "custom" layout type, set the `stylesheet` property.
|
246
|
+
(For other layout types, do not set the stylesheet property.)
|
247
|
+
|
248
|
+
See [Customizing the video layout for composed archives](https://tokbox.com/developer/guides/archiving/layout-control.html)
|
249
|
+
for more details.
|
250
|
+
|
251
|
+
You can set the initial layout class for a client's streams by setting the layout option when you
|
252
|
+
create the token for the client, using the `opentok.generate_token` method. And you can also change
|
253
|
+
the layout classes of a stream as follows:
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
streams_list = {
|
257
|
+
:items => [
|
258
|
+
{
|
259
|
+
:id => "8b732909-0a06-46a2-8ea8-074e64d43422",
|
260
|
+
:layoutClassList => ["full"]
|
261
|
+
},
|
262
|
+
{
|
263
|
+
:id => "8b732909-0a06-46a2-8ea8-074e64d43423",
|
264
|
+
:layoutClassList => ["full", "focus"]
|
265
|
+
}
|
266
|
+
]
|
267
|
+
}
|
268
|
+
response = opentok.streams.layout(session_id, streams_list)
|
269
|
+
```
|
270
|
+
|
271
|
+
For more information on setting stream layout classes, see the
|
272
|
+
[Changing the composed archive layout classes for an OpenTok
|
273
|
+
stream](https://tokbox.com/developer/rest/#change-stream-layout-classes-composed).
|
274
|
+
|
275
|
+
Please keep in mind that the `streams.layout` method applies to archive and broadcast streams only.
|
276
|
+
|
178
277
|
For more information on archiving, see the
|
179
278
|
[OpenTok archiving](https://tokbox.com/opentok/tutorials/archiving/) programming guide.
|
180
279
|
|
280
|
+
## Signaling
|
181
281
|
|
182
|
-
|
282
|
+
You can send a signal using the `opentok.signals.send(session_id, connection_id, opts)` method.
|
283
|
+
If `connection_id` is nil or an empty string, then the signal is send to all valid connections in
|
284
|
+
the session.
|
285
|
+
|
286
|
+
An example of `opts` field can be as follows:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
opts = { :type => "chat",
|
290
|
+
:data => "Hello"
|
291
|
+
}
|
292
|
+
```
|
293
|
+
|
294
|
+
The maximum length of the `type` string is 128 bytes, and it must contain only letters
|
295
|
+
(A-Z and a-z), numbers (0-9), '-', '_', and '~'.
|
296
|
+
|
297
|
+
The `data` string must not exceed the maximum size (8 kB).
|
298
|
+
|
299
|
+
The `connection_id` and `opts` parameter are jointly optional by default. Hence you can also
|
300
|
+
use `opentok.signals.send(session_id)`
|
301
|
+
|
302
|
+
For more information on signaling, see the
|
303
|
+
[OpenTok Signaling](https://tokbox.com/developer/guides/signaling/js/) programming guide.
|
304
|
+
|
305
|
+
## Broadcasting
|
306
|
+
|
307
|
+
You can broadcast your streams to a HLS or RTMP servers.
|
308
|
+
|
309
|
+
To successfully start broadcasting a session, at least one publishing client must be connected to
|
310
|
+
the session.
|
311
|
+
|
312
|
+
You can only have one active live streaming broadcast at a time for a session (however, having more
|
313
|
+
than one would not be useful).
|
314
|
+
|
315
|
+
The live streaming broadcast can target one HLS endpoint and up to five RTMP servers simultaneously
|
316
|
+
for a session.
|
317
|
+
|
318
|
+
You can only start live streaming for sessions that use the OpenTok Media Router (with the
|
319
|
+
media mode set to routed). You cannot use live streaming with sessions that have the media mode set
|
320
|
+
to relayed.
|
321
|
+
|
322
|
+
To create a HLS only broadcast:
|
323
|
+
```ruby
|
324
|
+
opts = {
|
325
|
+
:outputs => {
|
326
|
+
:hls => {}
|
327
|
+
}
|
328
|
+
}
|
329
|
+
broadcast = opentok.broadcasts.create(session_id, opts)
|
330
|
+
|
331
|
+
# HLS + RTMP
|
332
|
+
opts = {
|
333
|
+
:outputs => {
|
334
|
+
:hls => {},
|
335
|
+
:rtmp => [
|
336
|
+
{
|
337
|
+
:id => "myOpentokStream",
|
338
|
+
:serverUrl => "rtmp://x.rtmp.youtube.com/live123",
|
339
|
+
:streamName => "66c9-jwuh-pquf-9x00"
|
340
|
+
}
|
341
|
+
]
|
342
|
+
}
|
343
|
+
}
|
344
|
+
broadcast = opentok.broadcasts.create(session_id, opts)
|
345
|
+
```
|
346
|
+
|
347
|
+
The returned Broadcast object has information about the broadcast, like id, sessionId , projectId,
|
348
|
+
createdAt, updatedAt, resolution, status, and a Hash of broadcastUrls. The broadcastUrls
|
349
|
+
consists of an HLS URL and an array of RTMP objects. The RTMP objects resembles the `rtmp` value
|
350
|
+
in `opts` in the example above.
|
351
|
+
|
352
|
+
For more information on broadcast, see the
|
353
|
+
[OpenTok Broadcast guide](https://tokbox.com/developer/rest/#start_broadcast) programming guide.
|
183
354
|
|
184
|
-
|
355
|
+
To get information about a broadcast stream
|
356
|
+
```ruby
|
357
|
+
my_broadcast = opentok.broadcasts.find broadcast_id
|
358
|
+
```
|
359
|
+
The Broadcast object returned has properties describing the broadcast, like id, sessionId,
|
360
|
+
projectId, createdAt, updatedAt, resolution, status, and a Hash of broadcastUrls. The broadcastUrls
|
361
|
+
consists of an HLS URL and an array of RTMP objects. The RTMP objects resembles the `rtmp` value
|
362
|
+
in `opts` in the example above.
|
363
|
+
|
364
|
+
To stop a broadcast:
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
my_broadcast = opentok.broadcasts.stop broadcast_id
|
368
|
+
|
369
|
+
# stop at a broadcast object level too
|
370
|
+
#
|
371
|
+
my_broadcast = opentok.broadcasts.find broadcast_id
|
372
|
+
ret_broadcast = my_broadcast.stop
|
373
|
+
|
374
|
+
# Both the above returned objects has the "broadcastUrls" property as a nil value and the status
|
375
|
+
# property value is "stopped"
|
376
|
+
```
|
377
|
+
|
378
|
+
|
379
|
+
To change the layout of a broadcast dynamically
|
380
|
+
```ruby
|
381
|
+
opentok.broadcasts.layout(started_broadcast_id, {
|
382
|
+
:type => "verticalPresentation"
|
383
|
+
})
|
384
|
+
|
385
|
+
# On an object level
|
386
|
+
my_broadcast = opentok.broadcasts.find broadcast_id
|
387
|
+
my_broadcast.layout(
|
388
|
+
:type => 'pip',
|
389
|
+
)
|
390
|
+
|
391
|
+
# the returned value is true if successful
|
392
|
+
```
|
393
|
+
|
394
|
+
The hash above has two entries.
|
395
|
+
|
396
|
+
* The `type` is the layout type for the archive. Valid values are "bestFit" (best fit),
|
397
|
+
"custom" (custom), "horizontalPresentation" (horizontal presentation),
|
398
|
+
"pip" (picture-in-picture), and "verticalPresentation" (vertical presentation).
|
399
|
+
|
400
|
+
* If you specify a "custom" layout type, set the `stylesheet` property. (For other layout types,
|
401
|
+
do not set the stylesheet property.)
|
402
|
+
|
403
|
+
Refer to [Customizing the video layout for composed
|
404
|
+
archives](https://tokbox.com/developer/guides/archiving/layout-control.html)
|
405
|
+
for more details.
|
406
|
+
|
407
|
+
You can also change the layout of an individual stream dynamically. Refer to
|
408
|
+
[working with Streams](#working-with-streams).
|
409
|
+
|
410
|
+
## Force disconnect
|
411
|
+
|
412
|
+
You can cause a client to be forced to disconnect from a session by using the
|
413
|
+
`opentok.connections.forceDisconnect(session_id, connection_id)` method.
|
414
|
+
|
415
|
+
## Initiating a SIP call
|
185
416
|
|
417
|
+
You can initiate a SIP call using the `opentok.sip.dial(session_id, token, sip_uri, opts)` method.
|
418
|
+
This requires a SIP URL. You will often need to pass options for authenticating to the SIP provider
|
419
|
+
and specifying encrypted session establishment.
|
186
420
|
|
187
421
|
```ruby
|
188
422
|
opts = { "auth" => { "username" => sip_username,
|
@@ -193,7 +427,7 @@ response = opentok.sip.dial(session_id, token, "sip:+15128675309@acme.pstn.examp
|
|
193
427
|
```
|
194
428
|
|
195
429
|
For more information on SIP Interconnect, see the
|
196
|
-
[OpenTok SIP Interconnect](https://tokbox.com/developer/guides/sip/)
|
430
|
+
[OpenTok SIP Interconnect](https://tokbox.com/developer/guides/sip/) developer guide.
|
197
431
|
|
198
432
|
|
199
433
|
# Samples
|
@@ -210,7 +444,8 @@ Reference documentation is available at <http://www.tokbox.com//opentok/librarie
|
|
210
444
|
|
211
445
|
# Requirements
|
212
446
|
|
213
|
-
You need an OpenTok API key and API secret, which you can obtain
|
447
|
+
You need an OpenTok API key and API secret, which you can obtain by logging into your
|
448
|
+
[TokBox account](https://tokbox.com/account).
|
214
449
|
|
215
450
|
The OpenTok Ruby SDK requires Ruby 1.9.3 or greater.
|
216
451
|
|
data/lib/opentok/archive.rb
CHANGED
@@ -54,8 +54,8 @@ module OpenTok
|
|
54
54
|
# * "started" -- The archive started and is in the process of being recorded.
|
55
55
|
# * "stopped" -- The archive stopped recording.
|
56
56
|
# * "uploaded" -- The archive is available for download from the the upload target
|
57
|
-
# Amazon S3 bucket or Windows Azure container you set
|
58
|
-
#
|
57
|
+
# Amazon S3 bucket or Windows Azure container you set for your
|
58
|
+
# {https://tokbox.com/account OpenTok project}.
|
59
59
|
#
|
60
60
|
# @attr [string] url
|
61
61
|
# The download URL of the available MP4 file. This is only set for an archive with the status set to
|
@@ -71,14 +71,14 @@ module OpenTok
|
|
71
71
|
@json = json
|
72
72
|
end
|
73
73
|
|
74
|
-
# A JSON
|
74
|
+
# A JSON-encoded string representation of the archive.
|
75
75
|
def to_json
|
76
76
|
@json.to_json
|
77
77
|
end
|
78
78
|
|
79
79
|
# Stops an OpenTok archive that is being recorded.
|
80
80
|
#
|
81
|
-
# Archives automatically stop recording after
|
81
|
+
# Archives automatically stop recording after 120 minutes or when all clients have disconnected
|
82
82
|
# from the session being archived.
|
83
83
|
def stop
|
84
84
|
# TODO: validate returned json fits schema
|
@@ -95,6 +95,47 @@ module OpenTok
|
|
95
95
|
@json = @interface.delete_by_id @json['id']
|
96
96
|
end
|
97
97
|
|
98
|
+
# Sets the layout type for a composed archive. For a description of layout types, see
|
99
|
+
# {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
|
100
|
+
# the video layout for composed archives}.
|
101
|
+
#
|
102
|
+
# @option options [String] :type
|
103
|
+
# The layout type. Set this to "bestFit", "pip", "verticalPresentation",
|
104
|
+
# "horizontalPresentation", "focus", or "custom".
|
105
|
+
#
|
106
|
+
# @option options [String] :stylesheet
|
107
|
+
# The stylesheet for a custom layout. Set this parameter
|
108
|
+
# if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
|
109
|
+
#
|
110
|
+
# @raise [ArgumentError] The archive_id or options parameter is empty. Or the "custom"
|
111
|
+
# type was specified without a stylesheet option. Or a stylesheet was passed in for a
|
112
|
+
# type other than custom. Or an invalid type was passed in.
|
113
|
+
#
|
114
|
+
# @raise [OpenTokAuthenticationError]
|
115
|
+
# Authentication failed.
|
116
|
+
#
|
117
|
+
# @raise [ArgumentError]
|
118
|
+
# The archive_id or options parameter is empty.
|
119
|
+
#
|
120
|
+
# @raise [ArgumentError]
|
121
|
+
# The "custom" type was specified without a stylesheet option.
|
122
|
+
#
|
123
|
+
# @raise [ArgumentError]
|
124
|
+
# A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
|
125
|
+
#
|
126
|
+
# @raise [ArgumentError]
|
127
|
+
# An invalid layout type was passed in.
|
128
|
+
#
|
129
|
+
# @raise [OpenTokError]
|
130
|
+
# OpenTok server error.
|
131
|
+
#
|
132
|
+
# @raise [OpenTokArchiveError]
|
133
|
+
# Setting the layout failed.
|
134
|
+
def layout(opts= {})
|
135
|
+
# TODO: validate returned json fits schema
|
136
|
+
@json = @interface.layout(@json['id'], opts)
|
137
|
+
end
|
138
|
+
|
98
139
|
# @private ignore
|
99
140
|
def method_missing(method, *args, &block)
|
100
141
|
camelized_method = method.to_s.camelize(:lower)
|
data/lib/opentok/archives.rb
CHANGED
@@ -24,8 +24,8 @@ module OpenTok
|
|
24
24
|
# {https://tokbox.com/opentok/tutorials/archiving OpenTok archiving} programming guide.
|
25
25
|
#
|
26
26
|
# @param [String] session_id The session ID of the OpenTok session to archive.
|
27
|
-
# @param [Hash] options A hash with the
|
28
|
-
#
|
27
|
+
# @param [Hash] options A hash with the keys 'name', 'has_audio', 'has_video',
|
28
|
+
# and 'output_mode'.
|
29
29
|
# @option options [String] :name This is the name of the archive. You can use this name
|
30
30
|
# to identify the archive. It is a property of the Archive object, and it is a property
|
31
31
|
# of archive-related events in the OpenTok client SDKs.
|
@@ -44,6 +44,10 @@ module OpenTok
|
|
44
44
|
# (<code>:individual</code>). For more information on archiving and the archive file
|
45
45
|
# formats, see the {https://tokbox.com/opentok/tutorials/archiving OpenTok archiving}
|
46
46
|
# programming guide.
|
47
|
+
# @option options [String] :resolution The resolution of the archive, either "640x480" (SD, the
|
48
|
+
# default) or "1280x720" (HD). This property only applies to composed archives. If you set
|
49
|
+
# this property and set the outputMode property to "individual", the call the method
|
50
|
+
# results in an error.
|
47
51
|
#
|
48
52
|
# @return [Archive] The Archive object, which includes properties defining the archive,
|
49
53
|
# including the archive ID.
|
@@ -58,9 +62,11 @@ module OpenTok
|
|
58
62
|
# @raise [OpenTokArchiveError] The archive could not be started.
|
59
63
|
def create(session_id, options = {})
|
60
64
|
raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
|
65
|
+
raise ArgumentError,
|
66
|
+
"Resolution cannot be supplied for individual output mode" if options.key?(:resolution) and options[:output_mode] == :individual
|
61
67
|
|
62
68
|
# normalize opts so all keys are symbols and only include valid_opts
|
63
|
-
valid_opts = [ :name, :has_audio, :has_video, :output_mode ]
|
69
|
+
valid_opts = [ :name, :has_audio, :has_video, :output_mode, :resolution ]
|
64
70
|
opts = options.inject({}) do |m,(k,v)|
|
65
71
|
if valid_opts.include? k.to_sym
|
66
72
|
m[k.to_sym] = v
|
@@ -97,7 +103,7 @@ module OpenTok
|
|
97
103
|
# @option options [integer] :count Optional. The number of archives to be returned. The maximum
|
98
104
|
# number of archives returned is 1000.
|
99
105
|
# @option options [String] :session_id Optional. The session ID that archives belong to. This is
|
100
|
-
# useful when listing multiple archives for an {https://tokbox.com/developer/guides/archiving/#automatic-archives automatically archived session}
|
106
|
+
# useful when listing multiple archives for an {https://tokbox.com/developer/guides/archiving/#automatic-archives automatically archived session}.
|
101
107
|
#
|
102
108
|
# @return [ArchiveList] An ArchiveList object, which is an array of Archive objects.
|
103
109
|
def all(options = {})
|
@@ -108,7 +114,7 @@ module OpenTok
|
|
108
114
|
|
109
115
|
# Stops an OpenTok archive that is being recorded.
|
110
116
|
#
|
111
|
-
# Archives automatically stop recording after
|
117
|
+
# Archives automatically stop recording after 120 minutes or when all clients have disconnected
|
112
118
|
# from the session being archived.
|
113
119
|
#
|
114
120
|
# @param [String] archive_id The archive ID of the archive you want to stop recording.
|
@@ -146,5 +152,56 @@ module OpenTok
|
|
146
152
|
(200..300).include? response.code
|
147
153
|
end
|
148
154
|
|
155
|
+
# Sets the layout type for a composed archive. For a description of layout types, see
|
156
|
+
# {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
|
157
|
+
# the video layout for composed archives}.
|
158
|
+
#
|
159
|
+
# @param [String] archive_id
|
160
|
+
# The archive ID.
|
161
|
+
#
|
162
|
+
# @option options [String] :type
|
163
|
+
# The layout type. Set this to "bestFit", "pip", "verticalPresentation",
|
164
|
+
# "horizontalPresentation", "focus", or "custom".
|
165
|
+
#
|
166
|
+
# @option options [String] :stylesheet
|
167
|
+
# The stylesheet for a custom layout. Set this parameter
|
168
|
+
# if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
|
169
|
+
#
|
170
|
+
# @raise [ArgumentError]
|
171
|
+
# The archive_id or options parameter is empty. Or the "custom"
|
172
|
+
# type was specified without a stylesheet option. Or a stylesheet was passed in for a
|
173
|
+
# type other than custom. Or an invalid type was passed in.
|
174
|
+
#
|
175
|
+
# @raise [OpenTokAuthenticationError]
|
176
|
+
# Authentication failed.
|
177
|
+
#
|
178
|
+
# @raise [ArgumentError]
|
179
|
+
# The archive_id or options parameter is empty.
|
180
|
+
#
|
181
|
+
# @raise [ArgumentError]
|
182
|
+
# The "custom" type was specified without a stylesheet option.
|
183
|
+
#
|
184
|
+
# @raise [ArgumentError]
|
185
|
+
# A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
|
186
|
+
#
|
187
|
+
# @raise [ArgumentError]
|
188
|
+
# An invalid layout type was passed in.
|
189
|
+
#
|
190
|
+
# @raise [OpenTokError]
|
191
|
+
# OpenTok server error.
|
192
|
+
#
|
193
|
+
# @raise [OpenTokArchiveError]
|
194
|
+
# Setting the layout failed.
|
195
|
+
def layout(archive_id, options = {})
|
196
|
+
raise ArgumentError, "option parameter is empty" if options.empty?
|
197
|
+
raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty?
|
198
|
+
type = options[:type]
|
199
|
+
raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!options.key? :stylesheet)
|
200
|
+
valid_non_custom_type = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""].include? type
|
201
|
+
raise ArgumentError, "type is not valid or stylesheet not needed" if !valid_non_custom_type
|
202
|
+
raise ArgumentError, "type is not valid or stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
|
203
|
+
response = @client.layout_archive(archive_id, options)
|
204
|
+
(200..300).include? response.code
|
205
|
+
end
|
149
206
|
end
|
150
207
|
end
|