Skip to content

Commit 3282b82

Browse files
authored
Merge pull request #262 from opentok/devx-6817-auto-archive-improvements
DEVX-6817: Auto Archive Improvements
2 parents c43b8ac + 44826b5 commit 3282b82

File tree

6 files changed

+193
-8
lines changed

6 files changed

+193
-8
lines changed

lib/opentok/opentok.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ 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+
#
147157
# @option opts [true, false] :e2ee
148158
# (Boolean, optional) — Whether the session uses end-to-end encryption from client to client (default: false).
149159
# This should not be set to `true` if `:media_mode` is `:relayed`.
@@ -153,7 +163,7 @@ def initialize(api_key, api_secret, opts={})
153163
def create_session(opts={})
154164

155165
# normalize opts so all keys are symbols and only include valid_opts
156-
valid_opts = [ :media_mode, :location, :archive_mode, :e2ee ]
166+
valid_opts = [ :media_mode, :location, :archive_mode, :archive_name, :archive_resolution, :e2ee ]
157167
opts = opts.inject({}) do |m,(k,v)|
158168
if valid_opts.include? k.to_sym
159169
m[k.to_sym] = v
@@ -187,6 +197,7 @@ def create_session(opts={})
187197
# archive mode is optional, but it has to be one of the valid values if present
188198
unless params[:archive_mode].nil?
189199
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])
190201
end
191202

192203
response = client.create_session(params)

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, :e2ee, :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, @e2ee = opts.fetch(:media_mode, :relayed), opts[:location], opts.fetch(:archive_mode, :manual), opts.fetch(:e2ee, :false)
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

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/opentok/opentok_spec.rb

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@
106106
expect(session.location).to eq nil
107107
end
108108

109+
it "creates always archived sessions with a set archive name", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
110+
session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_name => 'foo'
111+
expect(session).to be_an_instance_of OpenTok::Session
112+
expect(session.session_id).to be_an_instance_of String
113+
expect(session.archive_mode).to eq :always
114+
expect(session.archive_name).to eq 'foo'
115+
expect(session.location).to eq nil
116+
end
117+
118+
it "creates always archived sessions with a set archive resolution", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
119+
session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_resolution => "720x1280"
120+
expect(session).to be_an_instance_of OpenTok::Session
121+
expect(session.session_id).to be_an_instance_of String
122+
expect(session.archive_mode).to eq :always
123+
expect(session.archive_resolution).to eq "720x1280"
124+
expect(session.location).to eq nil
125+
end
126+
127+
it "creates always archived sessions with a set archive name and resolution", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
128+
session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_name => 'foo', :archive_resolution => "720x1280"
129+
expect(session).to be_an_instance_of OpenTok::Session
130+
expect(session.session_id).to be_an_instance_of String
131+
expect(session.archive_mode).to eq :always
132+
expect(session.archive_name).to eq 'foo'
133+
expect(session.archive_resolution).to eq "720x1280"
134+
expect(session.location).to eq nil
135+
end
136+
109137
it "creates e2ee sessions", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
110138
session = opentok.create_session :media_mode => :routed, :e2ee => :true
111139
expect(session).to be_an_instance_of OpenTok::Session
@@ -114,11 +142,6 @@
114142
expect(session.location).to eq nil
115143
end
116144

117-
# context "with relayed media mode and always archive mode" do
118-
# subject { -> { session = opentok.create_session :archive_mode => :always, :media_mode => :relayed }}
119-
# it { should raise_error }
120-
# end
121-
122145
context "with relayed media mode and always archive mode" do
123146
it "raises an error" do
124147
expect {
@@ -127,6 +150,22 @@
127150
end
128151
end
129152

153+
context "with archive name set and manual archive mode" do
154+
it "raises an error" do
155+
expect {
156+
opentok.create_session :archive_mode => :manual, :archive_name => 'foo'
157+
}.to raise_error ArgumentError
158+
end
159+
end
160+
161+
context "with archive resolution set and manual archive mode" do
162+
it "raises an error" do
163+
expect {
164+
opentok.create_session :archive_mode => :manual, :archive_resolution => "720x1280"
165+
}.to raise_error ArgumentError
166+
end
167+
end
168+
130169
context "with relayed media mode and e2ee set to true" do
131170
it "raises an error" do
132171
expect {

0 commit comments

Comments
 (0)