From f25b47ed2f252b6056fa6d5919ff9a5cf3098ca8 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 20 Feb 2023 16:35:06 +0000 Subject: [PATCH 01/13] Initial implementation for E2EE support --- lib/opentok/opentok.rb | 2 +- lib/opentok/session.rb | 4 +- .../_create_session/creates_e2ee_sessions.yml | 40 +++++++++++++++++++ spec/opentok/opentok_spec.rb | 9 +++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index 5fe26ed5..deeae04c 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -148,7 +148,7 @@ def initialize(api_key, api_secret, opts={}) def create_session(opts={}) # normalize opts so all keys are symbols and only include valid_opts - valid_opts = [ :media_mode, :location, :archive_mode ] + valid_opts = [ :media_mode, :location, :archive_mode, :e2ee ] opts = opts.inject({}) do |m,(k,v)| if valid_opts.include? k.to_sym m[k.to_sym] = v diff --git a/lib/opentok/session.rb b/lib/opentok/session.rb index ccbcd0f7..82e84fa1 100644 --- a/lib/opentok/session.rb +++ b/lib/opentok/session.rb @@ -57,7 +57,7 @@ class Session :session_id => ->(instance) { instance.session_id } }) - attr_reader :session_id, :media_mode, :location, :archive_mode, :api_key, :api_secret + attr_reader :session_id, :media_mode, :location, :archive_mode, :e2ee, :api_key, :api_secret # @private # this implementation doesn't completely understand the format of a Session ID @@ -73,7 +73,7 @@ def self.belongs_to_api_key?(session_id, api_key) # @private def initialize(api_key, api_secret, session_id, opts={}) @api_key, @api_secret, @session_id = api_key, api_secret, session_id - @media_mode, @location, @archive_mode = opts.fetch(:media_mode, :relayed), opts[:location], opts.fetch(:archive_mode, :manual) + @media_mode, @location, @archive_mode, @e2ee = opts.fetch(:media_mode, :relayed), opts[:location], opts.fetch(:archive_mode, :manual), opts.fetch(:e2ee, :false) end # @private diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml new file mode 100644 index 00000000..3bcd7c20 --- /dev/null +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_e2ee_sessions.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/session/create + body: + encoding: UTF-8 + string: e2ee=true&p2p.preference=disabled + headers: + User-Agent: + - OpenTok-Ruby-SDK/<%= version %> + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" + Accept: "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 18 Apr 2023 16:17:40 GMT + Content-Type: + - text/xml + Connection: + - keep-alive + Access-Control-Allow-Origin: + - '*' + X-Tb-Host: + - mantis503-nyc.tokbox.com + Content-Length: + - '304' + body: + encoding: UTF-8 + string: 1_MX4xMjM0NTZ-MTIuMzQuNTYuNzh-TW9uIE1hciAxNyAwMTo0ODo1NSBQRFQgMjAxNH4wLjM0MTM0MzE0MDIyOTU4Mjh-123456Tue + Apr 18 08:17:40 PDT 2023 + recorded_at: Tue, 18 Apr 2023 16:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/opentok/opentok_spec.rb b/spec/opentok/opentok_spec.rb index 11942912..ce04cb5d 100644 --- a/spec/opentok/opentok_spec.rb +++ b/spec/opentok/opentok_spec.rb @@ -97,6 +97,7 @@ expect(session.media_mode).to eq :relayed expect(session.location).to eq nil end + it "creates always archived sessions", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do session = opentok.create_session :media_mode => :routed, :archive_mode => :always expect(session).to be_an_instance_of OpenTok::Session @@ -105,6 +106,14 @@ expect(session.location).to eq nil end + it "creates e2ee sessions", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + session = opentok.create_session :media_mode => :routed, :e2ee => :true + expect(session).to be_an_instance_of OpenTok::Session + expect(session.session_id).to be_an_instance_of String + expect(session.e2ee).to eq :true + expect(session.location).to eq nil + end + context "with relayed media mode and always archive mode" do subject { -> { session = opentok.create_session :archive_mode => :always, :media_mode => :relayed }} it { should raise_error } From 65d07e38363b374f14371104f133241b01389d28 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 3 Mar 2023 13:25:07 +0000 Subject: [PATCH 02/13] Adding input validations for e2ee session creation --- lib/opentok/opentok.rb | 9 +++++++-- spec/opentok/opentok_spec.rb | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index deeae04c..f34be59a 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -159,6 +159,13 @@ def create_session(opts={}) # keep opts around for Session constructor, build REST params params = opts.clone + # validate input combinations + raise ArgumentError, "A session with always archive mode must also have the routed media mode." if (params[:archive_mode] == :always && params[:media_mode] == :relayed) + + raise ArgumentError, "A session with relayed media mode should not have e2ee set to true." if (params[:media_mode] == :relayed && params[:e2ee] == true) + + raise ArgumentError, "A session with always archive mode must not have e2ee set to true." if (params[:archive_mode] == :always && params[:e2ee] == true) + # anything other than :relayed sets the REST param to "disabled", in which case we force # opts to be :routed. if we were more strict we could raise an error when the value isn't # either :relayed or :routed @@ -177,8 +184,6 @@ def create_session(opts={}) raise "archive mode must be either always or manual" unless ARCHIVE_MODES.include? params[:archive_mode].to_sym end - raise "A session with always archive mode must also have the routed media mode." if (params[:archive_mode] == :always && params[:media_mode] == :relayed) - response = client.create_session(params) Session.new api_key, api_secret, response['sessions']['Session']['session_id'], opts end diff --git a/spec/opentok/opentok_spec.rb b/spec/opentok/opentok_spec.rb index ce04cb5d..934626d3 100644 --- a/spec/opentok/opentok_spec.rb +++ b/spec/opentok/opentok_spec.rb @@ -114,9 +114,33 @@ expect(session.location).to eq nil end + # context "with relayed media mode and always archive mode" do + # subject { -> { session = opentok.create_session :archive_mode => :always, :media_mode => :relayed }} + # it { should raise_error } + # end + context "with relayed media mode and always archive mode" do - subject { -> { session = opentok.create_session :archive_mode => :always, :media_mode => :relayed }} - it { should raise_error } + it "raises an error" do + expect { + opentok.create_session :archive_mode => :always, :media_mode => :relayed + }.to raise_error ArgumentError + end + end + + context "with relayed media mode and e2ee set to true" do + it "raises an error" do + expect { + opentok.create_session :media_mode => :relayed, :e2ee => true + }.to raise_error ArgumentError + end + end + + context "with always archive mode and e2ee set to true" do + it "raises an error" do + expect { + opentok.create_session :archive_mode => :always, :e2ee => true + }.to raise_error ArgumentError + end end end From e7f73c5822b7724a00c4f1de3aa4fc92a97d819b Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 3 Mar 2023 15:32:46 +0000 Subject: [PATCH 03/13] Adding docs comments to Opentok#create_session for e2ee option --- lib/opentok/opentok.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index f34be59a..4af4ebbe 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -144,6 +144,11 @@ def initialize(api_key, api_secret, opts={}) # automatically (:always) or not (:manual). When using automatic # archiving, the session must use the :routed media mode. # + # @option opts [true, false] :e2ee + # (Boolean, optional) — whether the session is end-to-end encrypted from client to client (default: false). + # Should not be set to `true` if `:media_mode` is `:relayed` or if `:archive_mode` is `:always`. + # See the {https://tokbox.com/developer/guides/end-to-end-encryption/ documentation} for more information. + # # @return [Session] The Session object. The session_id property of the object is the session ID. def create_session(opts={}) From 5b93ec71f7fd71fbacaf567dc1b10d4ce5de4fc4 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 3 Mar 2023 15:54:30 +0000 Subject: [PATCH 04/13] Updating README to demonstrate creation of an e2ee session --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 731cda1b..b36822a0 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ session = opentok.create_session :location => '12.34.56.78' # A session with automatic archiving (must use the routed media mode): session = opentok.create_session :archive_mode => :always, :media_mode => :routed +# A session with end-to-end encryption (must use the routed media mode): +session = opentok.create_session :e2ee => true, :media_mode => :routed + # Store this sessionId in the database for later use: session_id = session.session_id ``` @@ -322,7 +325,7 @@ For more information on archiving, see the ### Signaling -You can send a signal using the `opentok.signals.send(session_id, connection_id, opts)` method. +You can send a signal using the `opentok.signals.send(session_id, connection_id, opts)` method. If `connection_id` is nil or an empty string, then the signal is send to all valid connections in the session. @@ -457,7 +460,7 @@ You can cause a client to be forced to disconnect from a session by using the ### Forcing clients in a session to mute published audio -You can force the publisher of a specific stream to stop publishing audio using the +You can force the publisher of a specific stream to stop publishing audio using the `opentok.streams.force_mute(session_id, stream_id)` method. You can force the publisher of all streams in a session (except for an optional list of streams) From 19a021c08c61e95e2d500df50b1f8fc2225dcc99 Mon Sep 17 00:00:00 2001 From: Jeff Swartz Date: Wed, 3 May 2023 16:00:03 -0400 Subject: [PATCH 05/13] Minor docs edit --- lib/opentok/opentok.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index 4af4ebbe..45abb048 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -145,8 +145,8 @@ def initialize(api_key, api_secret, opts={}) # archiving, the session must use the :routed media mode. # # @option opts [true, false] :e2ee - # (Boolean, optional) — whether the session is end-to-end encrypted from client to client (default: false). - # Should not be set to `true` if `:media_mode` is `:relayed` or if `:archive_mode` is `:always`. + # (Boolean, optional) — Whether the session uses end-to-end encryption from client to client (default: false). + # This should not be set to `true` if `:media_mode` is `:relayed`. # See the {https://tokbox.com/developer/guides/end-to-end-encryption/ documentation} for more information. # # @return [Session] The Session object. The session_id property of the object is the session ID. From 9568583cdc4f36052d29152a0a762d8cb4354514 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 12 Jun 2023 16:35:15 +0100 Subject: [PATCH 06/13] Updating OpenTok#create_session code comments --- lib/opentok/opentok.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index b257dd33..fe728931 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -144,6 +144,16 @@ def initialize(api_key, api_secret, opts={}) # automatically (:always) or not (:manual). When using automatic # archiving, the session must use the :routed media mode. # + # @option opts [Symbol] :archive_name The name to use for archives in auto-archived sessions. + # When setting this option, the :archive_mode option must be set to :always or an error will result. + # The length of the archive name can be up to 80 chars. + # Due to encoding limitations the following special characters are translated to a colon (:) character: ~, -, _. + # If you do not set a name and the archiveMode option is set to always, the archive name will be empty. + # + # @option opts [Symbol] :archive_resolution The resolution of archives in an auto-archived session. + # Valid values are "480x640", "640x480" (the default), "720x1280", "1280x720", "1080x1920", and "1920x1080". + # When setting this option, the :archive_mode option must be set to :always or an error will result. + # # @option opts [true, false] :e2ee # (Boolean, optional) — Whether the session uses end-to-end encryption from client to client (default: false). # This should not be set to `true` if `:media_mode` is `:relayed`. From e26c05e3af209de00dc3a3d37bba2fdf715151d2 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 12 Jun 2023 17:32:59 +0100 Subject: [PATCH 07/13] Adding tests and VCR mocks --- ...hived_sessions_with_a_set_archive_name.yml | 42 ++++++++++++++++ ...with_a_set_archive_name_and_resolution.yml | 42 ++++++++++++++++ ...sessions_with_a_set_archive_resolution.yml | 42 ++++++++++++++++ spec/opentok/opentok_spec.rb | 49 +++++++++++++++++-- 4 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml create mode 100644 spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml create mode 100644 spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml new file mode 100644 index 00000000..ad94b18b --- /dev/null +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/session/create + body: + encoding: UTF-8 + string: archiveMode=always&p2p.preference=disabled&archiveName=foo + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 12 Jun 2023 16:17:36 GMT + Content-Type: + - text/xml + Connection: + - keep-alive + Access-Control-Allow-Origin: + - '*' + X-Tb-Host: + - fms503-nyc.tokbox.com + Content-Length: + - '282' + body: + encoding: UTF-8 + string: 1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg123456Mon + Jun 12 16:17:36 GMT 2023 + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml new file mode 100644 index 00000000..e494757b --- /dev/null +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/session/create + body: + encoding: UTF-8 + string: archiveMode=always&p2p.preference=disabled&archiveName=foo&archiveResolution=720x1280 + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 12 Jun 2023 16:17:36 GMT + Content-Type: + - text/xml + Connection: + - keep-alive + Access-Control-Allow-Origin: + - '*' + X-Tb-Host: + - fms503-nyc.tokbox.com + Content-Length: + - '282' + body: + encoding: UTF-8 + string: 1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg123456Mon + Jun 12 16:17:36 GMT 2023 + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml new file mode 100644 index 00000000..92ab87e4 --- /dev/null +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/session/create + body: + encoding: UTF-8 + string: archiveMode=always&p2p.preference=disabled&archiveResolution=720x1280 + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 12 Jun 2023 16:17:36 GMT + Content-Type: + - text/xml + Connection: + - keep-alive + Access-Control-Allow-Origin: + - '*' + X-Tb-Host: + - fms503-nyc.tokbox.com + Content-Length: + - '282' + body: + encoding: UTF-8 + string: 1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg123456Mon + Jun 12 16:17:36 GMT 2023 + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/opentok/opentok_spec.rb b/spec/opentok/opentok_spec.rb index 934626d3..7a9d3cfd 100644 --- a/spec/opentok/opentok_spec.rb +++ b/spec/opentok/opentok_spec.rb @@ -106,6 +106,34 @@ expect(session.location).to eq nil end + it "creates always archived sessions with a set archive name", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_name => 'foo' + expect(session).to be_an_instance_of OpenTok::Session + expect(session.session_id).to be_an_instance_of String + expect(session.archive_mode).to eq :always + expect(session.archive_name).to eq 'foo' + expect(session.location).to eq nil + end + + it "creates always archived sessions with a set archive resolution", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_resolution => "720x1280" + expect(session).to be_an_instance_of OpenTok::Session + expect(session.session_id).to be_an_instance_of String + expect(session.archive_mode).to eq :always + expect(session.archive_resolution).to eq "720x1280" + expect(session.location).to eq nil + end + + 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 + session = opentok.create_session :media_mode => :routed, :archive_mode => :always, :archive_name => 'foo', :archive_resolution => "720x1280" + expect(session).to be_an_instance_of OpenTok::Session + expect(session.session_id).to be_an_instance_of String + expect(session.archive_mode).to eq :always + expect(session.archive_name).to eq 'foo' + expect(session.archive_resolution).to eq "720x1280" + expect(session.location).to eq nil + end + it "creates e2ee sessions", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do session = opentok.create_session :media_mode => :routed, :e2ee => :true expect(session).to be_an_instance_of OpenTok::Session @@ -114,11 +142,6 @@ expect(session.location).to eq nil end - # context "with relayed media mode and always archive mode" do - # subject { -> { session = opentok.create_session :archive_mode => :always, :media_mode => :relayed }} - # it { should raise_error } - # end - context "with relayed media mode and always archive mode" do it "raises an error" do expect { @@ -127,6 +150,22 @@ end end + context "with archive name set and manual archive mode" do + it "raises an error" do + expect { + opentok.create_session :archive_mode => :manual, :archive_name => 'foo' + }.to raise_error ArgumentError + end + end + + context "with archive resolution set and manual archive mode" do + it "raises an error" do + expect { + opentok.create_session :archive_mode => :manual, :archive_resolution => "720x1280" + }.to raise_error ArgumentError + end + end + context "with relayed media mode and e2ee set to true" do it "raises an error" do expect { From d8025f3a5f537f9fc19b37c84454028914db1a07 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 12 Jun 2023 18:15:52 +0100 Subject: [PATCH 08/13] Updating VCR cassettes --- ...creates_always_archived_sessions_with_a_set_archive_name.yml | 2 +- ...archived_sessions_with_a_set_archive_name_and_resolution.yml | 2 +- ...s_always_archived_sessions_with_a_set_archive_resolution.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml index ad94b18b..94fd8105 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://api.opentok.com/session/create body: encoding: UTF-8 - string: archiveMode=always&p2p.preference=disabled&archiveName=foo + string: archiveMode=always&archiveName=foo&p2p.preference=disabled headers: User-Agent: - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml index e494757b..a53a63de 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://api.opentok.com/session/create body: encoding: UTF-8 - string: archiveMode=always&p2p.preference=disabled&archiveName=foo&archiveResolution=720x1280 + string: archiveMode=always&archiveName=foo&archiveResolution=720x1280&p2p.preference=disabled headers: User-Agent: - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml index 92ab87e4..eb049b23 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://api.opentok.com/session/create body: encoding: UTF-8 - string: archiveMode=always&p2p.preference=disabled&archiveResolution=720x1280 + string: archiveMode=always&archiveResolution=720x1280&p2p.preference=disabled headers: User-Agent: - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 From 0c951fc516b6de2b8cba2dd8e0750ba9c9888629 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 12 Jun 2023 18:23:00 +0100 Subject: [PATCH 09/13] Implementing auto archive improvements --- lib/opentok/opentok.rb | 3 ++- lib/opentok/session.rb | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index fe728931..b7ecfad8 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -163,7 +163,7 @@ def initialize(api_key, api_secret, opts={}) def create_session(opts={}) # normalize opts so all keys are symbols and only include valid_opts - valid_opts = [ :media_mode, :location, :archive_mode, :e2ee ] + valid_opts = [ :media_mode, :location, :archive_mode, :archive_name, :archive_resolution, :e2ee ] opts = opts.inject({}) do |m,(k,v)| if valid_opts.include? k.to_sym m[k.to_sym] = v @@ -197,6 +197,7 @@ def create_session(opts={}) # archive mode is optional, but it has to be one of the valid values if present unless params[:archive_mode].nil? raise "archive mode must be either always or manual" unless ARCHIVE_MODES.include? params[:archive_mode].to_sym + 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]) end response = client.create_session(params) diff --git a/lib/opentok/session.rb b/lib/opentok/session.rb index 82e84fa1..4bd7fd55 100644 --- a/lib/opentok/session.rb +++ b/lib/opentok/session.rb @@ -20,6 +20,10 @@ module OpenTok # @attr_reader [String] archive_mode Whether the session will be archived automatically # (:always) or not (:manual). # + # @attr_reader [String] archive_name The name to use for archives in auto-archived sessions. + # + # @attr_reader [String] :archive_resolution The resolution of archives in an auto-archived session. + # # @!method generate_token(options) # Generates a token. # @@ -57,7 +61,7 @@ class Session :session_id => ->(instance) { instance.session_id } }) - attr_reader :session_id, :media_mode, :location, :archive_mode, :e2ee, :api_key, :api_secret + attr_reader :session_id, :media_mode, :location, :archive_mode, :archive_name, :archive_resolution, :e2ee, :api_key, :api_secret # @private # 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) # @private def initialize(api_key, api_secret, session_id, opts={}) @api_key, @api_secret, @session_id = api_key, api_secret, session_id - @media_mode, @location, @archive_mode, @e2ee = opts.fetch(:media_mode, :relayed), opts[:location], opts.fetch(:archive_mode, :manual), opts.fetch(:e2ee, :false) + @media_mode = opts.fetch(:media_mode, :relayed) + @location = opts[:location] + @archive_mode = opts.fetch(:archive_mode, :manual) + @archive_name = opts.fetch(:archive_name, '') if archive_mode == :always + @archive_resolution = opts.fetch(:archive_resolution, "640x480") if archive_mode == :always + @e2ee = opts.fetch(:e2ee, :false) end # @private From 44826b5ce5172b0f1ac550b26cda60d87be6fa42 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 12 Jun 2023 18:43:03 +0100 Subject: [PATCH 10/13] Fixing UA header in VCR casettes --- ...creates_always_archived_sessions_with_a_set_archive_name.yml | 2 +- ...archived_sessions_with_a_set_archive_name_and_resolution.yml | 2 +- ...s_always_archived_sessions_with_a_set_archive_resolution.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml index 94fd8105..832ae740 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name.yml @@ -8,7 +8,7 @@ http_interactions: string: archiveMode=always&archiveName=foo&p2p.preference=disabled headers: User-Agent: - - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Accept-Encoding: diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml index a53a63de..e7fd264f 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_name_and_resolution.yml @@ -8,7 +8,7 @@ http_interactions: string: archiveMode=always&archiveName=foo&archiveResolution=720x1280&p2p.preference=disabled headers: User-Agent: - - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Accept-Encoding: diff --git a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml index eb049b23..4b366efb 100644 --- a/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml +++ b/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions_with_a_set_archive_resolution.yml @@ -8,7 +8,7 @@ http_interactions: string: archiveMode=always&archiveResolution=720x1280&p2p.preference=disabled headers: User-Agent: - - OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.0.0-p0 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Accept-Encoding: From 47655bb3aa536b3e6ec894c359705515bb8cf856 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 19 Jun 2023 12:32:42 +0100 Subject: [PATCH 11/13] Adding ua_addendum to README initialization opts --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 739b3613..d85706e7 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ opentok = OpenTok::OpenTok.new api_key, api_secret #### Initialization Options +**Custom Timeout** + You can specify a custom timeout value for HTTP requests when initializing a new `OpenTok::OpenTok` object: @@ -71,6 +73,23 @@ opentok = OpenTok::OpenTok.new api_key, api_secret, :timeout_length => 10 The value for `:timeout_length` is an integer representing the number of seconds to wait for an HTTP request to complete. The default is set to 2 seconds. +**UA Addendum** + +You can also append a custom string to the `User-Agent` header value for HTTP requests when initializing a new `OpenTok::OpenTok` +object: + +```ruby +require "opentok" + +opentok = OpenTok::OpenTok.new api_key, api_secret, :ua_addendum => 'FOO' +``` + +The above would generate a `User-Agent` header something like this: + +``` +User-Agent: OpenTok-Ruby-SDK/4.6.0-Ruby-Version-3.1.2-p20 FOO +``` + ### Creating Sessions To create an OpenTok Session, use the `OpenTok#create_session(properties)` method. From ee40aef495936a2b04cab94f3be0af0b0bcf112a Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 20 Jun 2023 10:23:42 +0100 Subject: [PATCH 12/13] Updating changelog --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c984f5a0..fef6abd9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# 4.7.0 + +* Adds support for the End-to-end encryption (E2EE) feature [#259](https://github.com/opentok/OpenTok-Ruby-SDK/pull/259) +* Implements Auto-archive improvements [#262](https://github.com/opentok/OpenTok-Ruby-SDK/pull/262) +* Updates the README to explain appending a custom value to the `UserAgent` header [#263](https://github.com/opentok/OpenTok-Ruby-SDK/pull/263) + # 4.6.0 * Adds functionality for working with the Audio Connector feature [#247](https://github.com/opentok/OpenTok-Ruby-SDK/pull/247) From c7ece55b892055bf8069b664e814d478e737e4a5 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 20 Jun 2023 10:23:54 +0100 Subject: [PATCH 13/13] Bumping minor version --- lib/opentok/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opentok/version.rb b/lib/opentok/version.rb index 70bc320c..be1ffff9 100644 --- a/lib/opentok/version.rb +++ b/lib/opentok/version.rb @@ -1,4 +1,4 @@ module OpenTok # @private - VERSION = '4.6.0' + VERSION = '4.7.0' end