Skip to content

Commit bad4a19

Browse files
authored
Merge pull request #265 from opentok/dev
Version 4.7.0
2 parents bd5a5b2 + 5913718 commit bad4a19

10 files changed

+304
-8
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 4.7.0
2+
3+
* Adds support for the End-to-end encryption (E2EE) feature [#259](https://github.com/opentok/OpenTok-Ruby-SDK/pull/259)
4+
* Implements Auto-archive improvements [#262](https://github.com/opentok/OpenTok-Ruby-SDK/pull/262)
5+
* Updates the README to explain appending a custom value to the `UserAgent` header [#263](https://github.com/opentok/OpenTok-Ruby-SDK/pull/263)
6+
17
# 4.6.0
28

39
* Adds functionality for working with the Audio Connector feature [#247](https://github.com/opentok/OpenTok-Ruby-SDK/pull/247)

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ opentok = OpenTok::OpenTok.new api_key, api_secret
5959

6060
#### Initialization Options
6161

62+
**Custom Timeout**
63+
6264
You can specify a custom timeout value for HTTP requests when initializing a new `OpenTok::OpenTok`
6365
object:
6466

@@ -71,6 +73,23 @@ opentok = OpenTok::OpenTok.new api_key, api_secret, :timeout_length => 10
7173
The value for `:timeout_length` is an integer representing the number of seconds to wait for an HTTP
7274
request to complete. The default is set to 2 seconds.
7375

76+
**UA Addendum**
77+
78+
You can also append a custom string to the `User-Agent` header value for HTTP requests when initializing a new `OpenTok::OpenTok`
79+
object:
80+
81+
```ruby
82+
require "opentok"
83+
84+
opentok = OpenTok::OpenTok.new api_key, api_secret, :ua_addendum => 'FOO'
85+
```
86+
87+
The above would generate a `User-Agent` header something like this:
88+
89+
```
90+
User-Agent: OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.1.2-p20 FOO
91+
```
92+
7493
### Creating Sessions
7594

7695
To create an OpenTok Session, use the `OpenTok#create_session(properties)` method.
@@ -101,6 +120,9 @@ session = opentok.create_session :location => '12.34.56.78'
101120
# A session with automatic archiving (must use the routed media mode):
102121
session = opentok.create_session :archive_mode => :always, :media_mode => :routed
103122

123+
# A session with end-to-end encryption (must use the routed media mode):
124+
session = opentok.create_session :e2ee => true, :media_mode => :routed
125+
104126
# Store this sessionId in the database for later use:
105127
session_id = session.session_id
106128
```

lib/opentok/opentok.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,26 @@ def initialize(api_key, api_secret, opts={})
144144
# automatically (<code>:always</code>) or not (<code>:manual</code>). When using automatic
145145
# archiving, the session must use the <code>:routed</code> media mode.
146146
#
147+
# @option opts [Symbol] :archive_name The name to use for archives in auto-archived sessions.
148+
# When setting this option, the :archive_mode option must be set to :always or an error will result.
149+
# The length of the archive name can be up to 80 chars.
150+
# Due to encoding limitations the following special characters are translated to a colon (:) character: ~, -, _.
151+
# If you do not set a name and the archiveMode option is set to always, the archive name will be empty.
152+
#
153+
# @option opts [Symbol] :archive_resolution The resolution of archives in an auto-archived session.
154+
# Valid values are "480x640", "640x480" (the default), "720x1280", "1280x720", "1080x1920", and "1920x1080".
155+
# When setting this option, the :archive_mode option must be set to :always or an error will result.
156+
#
157+
# @option opts [true, false] :e2ee
158+
# (Boolean, optional) — Whether the session uses end-to-end encryption from client to client (default: false).
159+
# This should not be set to `true` if `:media_mode` is `:relayed`.
160+
# See the {https://tokbox.com/developer/guides/end-to-end-encryption/ documentation} for more information.
161+
#
147162
# @return [Session] The Session object. The session_id property of the object is the session ID.
148163
def create_session(opts={})
149164

150165
# normalize opts so all keys are symbols and only include valid_opts
151-
valid_opts = [ :media_mode, :location, :archive_mode ]
166+
valid_opts = [ :media_mode, :location, :archive_mode, :archive_name, :archive_resolution, :e2ee ]
152167
opts = opts.inject({}) do |m,(k,v)|
153168
if valid_opts.include? k.to_sym
154169
m[k.to_sym] = v
@@ -159,6 +174,13 @@ def create_session(opts={})
159174
# keep opts around for Session constructor, build REST params
160175
params = opts.clone
161176

177+
# validate input combinations
178+
raise ArgumentError, "A session with always archive mode must also have the routed media mode." if (params[:archive_mode] == :always && params[:media_mode] == :relayed)
179+
180+
raise ArgumentError, "A session with relayed media mode should not have e2ee set to true." if (params[:media_mode] == :relayed && params[:e2ee] == true)
181+
182+
raise ArgumentError, "A session with always archive mode must not have e2ee set to true." if (params[:archive_mode] == :always && params[:e2ee] == true)
183+
162184
# anything other than :relayed sets the REST param to "disabled", in which case we force
163185
# opts to be :routed. if we were more strict we could raise an error when the value isn't
164186
# either :relayed or :routed
@@ -175,10 +197,9 @@ def create_session(opts={})
175197
# archive mode is optional, but it has to be one of the valid values if present
176198
unless params[:archive_mode].nil?
177199
raise "archive mode must be either always or manual" unless ARCHIVE_MODES.include? params[:archive_mode].to_sym
200+
raise ArgumentError, "archive name and/or archive resolution must not be set if archive mode is manual" if params[:archive_mode] == :manual && (params[:archive_name] || params[:archive_resolution])
178201
end
179202

180-
raise "A session with always archive mode must also have the routed media mode." if (params[:archive_mode] == :always && params[:media_mode] == :relayed)
181-
182203
response = client.create_session(params)
183204
Session.new api_key, api_secret, response['sessions']['Session']['session_id'], opts
184205
end

lib/opentok/session.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module OpenTok
2020
# @attr_reader [String] archive_mode Whether the session will be archived automatically
2121
# (<code>:always</code>) or not (<code>:manual</code>).
2222
#
23+
# @attr_reader [String] archive_name The name to use for archives in auto-archived sessions.
24+
#
25+
# @attr_reader [String] :archive_resolution The resolution of archives in an auto-archived session.
26+
#
2327
# @!method generate_token(options)
2428
# Generates a token.
2529
#
@@ -57,7 +61,7 @@ class Session
5761
:session_id => ->(instance) { instance.session_id }
5862
})
5963

60-
attr_reader :session_id, :media_mode, :location, :archive_mode, :api_key, :api_secret
64+
attr_reader :session_id, :media_mode, :location, :archive_mode, :archive_name, :archive_resolution, :e2ee, :api_key, :api_secret
6165

6266
# @private
6367
# this implementation doesn't completely understand the format of a Session ID
@@ -73,7 +77,12 @@ def self.belongs_to_api_key?(session_id, api_key)
7377
# @private
7478
def initialize(api_key, api_secret, session_id, opts={})
7579
@api_key, @api_secret, @session_id = api_key, api_secret, session_id
76-
@media_mode, @location, @archive_mode = opts.fetch(:media_mode, :relayed), opts[:location], opts.fetch(:archive_mode, :manual)
80+
@media_mode = opts.fetch(:media_mode, :relayed)
81+
@location = opts[:location]
82+
@archive_mode = opts.fetch(:archive_mode, :manual)
83+
@archive_name = opts.fetch(:archive_name, '') if archive_mode == :always
84+
@archive_resolution = opts.fetch(:archive_resolution, "640x480") if archive_mode == :always
85+
@e2ee = opts.fetch(:e2ee, :false)
7786
end
7887

7988
# @private

lib/opentok/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module OpenTok
22
# @private
3-
VERSION = '4.6.0'
3+
VERSION = '4.7.0'
44
end

spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)