opentok 4.13.0 → 4.14.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/CHANGES.md +8 -0
- data/README.md +56 -2
- data/lib/opentok/client.rb +37 -3
- data/lib/opentok/connection.rb +46 -0
- data/lib/opentok/connection_list.rb +19 -0
- data/lib/opentok/connections.rb +22 -1
- data/lib/opentok/constants.rb +1 -0
- data/lib/opentok/opentok.rb +14 -2
- data/lib/opentok/session.rb +1 -0
- data/lib/opentok/token_generator.rb +42 -5
- data/lib/opentok/version.rb +1 -1
- data/lib/opentok/websocket.rb +2 -0
- data/opentok.gemspec +1 -1
- data/spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_all_connections.yml +63 -0
- data/spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_connections_with_an_offset.yml +55 -0
- data/spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_count_number_of_connections.yml +51 -0
- data/spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_part_of_the_connections_when_using_offset_and_count.yml +51 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml +1 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml +1 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml +1 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml +1 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_default_sessions.yml +5 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml +1 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions.yml +2 -1
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_for_invalid_media_modes.yml +2 -1
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_with_a_location_hint.yml +2 -1
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions.yml +2 -1
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_with_a_location_hint.yml +2 -1
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_sessions_with_a_location_hint.yml +2 -1
- 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 -1
- data/spec/opentok/connection_spec.rb +55 -7
- metadata +18 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70820e3fc205e74907214c25466b8a10b31ba550ab5386cfe728588e714802ba
|
|
4
|
+
data.tar.gz: 4afbf5e3276d0d055f0ce502408b36c7c79165ae67bfbb45f8bb0409ff466d0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6943fac926e9635617f9e0331766772e4e6404eb06fc663052ef0f0b8837ae6ac7d0e70727443d081bcad844a2a6cf997ebef46b5bd47be71c3e87aa4117e0d7
|
|
7
|
+
data.tar.gz: 7895a15eb0797a26629e24391303a10c0e1298f9515396384a8232381ed28d253090050a29a311911d5dc0aa1c28aa5e327414e4f23d410bfe5cb1b15ca88fc0
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 4.14.0
|
|
2
|
+
|
|
3
|
+
* Implements functionality to allow the use of Vonage Video endpoints and credentials.
|
|
4
|
+
* Adds a `Connections#list` method to allow the listing of connections to a session.
|
|
5
|
+
* Adds support for the 24KHz `audio_rate` for `WebSocket` connections
|
|
6
|
+
|
|
7
|
+
See [#295](https://github.com/opentok/OpenTok-Ruby-SDK/pull/295)
|
|
8
|
+
|
|
1
9
|
# 4.13.0
|
|
2
10
|
|
|
3
11
|
* Updating the `Archives#create` method to allow `quantization_parameter` as an option, and the `WebSocket#connect` method to allow `bidirectional` as an option. See [#290](https://github.com/opentok/OpenTok-Ruby-SDK/pull/290)
|
data/README.md
CHANGED
|
@@ -19,6 +19,7 @@ The OpenTok Ruby SDK provides methods for:
|
|
|
19
19
|
* [Forcing clients in a session to disconnect or mute published audio](https://tokbox.com/developer/guides/moderation/)
|
|
20
20
|
* Working with OpenTok [Experience Composers](https://tokbox.com/developer/guides/experience-composer)
|
|
21
21
|
* Working with OpenTok [Audio Connector](https://tokbox.com/developer/guides/audio-connector)
|
|
22
|
+
* Using [Vonage Endpoints and Credentials](#using-vonage-endpoints-and-credentials)
|
|
22
23
|
|
|
23
24
|
## Note!
|
|
24
25
|
|
|
@@ -486,10 +487,42 @@ for more details.
|
|
|
486
487
|
You can also change the layout of an individual stream dynamically. Refer to
|
|
487
488
|
[working with Streams](#working-with-streams).
|
|
488
489
|
|
|
489
|
-
###
|
|
490
|
+
### Working with Connections
|
|
491
|
+
|
|
492
|
+
#### Listing Connections
|
|
493
|
+
|
|
494
|
+
You can retrieve a list of clients connected to a session using the `OpenTok::Connections#list` method, passing in the Session ID of the session, for example:
|
|
495
|
+
|
|
496
|
+
```ruby
|
|
497
|
+
connection_list = opentok.connections.list('abcdefg12345')
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
This will return an iterable `ConnectionList` object with `total` and `session_id` getter methods:
|
|
501
|
+
|
|
502
|
+
```ruby
|
|
503
|
+
connection_list.total # => 5
|
|
504
|
+
connection_list.session_id # => 'abcdefg12345'
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
The items in the connection list are `Connection` objects, each representing a client connection to the session. You can access data on individual connection objects:
|
|
508
|
+
|
|
509
|
+
```ruby
|
|
510
|
+
connection_1 = connection_list.first
|
|
511
|
+
connection_1.connection_id # => "249b7640-1bcf-4f49-8fc7-3d7998ff218b"
|
|
512
|
+
connection_1.connection_state # => "Connected"
|
|
513
|
+
connection_1.created_at # => 1779287104931
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
#### Force disconnect
|
|
490
517
|
|
|
491
518
|
You can cause a client to be forced to disconnect from a session by using the
|
|
492
|
-
`opentok.connections.forceDisconnect(session_id, connection_id)` method.
|
|
519
|
+
`opentok.connections.forceDisconnect(session_id, connection_id)` method and passing in the Session ID and Connection ID.
|
|
520
|
+
|
|
521
|
+
You can also call the `Connection#force_disconnect` method on a `Connection` object returned when listing connections:
|
|
522
|
+
|
|
523
|
+
```ruby
|
|
524
|
+
connection_1.force_disconnect
|
|
525
|
+
```
|
|
493
526
|
|
|
494
527
|
### Forcing clients in a session to mute published audio
|
|
495
528
|
|
|
@@ -536,6 +569,27 @@ and `opentok.renders.list(options)` methods.
|
|
|
536
569
|
You can start an [Audio Connector](https://tokbox.com/developer/guides/audio-connector) WebSocket
|
|
537
570
|
by calling the `opentok.websocket.connect()` method.
|
|
538
571
|
|
|
572
|
+
### Using Vonage Endpoints and Credentials
|
|
573
|
+
|
|
574
|
+
You can use this library with the [Vonage Video API endpoints](https://developer.vonage.com/en/api/video) and Vonage credentials, instead of the TokBox endpoints and credentials.
|
|
575
|
+
|
|
576
|
+
In order to do so, you will need to create a Vonage Application in order to generate an Application ID and Private Key. You can create a Vonage Application in the following ways:
|
|
577
|
+
|
|
578
|
+
- Via the [Vonage Developer Dashboard](https://dashboard.nexmo.com/applications)
|
|
579
|
+
- Using the [Vonage CLI](https://github.com/vonage/vonage-cli)
|
|
580
|
+
- Using the [Vonage Application API](https://developer.vonage.com/application/code-snippets/application/create-application)
|
|
581
|
+
|
|
582
|
+
Once you have the Application ID and Private Key, you can instantiate am `OpenTok` object as you normally would, using the Application ID in place of the API Key and the Private Key instead of the API Secret.
|
|
583
|
+
Additionally, you need to specify in the options that the Vonage endpoints should be used:
|
|
584
|
+
|
|
585
|
+
```ruby
|
|
586
|
+
require "opentok"
|
|
587
|
+
|
|
588
|
+
opentok = OpenTok::OpenTok.new application_id, private_key, :use_vonage_endpoints => true
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
You can then use the `OpenTok` object as you normally would to create sessions, generate client tokens, and perform other interactions with the API.
|
|
592
|
+
|
|
539
593
|
## Samples
|
|
540
594
|
|
|
541
595
|
There are three sample applications included in this repository. To get going as fast as possible, clone the whole
|
data/lib/opentok/client.rb
CHANGED
|
@@ -5,7 +5,7 @@ require "opentok/version"
|
|
|
5
5
|
|
|
6
6
|
require "active_support/inflector"
|
|
7
7
|
require "httparty"
|
|
8
|
-
require "jwt"
|
|
8
|
+
require "vonage-jwt"
|
|
9
9
|
|
|
10
10
|
module OpenTok
|
|
11
11
|
# @private For internal use by the SDK.
|
|
@@ -16,6 +16,7 @@ module OpenTok
|
|
|
16
16
|
# debug_output $stdout
|
|
17
17
|
|
|
18
18
|
attr_accessor :api_key, :api_secret, :api_url, :ua_addendum, :timeout_length
|
|
19
|
+
attr_reader :use_vonage_endpoints
|
|
19
20
|
|
|
20
21
|
def initialize(api_key, api_secret, api_url, ua_addendum='', opts={})
|
|
21
22
|
self.class.base_uri api_url
|
|
@@ -26,6 +27,7 @@ module OpenTok
|
|
|
26
27
|
@api_secret = api_secret
|
|
27
28
|
@timeout_length = opts[:timeout_length] || 2
|
|
28
29
|
self.class.open_timeout @timeout_length
|
|
30
|
+
@use_vonage_endpoints = opts[:use_vonage_endpoints] == true ? true : false
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def generate_jwt(api_key, api_secret)
|
|
@@ -39,8 +41,16 @@ module OpenTok
|
|
|
39
41
|
token
|
|
40
42
|
end
|
|
41
43
|
|
|
44
|
+
def generate_vonage_jwt(api_key, api_secret)
|
|
45
|
+
Vonage::JWTBuilder.new(application_id: api_key, private_key: api_secret).jwt.generate
|
|
46
|
+
end
|
|
47
|
+
|
|
42
48
|
def generate_headers(extra_headers = {})
|
|
43
|
-
|
|
49
|
+
if use_vonage_endpoints == true
|
|
50
|
+
defaults = { "Authorization" => "Bearer #{generate_vonage_jwt(@api_key, @api_secret)}" }
|
|
51
|
+
else
|
|
52
|
+
defaults = { "X-OPENTOK-AUTH" => generate_jwt(@api_key, @api_secret) }
|
|
53
|
+
end
|
|
44
54
|
defaults.merge extra_headers
|
|
45
55
|
end
|
|
46
56
|
|
|
@@ -48,7 +58,7 @@ module OpenTok
|
|
|
48
58
|
opts.extend(HashExtensions)
|
|
49
59
|
response = self.class.post("/session/create", {
|
|
50
60
|
:body => opts.camelize_keys!,
|
|
51
|
-
:headers => generate_headers
|
|
61
|
+
:headers => generate_headers("Content-Type" => "application/x-www-form-urlencoded")
|
|
52
62
|
})
|
|
53
63
|
case response.code
|
|
54
64
|
when (200..300)
|
|
@@ -411,6 +421,30 @@ module OpenTok
|
|
|
411
421
|
|
|
412
422
|
# Connections methods
|
|
413
423
|
|
|
424
|
+
def list_connections(session_id, offset, count)
|
|
425
|
+
query = Hash.new
|
|
426
|
+
query[:offset] = offset unless offset.nil?
|
|
427
|
+
query[:count] = count unless count.nil?
|
|
428
|
+
response = self.class.get("/v2/project/#{@api_key}/session/#{session_id}/connection", {
|
|
429
|
+
:query => query.empty? ? nil : query,
|
|
430
|
+
:headers => generate_headers
|
|
431
|
+
})
|
|
432
|
+
case response.code
|
|
433
|
+
when 200
|
|
434
|
+
response
|
|
435
|
+
when 400
|
|
436
|
+
raise ArgumentError, "Invalid request. This response may indicate that some parameter of your query is invalid."
|
|
437
|
+
when 403
|
|
438
|
+
raise OpenTokAuthenticationError, "Authentication failed while retrieving connections. API Key: #{@api_key}"
|
|
439
|
+
when 404
|
|
440
|
+
raise OpenTokConnectionError, "Either the OpenTok session could not be found, or no clients are actively connected to the session."
|
|
441
|
+
else
|
|
442
|
+
raise OpenTokConnectionError, "The connections could not be retrieved."
|
|
443
|
+
end
|
|
444
|
+
rescue StandardError => e
|
|
445
|
+
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
|
446
|
+
end
|
|
447
|
+
|
|
414
448
|
def forceDisconnect(session_id, connection_id)
|
|
415
449
|
response = self.class.delete("/v2/project/#{@api_key}/session/#{session_id}/connection/#{connection_id}", {
|
|
416
450
|
:headers => generate_headers("Content-Type" => "application/json")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "active_support/inflector"
|
|
2
|
+
|
|
3
|
+
module OpenTok
|
|
4
|
+
# Represents a connection in an OpenTok session.
|
|
5
|
+
#
|
|
6
|
+
# @attr [String] connection_id
|
|
7
|
+
# The ID of the connection.
|
|
8
|
+
#
|
|
9
|
+
# @attr [Integer] created_at
|
|
10
|
+
# The timestamp when the connection was created, expressed in milliseconds since the Unix epoch.
|
|
11
|
+
#
|
|
12
|
+
# @attr [String] connection_state
|
|
13
|
+
# The state of the connection.
|
|
14
|
+
#
|
|
15
|
+
class Connection
|
|
16
|
+
# @private
|
|
17
|
+
def initialize(interface, session_id, json)
|
|
18
|
+
@interface = interface
|
|
19
|
+
@session_id = session_id
|
|
20
|
+
# TODO: validate json fits schema
|
|
21
|
+
@json = json
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A JSON-encoded string representation of the connection.
|
|
25
|
+
def to_json
|
|
26
|
+
@json.to_json
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Forces the disconnection of this connection from the OpenTok session.
|
|
30
|
+
#
|
|
31
|
+
# A client must be actively connected to the OpenTok session for you to disconnect it.
|
|
32
|
+
def force_disconnect
|
|
33
|
+
@interface.forceDisconnect(@session_id, @json['connectionId'])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @private ignore
|
|
37
|
+
def method_missing(method, *args, &block)
|
|
38
|
+
camelized_method = method.to_s.camelize(:lower)
|
|
39
|
+
if @json.has_key? camelized_method and args.empty?
|
|
40
|
+
@json[camelized_method]
|
|
41
|
+
else
|
|
42
|
+
super method, *args, &block
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "opentok/connection"
|
|
2
|
+
|
|
3
|
+
module OpenTok
|
|
4
|
+
# A class for accessing an array of Connection objects.
|
|
5
|
+
class ConnectionList < Array
|
|
6
|
+
|
|
7
|
+
# `total`: The total number of connections.
|
|
8
|
+
# `session_id`: The session ID of the session these connections belong to.
|
|
9
|
+
attr_reader :total, :session_id
|
|
10
|
+
|
|
11
|
+
# @private
|
|
12
|
+
def initialize(interface, json)
|
|
13
|
+
@total = json['count']
|
|
14
|
+
@session_id = json['sessionId']
|
|
15
|
+
super json['items'].map { |item| Connection.new interface, session_id, item }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/opentok/connections.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
require "opentok/client"
|
|
2
|
+
require "opentok/connection"
|
|
3
|
+
require "opentok/connection_list"
|
|
4
|
+
|
|
1
5
|
module OpenTok
|
|
2
6
|
# A class for working with OpenTok connections.
|
|
3
7
|
class Connections
|
|
@@ -6,6 +10,23 @@ module OpenTok
|
|
|
6
10
|
@client = client
|
|
7
11
|
end
|
|
8
12
|
|
|
13
|
+
# Returns a ConnectionList, which is an array of connections that are active in a session,
|
|
14
|
+
# for your API key.
|
|
15
|
+
#
|
|
16
|
+
# @param [String] session_id The session ID of the OpenTok session.
|
|
17
|
+
# @param [Hash] options A hash with keys defining which range of connections to retrieve.
|
|
18
|
+
# @option options [integer] :offset Optional. The index offset of the first connection. If you do not specify an offset, 0 is used.
|
|
19
|
+
# @option options [integer] :count Optional. The number of connections to be returned. The maximum
|
|
20
|
+
# number of connections returned is 1000. If you do not specify a count, 50 is used.
|
|
21
|
+
#
|
|
22
|
+
# @return [ConnectionList] A ConnectionList object, which is an array of Connection objects.
|
|
23
|
+
def list(session_id, options = {})
|
|
24
|
+
raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
|
|
25
|
+
raise ArgumentError, "count must be between 1 and 1000" if options[:count] && (options[:count] < 1 || options[:count] > 1000)
|
|
26
|
+
connections_list_json = @client.list_connections(session_id, options[:offset], options[:count])
|
|
27
|
+
ConnectionList.new self, connections_list_json
|
|
28
|
+
end
|
|
29
|
+
|
|
9
30
|
# Force a client to disconnect from an OpenTok session.
|
|
10
31
|
#
|
|
11
32
|
# A client must be actively connected to the OpenTok session for you to disconnect it.
|
|
@@ -17,7 +38,7 @@ module OpenTok
|
|
|
17
38
|
# @raise [OpenTokAuthenticationError] You are not authorized to disconnect the connection. Check your authentication credentials.
|
|
18
39
|
# @raise [OpenTokConnectionError] The client specified by the connection_id property is not connected to the session.
|
|
19
40
|
#
|
|
20
|
-
def forceDisconnect(session_id, connection_id
|
|
41
|
+
def forceDisconnect(session_id, connection_id)
|
|
21
42
|
raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
|
|
22
43
|
raise ArgumentError, "connection_id not provided" if connection_id.to_s.empty?
|
|
23
44
|
response = @client.forceDisconnect(session_id, connection_id)
|
data/lib/opentok/constants.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module OpenTok
|
|
2
2
|
require "set"
|
|
3
3
|
API_URL = "https://api.opentok.com"
|
|
4
|
+
VONAGE_API_URL = "https://video.api.vonage.com"
|
|
4
5
|
TOKEN_SENTINEL = "T1=="
|
|
5
6
|
ROLES = { subscriber: "subscriber", publisher: "publisher", moderator: "moderator", publisheronly: "publisheronly" }
|
|
6
7
|
ARCHIVE_MODES = ::Set.new([:manual, :always])
|
data/lib/opentok/opentok.rb
CHANGED
|
@@ -87,8 +87,9 @@ module OpenTok
|
|
|
87
87
|
@api_key = api_key.to_s()
|
|
88
88
|
@api_secret = api_secret
|
|
89
89
|
@timeout_length = opts[:timeout_length] || 2
|
|
90
|
-
@api_url = opts
|
|
90
|
+
@api_url = set_api_url(opts)
|
|
91
91
|
@ua_addendum = opts[:ua_addendum]
|
|
92
|
+
@use_vonage_endpoints = opts[:use_vonage_endpoints] == true ? true : false
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
# Creates a new OpenTok session and returns the session ID, which uniquely identifies
|
|
@@ -203,6 +204,7 @@ module OpenTok
|
|
|
203
204
|
end
|
|
204
205
|
|
|
205
206
|
response = client.create_session(params)
|
|
207
|
+
opts[:use_vonage_endpoints] = @use_vonage_endpoints
|
|
206
208
|
Session.new api_key, api_secret, response['sessions']['Session']['session_id'], opts
|
|
207
209
|
end
|
|
208
210
|
|
|
@@ -253,8 +255,18 @@ module OpenTok
|
|
|
253
255
|
|
|
254
256
|
protected
|
|
255
257
|
def client
|
|
256
|
-
@client ||= Client.new api_key, api_secret, api_url, ua_addendum, timeout_length: @timeout_length
|
|
258
|
+
@client ||= Client.new api_key, api_secret, api_url, ua_addendum, timeout_length: @timeout_length, use_vonage_endpoints: @use_vonage_endpoints
|
|
257
259
|
end
|
|
258
260
|
|
|
261
|
+
private
|
|
262
|
+
def set_api_url(opts)
|
|
263
|
+
if opts[:api_url]
|
|
264
|
+
opts[:api_url]
|
|
265
|
+
elsif opts[:use_vonage_endpoints] == true
|
|
266
|
+
VONAGE_API_URL
|
|
267
|
+
else
|
|
268
|
+
API_URL
|
|
269
|
+
end
|
|
270
|
+
end
|
|
259
271
|
end
|
|
260
272
|
end
|
data/lib/opentok/session.rb
CHANGED
|
@@ -87,6 +87,7 @@ module OpenTok
|
|
|
87
87
|
@archive_name = opts.fetch(:archive_name, '') if archive_mode == :always
|
|
88
88
|
@archive_resolution = opts.fetch(:archive_resolution, "640x480") if archive_mode == :always
|
|
89
89
|
@e2ee = opts.fetch(:e2ee, :false)
|
|
90
|
+
@use_vonage_endpoints = opts[:use_vonage_endpoints] == true ? true : false
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
# @private
|
|
@@ -6,12 +6,12 @@ require "addressable/uri"
|
|
|
6
6
|
require "openssl"
|
|
7
7
|
require "active_support"
|
|
8
8
|
require "active_support/time"
|
|
9
|
-
require "jwt"
|
|
9
|
+
require "vonage-jwt"
|
|
10
10
|
|
|
11
11
|
module OpenTok
|
|
12
12
|
# @private
|
|
13
13
|
module TokenGenerator
|
|
14
|
-
VALID_TOKEN_TYPES = ['T1', 'JWT'].freeze
|
|
14
|
+
VALID_TOKEN_TYPES = ['T1', 'JWT', 'VONAGE'].freeze
|
|
15
15
|
|
|
16
16
|
# this works when using include TokenGenerator
|
|
17
17
|
def self.included(base)
|
|
@@ -30,7 +30,6 @@ module OpenTok
|
|
|
30
30
|
def generates_tokens(arg_lambdas={})
|
|
31
31
|
@arg_lambdas = arg_lambdas
|
|
32
32
|
define_method(:generate_token) do |*args|
|
|
33
|
-
# puts "generate_something is being called on #{self}. set up with #{method_opts.inspect}"
|
|
34
33
|
dynamic_args = [ :api_key, :api_secret, :session_id, :token_opts ].map do |arg|
|
|
35
34
|
self.class.arg_lambdas[arg].call(self) if self.class.arg_lambdas[arg]
|
|
36
35
|
end
|
|
@@ -38,6 +37,8 @@ module OpenTok
|
|
|
38
37
|
args = args.first(4-dynamic_args.length)
|
|
39
38
|
token_type = if args.any? && args.last.is_a?(Hash) && args.last.has_key?(:token_type)
|
|
40
39
|
args.last[:token_type].upcase
|
|
40
|
+
elsif @use_vonage_endpoints == true
|
|
41
|
+
"VONAGE"
|
|
41
42
|
else
|
|
42
43
|
"JWT"
|
|
43
44
|
end
|
|
@@ -54,9 +55,15 @@ module OpenTok
|
|
|
54
55
|
|
|
55
56
|
# Generates a token
|
|
56
57
|
def generate_token(token_type)
|
|
57
|
-
token_type
|
|
58
|
+
case token_type
|
|
59
|
+
when 'T1'
|
|
60
|
+
TokenGenerator::GENERATE_T1_TOKEN_LAMBDA
|
|
61
|
+
when 'JWT'
|
|
62
|
+
TokenGenerator::GENERATE_JWT_LAMBDA
|
|
63
|
+
when 'VONAGE'
|
|
64
|
+
TokenGenerator::GENERATE_VONAGE_TOKEN_LAMBDA
|
|
65
|
+
end
|
|
58
66
|
end
|
|
59
|
-
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
# @private TODO: this probably doesn't need to be a constant anyone can read
|
|
@@ -158,6 +165,36 @@ module OpenTok
|
|
|
158
165
|
JWT.encode(data_params, api_secret, 'HS256', header_fields={typ: 'JWT'})
|
|
159
166
|
end
|
|
160
167
|
|
|
168
|
+
GENERATE_VONAGE_TOKEN_LAMBDA = ->(api_key, api_secret, session_id, opts = {}) do
|
|
169
|
+
# normalize required data params
|
|
170
|
+
role = opts.fetch(:role, :publisher)
|
|
171
|
+
unless ROLES.has_key? role
|
|
172
|
+
raise "'#{role}' is not a recognized role"
|
|
173
|
+
end
|
|
174
|
+
unless Session.belongs_to_api_key? session_id.to_s, api_key
|
|
175
|
+
raise "Cannot generate token for a session_id that doesn't belong to api_key: #{api_key}"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
claims = {
|
|
179
|
+
application_id: api_key,
|
|
180
|
+
scope: 'session.connect',
|
|
181
|
+
session_id: session_id,
|
|
182
|
+
role: role,
|
|
183
|
+
initial_layout_class_list: '',
|
|
184
|
+
sub: 'video',
|
|
185
|
+
acl: {
|
|
186
|
+
paths: {'/session/**' => {}}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
claims[:data] = opts[:data] if opts[:data]
|
|
191
|
+
claims[:initial_layout_class_list] = opts[:initial_layout_class_list].join(' ') if opts[:initial_layout_class_list]
|
|
192
|
+
claims[:exp] = opts[:expire_time].to_i if opts[:expire_time]
|
|
193
|
+
|
|
194
|
+
claims[:private_key] = api_secret
|
|
195
|
+
Vonage::JWTBuilder.new(claims).jwt.generate
|
|
196
|
+
end
|
|
197
|
+
|
|
161
198
|
# this works when using extend TokenGenerator
|
|
162
199
|
# def generates_tokens(method_opts)
|
|
163
200
|
# puts "I'm being called on #{self} with argument #{method_opts.inspect}"
|
data/lib/opentok/version.rb
CHANGED
data/lib/opentok/websocket.rb
CHANGED
|
@@ -27,6 +27,8 @@ module OpenTok
|
|
|
27
27
|
# @option opts [Hash] :headers (optional) A hash of key-value pairs of headers to be sent to your WebSocket server with each message,
|
|
28
28
|
# with a maximum length of 512 bytes.
|
|
29
29
|
# @option opts [Boolean] :bidirectional (optional) Whether the WebSocket connection should be bidirectional.
|
|
30
|
+
# @option opts [Integer] :audio_rate (optional) A number representing the audio sampling rate in Hz for the WebSocket stream.
|
|
31
|
+
# - Must be one of: 8000, 16000, 24000
|
|
30
32
|
def connect(session_id, token, websocket_uri, opts = {})
|
|
31
33
|
response = @client.connect_websocket(session_id, token, websocket_uri, opts)
|
|
32
34
|
end
|
data/opentok.gemspec
CHANGED
|
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.add_dependency "addressable", "~> 2.3" # 2.3.0 <= version < 3.0.0
|
|
31
31
|
spec.add_dependency "httparty", ">= 0.18.0"
|
|
32
32
|
spec.add_dependency "activesupport", ">= 2.0"
|
|
33
|
-
spec.add_dependency "jwt", "
|
|
33
|
+
spec.add_dependency "vonage-jwt", "~> 0.2.0"
|
|
34
34
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/connection
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- OpenTok-Ruby-SDK/<%= version %>
|
|
12
|
+
X-Opentok-Auth:
|
|
13
|
+
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
Accept:
|
|
17
|
+
- "*/*"
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 19 May 2026 14:06:41 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
body:
|
|
34
|
+
encoding: UTF-8
|
|
35
|
+
string: |-
|
|
36
|
+
{
|
|
37
|
+
"count" : 5,
|
|
38
|
+
"projectId" : "123456",
|
|
39
|
+
"sessionId" : "2_MX40NzIwMzJ-flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN-MC45NDQ2MzE2NH4",
|
|
40
|
+
"items" : [{
|
|
41
|
+
"connectionId": "527775e1-626e-42c3-b0e8-e2122d20661a",
|
|
42
|
+
"createdAt": 1747655658197,
|
|
43
|
+
"connectionState": "Connected"
|
|
44
|
+
},{
|
|
45
|
+
"connectionId": "c6db93f0-8692-438c-944b-cfbaf577c878",
|
|
46
|
+
"createdAt": 1747655658227,
|
|
47
|
+
"connectionState": "Connected"
|
|
48
|
+
},{
|
|
49
|
+
"connectionId": "d95f6496-df6e-4f49-86d6-832e00303602",
|
|
50
|
+
"createdAt": 1747655658258,
|
|
51
|
+
"connectionState": "Connected"
|
|
52
|
+
},{
|
|
53
|
+
"connectionId": "15d73844-d503-4656-afdd-3eb10c96f4dc",
|
|
54
|
+
"createdAt": 1747655658300,
|
|
55
|
+
"connectionState": "Connected"
|
|
56
|
+
},{
|
|
57
|
+
"connectionId": "6f2a13b1-8d59-40ba-9719-891498aba89e",
|
|
58
|
+
"createdAt": 1747655658400,
|
|
59
|
+
"connectionState": "Connected"
|
|
60
|
+
}]
|
|
61
|
+
}
|
|
62
|
+
recorded_at: Tue, 19 May 2026 14:06:41 GMT
|
|
63
|
+
recorded_with: VCR 6.3.1
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/connection?offset=2
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- OpenTok-Ruby-SDK/<%= version %>
|
|
12
|
+
X-Opentok-Auth:
|
|
13
|
+
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
Accept:
|
|
17
|
+
- "*/*"
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 19 May 2026 14:06:41 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
body:
|
|
34
|
+
encoding: UTF-8
|
|
35
|
+
string: |-
|
|
36
|
+
{
|
|
37
|
+
"count" : 3,
|
|
38
|
+
"projectId" : "123456",
|
|
39
|
+
"sessionId" : "2_MX40NzIwMzJ-flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN-MC45NDQ2MzE2NH4",
|
|
40
|
+
"items" : [{
|
|
41
|
+
"connectionId": "d95f6496-df6e-4f49-86d6-832e00303602",
|
|
42
|
+
"createdAt": 1747655658258,
|
|
43
|
+
"connectionState": "Connected"
|
|
44
|
+
},{
|
|
45
|
+
"connectionId": "15d73844-d503-4656-afdd-3eb10c96f4dc",
|
|
46
|
+
"createdAt": 1747655658300,
|
|
47
|
+
"connectionState": "Connected"
|
|
48
|
+
},{
|
|
49
|
+
"connectionId": "6f2a13b1-8d59-40ba-9719-891498aba89e",
|
|
50
|
+
"createdAt": 1747655658400,
|
|
51
|
+
"connectionState": "Connected"
|
|
52
|
+
}]
|
|
53
|
+
}
|
|
54
|
+
recorded_at: Tue, 19 May 2026 14:06:41 GMT
|
|
55
|
+
recorded_with: VCR 6.3.1
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/connection?count=2
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- OpenTok-Ruby-SDK/<%= version %>
|
|
12
|
+
X-Opentok-Auth:
|
|
13
|
+
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
Accept:
|
|
17
|
+
- "*/*"
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 19 May 2026 14:06:41 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
body:
|
|
34
|
+
encoding: UTF-8
|
|
35
|
+
string: |-
|
|
36
|
+
{
|
|
37
|
+
"count" : 2,
|
|
38
|
+
"projectId" : "123456",
|
|
39
|
+
"sessionId" : "2_MX40NzIwMzJ-flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN-MC45NDQ2MzE2NH4",
|
|
40
|
+
"items" : [{
|
|
41
|
+
"connectionId": "527775e1-626e-42c3-b0e8-e2122d20661a",
|
|
42
|
+
"createdAt": 1747655658197,
|
|
43
|
+
"connectionState": "Connected"
|
|
44
|
+
},{
|
|
45
|
+
"connectionId": "c6db93f0-8692-438c-944b-cfbaf577c878",
|
|
46
|
+
"createdAt": 1747655658227,
|
|
47
|
+
"connectionState": "Connected"
|
|
48
|
+
}]
|
|
49
|
+
}
|
|
50
|
+
recorded_at: Tue, 19 May 2026 14:06:41 GMT
|
|
51
|
+
recorded_with: VCR 6.3.1
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/connection?count=2&offset=1
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- OpenTok-Ruby-SDK/<%= version %>
|
|
12
|
+
X-Opentok-Auth:
|
|
13
|
+
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
Accept:
|
|
17
|
+
- "*/*"
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 19 May 2026 14:06:41 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
body:
|
|
34
|
+
encoding: UTF-8
|
|
35
|
+
string: |-
|
|
36
|
+
{
|
|
37
|
+
"count" : 2,
|
|
38
|
+
"projectId" : "123456",
|
|
39
|
+
"sessionId" : "2_MX40NzIwMzJ-flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN-MC45NDQ2MzE2NH4",
|
|
40
|
+
"items" : [{
|
|
41
|
+
"connectionId": "c6db93f0-8692-438c-944b-cfbaf577c878",
|
|
42
|
+
"createdAt": 1747655658227,
|
|
43
|
+
"connectionState": "Connected"
|
|
44
|
+
},{
|
|
45
|
+
"connectionId": "d95f6496-df6e-4f49-86d6-832e00303602",
|
|
46
|
+
"createdAt": 1747655658258,
|
|
47
|
+
"connectionState": "Connected"
|
|
48
|
+
}]
|
|
49
|
+
}
|
|
50
|
+
recorded_at: Tue, 19 May 2026 14:06:41 GMT
|
|
51
|
+
recorded_with: VCR 6.3.1
|
|
@@ -13,6 +13,7 @@ http_interactions:
|
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
15
|
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -11,8 +11,11 @@ http_interactions:
|
|
|
11
11
|
- OpenTok-Ruby-SDK/<%= version %>
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
|
-
Accept-Encoding:
|
|
15
|
-
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
Accept:
|
|
17
|
+
- "*/*"
|
|
18
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
19
|
response:
|
|
17
20
|
status:
|
|
18
21
|
code: 200
|
|
@@ -13,6 +13,7 @@ http_interactions:
|
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
15
|
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -12,7 +12,8 @@ http_interactions:
|
|
|
12
12
|
X-Opentok-Auth:
|
|
13
13
|
- eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
|
|
14
14
|
Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
|
15
|
-
Accept: "*/*"
|
|
15
|
+
Accept: "*/*"
|
|
16
|
+
Content-Type: "application/x-www-form-urlencoded"
|
|
16
17
|
response:
|
|
17
18
|
status:
|
|
18
19
|
code: 200
|
|
@@ -14,25 +14,73 @@ describe OpenTok::Connections do
|
|
|
14
14
|
let(:session_id) { "SESSIONID" }
|
|
15
15
|
let(:connection_id) { "CONNID" }
|
|
16
16
|
let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
|
|
17
|
-
let(:
|
|
17
|
+
let(:connections) { opentok.connections }
|
|
18
18
|
|
|
19
|
-
subject {
|
|
19
|
+
subject { connections }
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
it '
|
|
22
|
+
it 'raises an error on nil session_id when attempting to force disconnect' do
|
|
23
23
|
expect {
|
|
24
|
-
|
|
24
|
+
connections.forceDisconnect(nil,connection_id)
|
|
25
25
|
}.to raise_error(ArgumentError)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
it '
|
|
28
|
+
it 'raises an error on nil connection_id when attempting to force disconnect' do
|
|
29
29
|
expect {
|
|
30
|
-
|
|
30
|
+
connections.forceDisconnect(session_id,nil)
|
|
31
31
|
}.to raise_error(ArgumentError)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "forces a connection to be terminated", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
|
|
35
|
-
response =
|
|
35
|
+
response = connections.forceDisconnect(session_id, connection_id)
|
|
36
36
|
expect(response).not_to be_nil
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
context "when attempting to list connections" do
|
|
40
|
+
it 'raises an error on nil session_id' do
|
|
41
|
+
expect {
|
|
42
|
+
connections.list(nil)
|
|
43
|
+
}.to raise_error(ArgumentError)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'raises an error with count too low' do
|
|
47
|
+
expect {
|
|
48
|
+
connections.list(session_id, :count => 0)
|
|
49
|
+
}.to raise_error(ArgumentError)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'raises an error with count too high' do
|
|
53
|
+
expect {
|
|
54
|
+
connections.list(session_id, :count => 1001)
|
|
55
|
+
}.to raise_error(ArgumentError)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should return all connections", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
|
|
59
|
+
connections_list = connections.list(session_id)
|
|
60
|
+
expect(connections_list).to be_an_instance_of OpenTok::ConnectionList
|
|
61
|
+
expect(connections_list.total).to eq 5
|
|
62
|
+
expect(connections_list.count).to eq 5
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should return connections with an offset", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
|
|
66
|
+
connections_list = connections.list(session_id, :offset => 2)
|
|
67
|
+
expect(connections_list).to be_an_instance_of OpenTok::ConnectionList
|
|
68
|
+
expect(connections_list.total).to eq 3
|
|
69
|
+
expect(connections_list.count).to eq 3
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should return count number of connections", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
|
|
73
|
+
connections_list = connections.list(session_id, :count => 2)
|
|
74
|
+
expect(connections_list).to be_an_instance_of OpenTok::ConnectionList
|
|
75
|
+
expect(connections_list.total).to eq 2
|
|
76
|
+
expect(connections_list.count).to eq 2
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should return part of the connections when using offset and count", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
|
|
80
|
+
connections_list = connections.list(session_id, :offset => 1, :count => 2)
|
|
81
|
+
expect(connections_list).to be_an_instance_of OpenTok::ConnectionList
|
|
82
|
+
expect(connections_list.total).to eq 2
|
|
83
|
+
expect(connections_list.count).to eq 2
|
|
84
|
+
end
|
|
85
|
+
end
|
|
38
86
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentok
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stijn Mathysen
|
|
@@ -9,10 +9,9 @@ authors:
|
|
|
9
9
|
- Song Zheng
|
|
10
10
|
- Patrick Quinn-Graham
|
|
11
11
|
- Ankur Oberoi
|
|
12
|
-
autorequire:
|
|
13
12
|
bindir: bin
|
|
14
13
|
cert_chain: []
|
|
15
|
-
date:
|
|
14
|
+
date: 2026-07-02 00:00:00.000000000 Z
|
|
16
15
|
dependencies:
|
|
17
16
|
- !ruby/object:Gem::Dependency
|
|
18
17
|
name: bundler
|
|
@@ -141,19 +140,19 @@ dependencies:
|
|
|
141
140
|
- !ruby/object:Gem::Version
|
|
142
141
|
version: '2.0'
|
|
143
142
|
- !ruby/object:Gem::Dependency
|
|
144
|
-
name: jwt
|
|
143
|
+
name: vonage-jwt
|
|
145
144
|
requirement: !ruby/object:Gem::Requirement
|
|
146
145
|
requirements:
|
|
147
|
-
- - "
|
|
146
|
+
- - "~>"
|
|
148
147
|
- !ruby/object:Gem::Version
|
|
149
|
-
version:
|
|
148
|
+
version: 0.2.0
|
|
150
149
|
type: :runtime
|
|
151
150
|
prerelease: false
|
|
152
151
|
version_requirements: !ruby/object:Gem::Requirement
|
|
153
152
|
requirements:
|
|
154
|
-
- - "
|
|
153
|
+
- - "~>"
|
|
155
154
|
- !ruby/object:Gem::Version
|
|
156
|
-
version:
|
|
155
|
+
version: 0.2.0
|
|
157
156
|
description: OpenTok is an API from TokBox that enables websites to weave live group
|
|
158
157
|
video communication into their online experience. With OpenTok you have the freedom
|
|
159
158
|
and flexibility to create the most engaging web experience for your users. This
|
|
@@ -191,6 +190,8 @@ files:
|
|
|
191
190
|
- lib/opentok/broadcasts.rb
|
|
192
191
|
- lib/opentok/captions.rb
|
|
193
192
|
- lib/opentok/client.rb
|
|
193
|
+
- lib/opentok/connection.rb
|
|
194
|
+
- lib/opentok/connection_list.rb
|
|
194
195
|
- lib/opentok/connections.rb
|
|
195
196
|
- lib/opentok/constants.rb
|
|
196
197
|
- lib/opentok/exceptions.rb
|
|
@@ -288,6 +289,10 @@ files:
|
|
|
288
289
|
- spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_starting_captions_with_options.yml
|
|
289
290
|
- spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_stopping_captions.yml
|
|
290
291
|
- spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml
|
|
292
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_all_connections.yml
|
|
293
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_connections_with_an_offset.yml
|
|
294
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_count_number_of_connections.yml
|
|
295
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_part_of_the_connections_when_using_offset_and_count.yml
|
|
291
296
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml
|
|
292
297
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml
|
|
293
298
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml
|
|
@@ -343,7 +348,6 @@ licenses:
|
|
|
343
348
|
- MIT
|
|
344
349
|
metadata:
|
|
345
350
|
source_code_uri: https://github.com/opentok/OpenTok-Ruby-SDK
|
|
346
|
-
post_install_message:
|
|
347
351
|
rdoc_options: []
|
|
348
352
|
require_paths:
|
|
349
353
|
- lib
|
|
@@ -358,8 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
358
362
|
- !ruby/object:Gem::Version
|
|
359
363
|
version: '0'
|
|
360
364
|
requirements: []
|
|
361
|
-
rubygems_version: 3.
|
|
362
|
-
signing_key:
|
|
365
|
+
rubygems_version: 3.6.2
|
|
363
366
|
specification_version: 4
|
|
364
367
|
summary: Ruby gem for the OpenTok API
|
|
365
368
|
test_files:
|
|
@@ -412,6 +415,10 @@ test_files:
|
|
|
412
415
|
- spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_starting_captions_with_options.yml
|
|
413
416
|
- spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_stopping_captions.yml
|
|
414
417
|
- spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml
|
|
418
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_all_connections.yml
|
|
419
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_connections_with_an_offset.yml
|
|
420
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_count_number_of_connections.yml
|
|
421
|
+
- spec/cassettes/OpenTok_Connections/when_attempting_to_list_connections/should_return_part_of_the_connections_when_using_offset_and_count.yml
|
|
415
422
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml
|
|
416
423
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml
|
|
417
424
|
- spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml
|