From 06f44e6defe1993ecf26fe80e57243b2e0fd214e Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 29 Oct 2021 11:09:03 +0100 Subject: [PATCH 1/8] Adding force_mute_stream and force_mute_session methods --- lib/opentok/client.rb | 39 ++++++++++++++++++++++++++++++++++++++ lib/opentok/connections.rb | 10 +++++++++- lib/opentok/opentok.rb | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/opentok/client.rb b/lib/opentok/client.rb index 2808520f..bea15e2f 100644 --- a/lib/opentok/client.rb +++ b/lib/opentok/client.rb @@ -206,6 +206,45 @@ def forceDisconnect(session_id, connection_id) raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}" end + def force_mute_stream(session_id, stream_id) + response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/stream/#{stream_id}/mute", { + :headers => generate_headers("Content-Type" => "application/json") + }) + case response.code + when 200 + response + when 400 + raise ArgumentError, "Force mute failed. Stream ID #{stream_id} or Session ID #{session_id} is invalid" + when 403 + raise OpenTokAuthenticationError, "You are not authorized to force_mute_stream, check your authentication credentials or token type is non-moderator" + when 404 + raise OpenTokConnectionError, "Either Stream ID #{stream_id} or Session ID #{session_id} is invalid" + end + rescue StandardError => e + raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}" + end + + def force_mute_session(session_id, opts) + opts.extend(HashExtensions) + body = opts.camelize_keys! + response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/mute", { + :body => body.to_json, + :headers => generate_headers("Content-Type" => "application/json") + }) + case response.code + when 200 + response + when 400 + raise ArgumentError, "Force mute failed. The request could not be processed due to a bad request" + when 403 + raise OpenTokAuthenticationError, "You are not authorized to force_mute_session, check your authentication credentials or token type is non-moderator" + when 404 + raise OpenTokConnectionError, "Session ID #{session_id} is invalid" + end + rescue StandardError => e + raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}" + end + def signal(session_id, connection_id, opts) opts.extend(HashExtensions) connectionPath = connection_id.to_s.empty? ? "" : "/connection/#{connection_id}" diff --git a/lib/opentok/connections.rb b/lib/opentok/connections.rb index 5a5fa7c0..08a6786c 100644 --- a/lib/opentok/connections.rb +++ b/lib/opentok/connections.rb @@ -24,5 +24,13 @@ def forceDisconnect(session_id, connection_id ) (200..300).include? response.code end + def force_mute_stream(session_id, stream_id) + response = @client.force_mute_stream(session_id, connection_id) + end + + def force_mute_session(session_id, opts) + response = @client.force_mute_session(session_id, opts) + end + end -end \ No newline at end of file +end diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index 6d0933ce..4a8f7b8b 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -207,7 +207,7 @@ def signals @signals ||= Signals.new client end - # A Connections object, which lets disconnect clients from an OpenTok session. + # A Connections object, which lets you manage clients connected to an OpenTok session. def connections @connections ||= Connections.new client end From 7f2fc80b54d7d8f1e2f2e7cd768123513e019561 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 29 Oct 2021 12:02:41 +0100 Subject: [PATCH 2/8] Fixing param name --- lib/opentok/connections.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opentok/connections.rb b/lib/opentok/connections.rb index 08a6786c..45c40092 100644 --- a/lib/opentok/connections.rb +++ b/lib/opentok/connections.rb @@ -25,7 +25,7 @@ def forceDisconnect(session_id, connection_id ) end def force_mute_stream(session_id, stream_id) - response = @client.force_mute_stream(session_id, connection_id) + response = @client.force_mute_stream(session_id, stream_id) end def force_mute_session(session_id, opts) From 33ddde83c87077f5ba20bc7c41fb8f02947270c4 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 29 Oct 2021 12:44:22 +0100 Subject: [PATCH 3/8] Setting default argument for opts in Connections#force_mute_session --- lib/opentok/connections.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opentok/connections.rb b/lib/opentok/connections.rb index 45c40092..266b7c31 100644 --- a/lib/opentok/connections.rb +++ b/lib/opentok/connections.rb @@ -28,7 +28,7 @@ def force_mute_stream(session_id, stream_id) response = @client.force_mute_stream(session_id, stream_id) end - def force_mute_session(session_id, opts) + def force_mute_session(session_id, opts = {}) response = @client.force_mute_session(session_id, opts) end From 1709b4a8be5bfa52a18fcf2a7d5f5be4561143ce Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 30 Oct 2021 19:36:21 +0100 Subject: [PATCH 4/8] Adding tests for force mute functionality --- ...treams_joining_the_session_to_be_muted.yml | 39 +++++++++++++++++++ ...ept_for_the_specified_excluded_streams.yml | 39 +++++++++++++++++++ ...s_all_streams_in_a_session_to_be_muted.yml | 39 +++++++++++++++++++ ...orces_the_specified_stream_to_be_muted.yml | 39 +++++++++++++++++++ spec/opentok/connection_spec.rb | 23 ++++++++++- 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml create mode 100644 spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml create mode 100644 spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml create mode 100644 spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml new file mode 100644 index 00000000..6f4ffeca --- /dev/null +++ b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute + body: + encoding: UTF-8 + string: '{"active":"true"}' + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Content-Type: + - application/json + 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: + - Fri, 29 Oct 2021 11:57:18 GMT + Content-Type: + - application/json + Content-Length: + - '0' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '' + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml new file mode 100644 index 00000000..1da1055b --- /dev/null +++ b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute + body: + encoding: UTF-8 + string: '{"excludedStreams":["b1963d15-537f-459a-be89-e00fc310b82b"]}' + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Content-Type: + - application/json + 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: + - Fri, 29 Oct 2021 12:01:42 GMT + Content-Type: + - application/json + Content-Length: + - '0' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '' + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml new file mode 100644 index 00000000..155fef74 --- /dev/null +++ b/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute + body: + encoding: UTF-8 + string: "{}" + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Content-Type: + - application/json + 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: + - Fri, 29 Oct 2021 11:48:19 GMT + Content-Type: + - application/json + Content-Length: + - '0' + Connection: + - close + body: + encoding: UTF-8 + string: '' + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml new file mode 100644 index 00000000..f9ee53a7 --- /dev/null +++ b/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/stream/STREAMID/mute + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + X-Opentok-Auth: + - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 + Content-Type: + - application/json + 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: + - Fri, 29 Oct 2021 11:01:54 GMT + Content-Type: + - application/json + Content-Length: + - '0' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '' + recorded_at: Tue, 18 Apr 2017 10:17:40 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/opentok/connection_spec.rb b/spec/opentok/connection_spec.rb index 3d682436..d0506ade 100644 --- a/spec/opentok/connection_spec.rb +++ b/spec/opentok/connection_spec.rb @@ -13,6 +13,7 @@ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" } let(:session_id) { "SESSIONID" } let(:connection_id) { "CONNID" } + let(:stream_id) { "STREAMID" } let(:opentok) { OpenTok::OpenTok.new api_key, api_secret } let(:connection) { opentok.connections } @@ -35,4 +36,24 @@ response = connection.forceDisconnect(session_id, connection_id) expect(response).not_to be_nil end -end \ No newline at end of file + + it "forces the specified stream to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = connection.force_mute_stream(session_id, stream_id) + expect(response.code).to eq(200) + end + + it "forces all streams in a session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = connection.force_mute_session(session_id) + expect(response.code).to eq(200) + end + + it "forces all current streams in a session and future streams joining the session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = connection.force_mute_session(session_id, { "active" => "true" }) + expect(response.code).to eq(200) + end + + it "forces all current streams in a session to be muted except for the specified excluded streams", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = connection.force_mute_session(session_id, { "excludedStreams" => ["b1963d15-537f-459a-be89-e00fc310b82b"] }) + expect(response.code).to eq(200) + end +end From 1e7c29e8bd138a22ff557a7a1cf0c710d4c5fcf9 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 30 Oct 2021 19:53:38 +0100 Subject: [PATCH 5/8] Fixing User-Agent issue in VCR casettes --- ...ssion_and_future_streams_joining_the_session_to_be_muted.yml | 2 +- ...on_to_be_muted_except_for_the_specified_excluded_streams.yml | 2 +- .../forces_all_streams_in_a_session_to_be_muted.yml | 2 +- .../forces_the_specified_stream_to_be_muted.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml index 6f4ffeca..0070751b 100644 --- a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml +++ b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml @@ -8,7 +8,7 @@ http_interactions: string: '{"active":"true"}' headers: User-Agent: - - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Content-Type: diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml index 1da1055b..8743afcc 100644 --- a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml +++ b/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml @@ -8,7 +8,7 @@ http_interactions: string: '{"excludedStreams":["b1963d15-537f-459a-be89-e00fc310b82b"]}' headers: User-Agent: - - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Content-Type: diff --git a/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml index 155fef74..49087043 100644 --- a/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml +++ b/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml @@ -8,7 +8,7 @@ http_interactions: string: "{}" headers: User-Agent: - - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Content-Type: diff --git a/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml b/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml index f9ee53a7..4460155e 100644 --- a/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml +++ b/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml @@ -8,7 +8,7 @@ http_interactions: string: '' headers: User-Agent: - - OpenTok-Ruby-SDK/4.3.0-Ruby-Version-2.6.2-p47 + - OpenTok-Ruby-SDK/<%= version %> X-Opentok-Auth: - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120 Content-Type: From 6fe45389e0f7e7a5e64572ac75b00db97b11f41f Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 31 Oct 2021 13:04:48 +0000 Subject: [PATCH 6/8] Adding method guidance comments to connections.rb --- lib/opentok/connections.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/opentok/connections.rb b/lib/opentok/connections.rb index 266b7c31..c668724e 100644 --- a/lib/opentok/connections.rb +++ b/lib/opentok/connections.rb @@ -24,10 +24,32 @@ def forceDisconnect(session_id, connection_id ) (200..300).include? response.code end + # Force a specific client connected to an OpenTok session to mute itself. + # + # @param [String] session_id The session ID of the OpenTok session. + # @param [String] stream_id The stream ID of the client in the session. + def force_mute_stream(session_id, stream_id) response = @client.force_mute_stream(session_id, stream_id) end + # Force all clients connected to an OpenTok session to mute themselves. + # + # @param [String] session_id The session ID of the OpenTok session. + # @param [Hash] opts An optional hash defining options for muting action. For example: + # @option opts [true, false] :active Whether streams published after this call, in + # addition to the current streams in the session, should be muted (true) or not (false). + # @option opts [Array] :excluded_streams The stream IDs for streams that should not be muted. + # This is an optional property. If you omit this property, all streams in the session will be muted. + # @example + # { + # "active": true, + # "excluded_streams": [ + # "excludedStreamId1", + # "excludedStreamId2" + # ] + # } + def force_mute_session(session_id, opts = {}) response = @client.force_mute_session(session_id, opts) end From f4477713fd358af1f7d62c0ea66fd9ced753cdb1 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 30 Nov 2021 10:49:32 +0000 Subject: [PATCH 7/8] Moving mute and mute all functionality from connections to streams --- lib/opentok/connections.rb | 30 ----------------- lib/opentok/streams.rb | 32 ++++++++++++++++++- ...treams_joining_the_session_to_be_muted.yml | 0 ...ept_for_the_specified_excluded_streams.yml | 0 ...s_all_streams_in_a_session_to_be_muted.yml | 0 ...orces_the_specified_stream_to_be_muted.yml | 0 spec/opentok/connection_spec.rb | 21 ------------ spec/opentok/streams_spec.rb | 22 ++++++++++++- 8 files changed, 52 insertions(+), 53 deletions(-) rename spec/cassettes/{OpenTok_Connections => OpenTok_Streams}/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml (100%) rename spec/cassettes/{OpenTok_Connections => OpenTok_Streams}/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml (100%) rename spec/cassettes/{OpenTok_Connections => OpenTok_Streams}/forces_all_streams_in_a_session_to_be_muted.yml (100%) rename spec/cassettes/{OpenTok_Connections => OpenTok_Streams}/forces_the_specified_stream_to_be_muted.yml (100%) diff --git a/lib/opentok/connections.rb b/lib/opentok/connections.rb index c668724e..86919a2e 100644 --- a/lib/opentok/connections.rb +++ b/lib/opentok/connections.rb @@ -24,35 +24,5 @@ def forceDisconnect(session_id, connection_id ) (200..300).include? response.code end - # Force a specific client connected to an OpenTok session to mute itself. - # - # @param [String] session_id The session ID of the OpenTok session. - # @param [String] stream_id The stream ID of the client in the session. - - def force_mute_stream(session_id, stream_id) - response = @client.force_mute_stream(session_id, stream_id) - end - - # Force all clients connected to an OpenTok session to mute themselves. - # - # @param [String] session_id The session ID of the OpenTok session. - # @param [Hash] opts An optional hash defining options for muting action. For example: - # @option opts [true, false] :active Whether streams published after this call, in - # addition to the current streams in the session, should be muted (true) or not (false). - # @option opts [Array] :excluded_streams The stream IDs for streams that should not be muted. - # This is an optional property. If you omit this property, all streams in the session will be muted. - # @example - # { - # "active": true, - # "excluded_streams": [ - # "excludedStreamId1", - # "excludedStreamId2" - # ] - # } - - def force_mute_session(session_id, opts = {}) - response = @client.force_mute_session(session_id, opts) - end - end end diff --git a/lib/opentok/streams.rb b/lib/opentok/streams.rb index 59c91fde..fd302b91 100644 --- a/lib/opentok/streams.rb +++ b/lib/opentok/streams.rb @@ -75,5 +75,35 @@ def layout(session_id, opts) (200..300).include? response.code end + # Force a specific stream connected to an OpenTok session to mute itself. + # + # @param [String] session_id The session ID of the OpenTok session. + # @param [String] stream_id The stream ID of the stream in the session. + # + def force_mute(session_id, stream_id) + response = @client.force_mute_stream(session_id, stream_id) + end + + # Force all streams connected to an OpenTok session to mute themselves. + # + # @param [String] session_id The session ID of the OpenTok session. + # @param [Hash] opts An optional hash defining options for muting action. For example: + # @option opts [true, false] :active Whether streams published after this call, in + # addition to the current streams in the session, should be muted (true) or not (false). + # @option opts [Array] :excluded_streams The stream IDs for streams that should not be muted. + # This is an optional property. If you omit this property, all streams in the session will be muted. + # @example + # { + # "active": true, + # "excluded_streams": [ + # "excludedStreamId1", + # "excludedStreamId2" + # ] + # } + # + def force_mute_all(session_id, opts = {}) + response = @client.force_mute_session(session_id, opts) + end + end -end \ No newline at end of file +end diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml b/spec/cassettes/OpenTok_Streams/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml similarity index 100% rename from spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml rename to spec/cassettes/OpenTok_Streams/forces_all_current_streams_in_a_session_and_future_streams_joining_the_session_to_be_muted.yml diff --git a/spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml b/spec/cassettes/OpenTok_Streams/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml similarity index 100% rename from spec/cassettes/OpenTok_Connections/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml rename to spec/cassettes/OpenTok_Streams/forces_all_current_streams_in_a_session_to_be_muted_except_for_the_specified_excluded_streams.yml diff --git a/spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml b/spec/cassettes/OpenTok_Streams/forces_all_streams_in_a_session_to_be_muted.yml similarity index 100% rename from spec/cassettes/OpenTok_Connections/forces_all_streams_in_a_session_to_be_muted.yml rename to spec/cassettes/OpenTok_Streams/forces_all_streams_in_a_session_to_be_muted.yml diff --git a/spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml b/spec/cassettes/OpenTok_Streams/forces_the_specified_stream_to_be_muted.yml similarity index 100% rename from spec/cassettes/OpenTok_Connections/forces_the_specified_stream_to_be_muted.yml rename to spec/cassettes/OpenTok_Streams/forces_the_specified_stream_to_be_muted.yml diff --git a/spec/opentok/connection_spec.rb b/spec/opentok/connection_spec.rb index d0506ade..662714a4 100644 --- a/spec/opentok/connection_spec.rb +++ b/spec/opentok/connection_spec.rb @@ -13,7 +13,6 @@ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" } let(:session_id) { "SESSIONID" } let(:connection_id) { "CONNID" } - let(:stream_id) { "STREAMID" } let(:opentok) { OpenTok::OpenTok.new api_key, api_secret } let(:connection) { opentok.connections } @@ -36,24 +35,4 @@ response = connection.forceDisconnect(session_id, connection_id) expect(response).not_to be_nil end - - it "forces the specified stream to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do - response = connection.force_mute_stream(session_id, stream_id) - expect(response.code).to eq(200) - end - - it "forces all streams in a session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do - response = connection.force_mute_session(session_id) - expect(response.code).to eq(200) - end - - it "forces all current streams in a session and future streams joining the session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do - response = connection.force_mute_session(session_id, { "active" => "true" }) - expect(response.code).to eq(200) - end - - it "forces all current streams in a session to be muted except for the specified excluded streams", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do - response = connection.force_mute_session(session_id, { "excludedStreams" => ["b1963d15-537f-459a-be89-e00fc310b82b"] }) - expect(response.code).to eq(200) - end end diff --git a/spec/opentok/streams_spec.rb b/spec/opentok/streams_spec.rb index 3fc45451..211be08c 100644 --- a/spec/opentok/streams_spec.rb +++ b/spec/opentok/streams_spec.rb @@ -72,4 +72,24 @@ response = streams.layout(session_id, streams_list) expect(response).not_to be_nil end -end \ No newline at end of file + + it "forces the specified stream to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = streams.force_mute(session_id, stream_id) + expect(response.code).to eq(200) + end + + it "forces all streams in a session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = streams.force_mute_all(session_id) + expect(response.code).to eq(200) + end + + it "forces all current streams in a session and future streams joining the session to be muted", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = streams.force_mute_all(session_id, { "active" => "true" }) + expect(response.code).to eq(200) + end + + it "forces all current streams in a session to be muted except for the specified excluded streams", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + response = streams.force_mute_all(session_id, { "excludedStreams" => ["b1963d15-537f-459a-be89-e00fc310b82b"] }) + expect(response.code).to eq(200) + end +end From 441dd9c19de6f0aff9eeb790f0d40ae243e5dd11 Mon Sep 17 00:00:00 2001 From: superchilled Date: Thu, 2 Dec 2021 12:20:57 +0000 Subject: [PATCH 8/8] Minor updates following second review. --- lib/opentok/client.rb | 4 ++-- lib/opentok/opentok.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/opentok/client.rb b/lib/opentok/client.rb index bea15e2f..b5ee3158 100644 --- a/lib/opentok/client.rb +++ b/lib/opentok/client.rb @@ -216,7 +216,7 @@ def force_mute_stream(session_id, stream_id) when 400 raise ArgumentError, "Force mute failed. Stream ID #{stream_id} or Session ID #{session_id} is invalid" when 403 - raise OpenTokAuthenticationError, "You are not authorized to force_mute_stream, check your authentication credentials or token type is non-moderator" + raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}" when 404 raise OpenTokConnectionError, "Either Stream ID #{stream_id} or Session ID #{session_id} is invalid" end @@ -237,7 +237,7 @@ def force_mute_session(session_id, opts) when 400 raise ArgumentError, "Force mute failed. The request could not be processed due to a bad request" when 403 - raise OpenTokAuthenticationError, "You are not authorized to force_mute_session, check your authentication credentials or token type is non-moderator" + raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}" when 404 raise OpenTokConnectionError, "Session ID #{session_id} is invalid" end diff --git a/lib/opentok/opentok.rb b/lib/opentok/opentok.rb index 4a8f7b8b..9062a7d7 100644 --- a/lib/opentok/opentok.rb +++ b/lib/opentok/opentok.rb @@ -207,7 +207,7 @@ def signals @signals ||= Signals.new client end - # A Connections object, which lets you manage clients connected to an OpenTok session. + # A Connections object, which lets you disconnect clients from an OpenTok session. def connections @connections ||= Connections.new client end