diff --git a/CHANGES.md b/CHANGES.md index 5a1a75b..5b42f45 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 4.13.0 + +* 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) + # 4.12.0 * Updating the `Archives#create` method to allow `max_bitrate` as an option. See [#288](https://github.com/opentok/OpenTok-Ruby-SDK/pull/288) diff --git a/lib/opentok/archives.rb b/lib/opentok/archives.rb index c24eb00..f410ea1 100644 --- a/lib/opentok/archives.rb +++ b/lib/opentok/archives.rb @@ -84,6 +84,11 @@ def initialize(client) # to control the size of the composed archive. This maximum bitrate applies to the video bitrate only. If the output archive has # audio, those bits will be excluded from the limit. # + # @option options [Integer] :quantization_parameter (Optional) The quantization parameter (QP) is an optional video encoding value allowed for composed archiving, + # smaller values generate higher quality and larger archives, larger values generate lower quality and smaller archives, QP uses variable bitrate (VBR). The minimum + # value is 15 and the maximum is 40. + # This parameter is mutually exclusive with the max_bitrate parameter. + # # @return [Archive] The Archive object, which includes properties defining the archive, # including the archive ID. # @@ -110,7 +115,8 @@ def create(session_id, options = {}) :layout, :multi_archive_tag, :stream_mode, - :max_bitrate + :max_bitrate, + :quantization_parameter ] opts = options.inject({}) do |m,(k,v)| if valid_opts.include? k.to_sym diff --git a/lib/opentok/version.rb b/lib/opentok/version.rb index f2ad728..ba83867 100644 --- a/lib/opentok/version.rb +++ b/lib/opentok/version.rb @@ -1,4 +1,4 @@ module OpenTok # @private - VERSION = '4.12.0' + VERSION = '4.13.0' end diff --git a/lib/opentok/websocket.rb b/lib/opentok/websocket.rb index 875487b..2389a04 100644 --- a/lib/opentok/websocket.rb +++ b/lib/opentok/websocket.rb @@ -26,6 +26,7 @@ class WebSocket # If you omit this property, all streams in the session will be included. # @option opts [Hash] :headers (optional) A hash of key-value pairs of headers to be sent to your WebSocket server with each message, # with a maximum length of 512 bytes. + # @option opts [Boolean] :bidirectional (optional) Whether the WebSocket connection should be bidirectional. def connect(session_id, token, websocket_uri, opts = {}) response = @client.connect_websocket(session_id, token, websocket_uri, opts) end diff --git a/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_quantizationParameter_set_to_specified_quantization_parameter_value.yml b/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_quantizationParameter_set_to_specified_quantization_parameter_value.yml new file mode 100644 index 0000000..82acb9f --- /dev/null +++ b/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_quantizationParameter_set_to_specified_quantization_parameter_value.yml @@ -0,0 +1,52 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/archive + body: + encoding: UTF-8 + string: '{"sessionId":"SESSIONID","quantizationParameter":40}' + headers: + User-Agent: + - OpenTok-Ruby-SDK/<%= version %> + 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: + - Mon, 06 Oct 2025 08:48:17 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + body: + encoding: UTF-8 + string: |- + { + "createdAt" : 1395183243556, + "duration" : 0, + "id" : "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9", + "name" : "", + "partnerId" : 123456, + "reason" : "", + "sessionId" : "SESSIONID", + "size" : 0, + "status" : "started", + "url" : null, + "quantizationParameter": 40 + } + recorded_at: Mon, 06 Oct 2025 08:48:17 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/OpenTok_WebSocket/receives_a_valid_response_with_opts.yml b/spec/cassettes/OpenTok_WebSocket/receives_a_valid_response_with_opts.yml new file mode 100644 index 0000000..374791b --- /dev/null +++ b/spec/cassettes/OpenTok_WebSocket/receives_a_valid_response_with_opts.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.opentok.com/v2/project/123456/connect + body: + encoding: UTF-8 + string: '{"sessionId":"SESSIONID","token":"TOKENID","websocket":{"uri":"ws://service.com/wsendpoint","streams":["123456"],"headers":{"foo":"bar"},"bidirectional":true}}' + headers: + User-Agent: + - OpenTok-Ruby-SDK/<%= version %> + 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: + Date: + - Mon, 06 Oct 2025 09:42:20 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + X-Opentok-Trace: + - f=unknown&s=cerberus&u=3E467A7C-6130-469D-BD7B-10308CD0D395 + body: + encoding: UTF-8 + string: '{"id":"2299ba24-a6de-417c-88f7-28da54a441cf","connectionId":"833a7182-61a5-49d4-baae-c324b09953af"}' + recorded_at: Mon, 06 Oct 2025 09:42:20 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/opentok/archives_spec.rb b/spec/opentok/archives_spec.rb index 68d5b22..39b9536 100644 --- a/spec/opentok/archives_spec.rb +++ b/spec/opentok/archives_spec.rb @@ -77,6 +77,13 @@ expect(archive.max_bitrate).to eq max_bitrate end + it "should create an archive with quantizationParameter set to specified quantization_parameter value", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + quantization_parameter = 40 + archive = archives.create session_id, :quantization_parameter => quantization_parameter + expect(archive).to be_an_instance_of OpenTok::Archive + expect(archive.quantization_parameter).to eq quantization_parameter + end + it "should create audio only archives", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do archive = archives.create session_id, :has_video => false expect(archive).to be_an_instance_of OpenTok::Archive diff --git a/spec/opentok/websocket_spec.rb b/spec/opentok/websocket_spec.rb index 2ce8b8c..252393b 100644 --- a/spec/opentok/websocket_spec.rb +++ b/spec/opentok/websocket_spec.rb @@ -23,4 +23,15 @@ response = websocket.connect(session_id, expiring_token, websocket_uri) expect(response).not_to be_nil end + + it "receives a valid response with opts", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do + opts = { + "streams" => ["123456"], + "headers" => {"foo" => "bar"}, + "bidirectional" => true + } + + response = websocket.connect(session_id, expiring_token, websocket_uri, opts) + expect(response).not_to be_nil + end end