Skip to content

Commit

Permalink
Merge pull request #218 from Abdelrahman-Atia/fix-custom-layout
Browse files Browse the repository at this point in the history
Can't Add Custom Broadcast Layout Fix
  • Loading branch information
Ben Greenberg authored Jul 15, 2020
2 parents af4350d + f5796da commit 928c40c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/opentok/archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def layout(archive_id, options = {})
type = options[:type]
raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!options.key? :stylesheet)
valid_non_custom_type = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""].include? type
raise ArgumentError, "type is not valid or stylesheet not needed" if !valid_non_custom_type
raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom")
raise ArgumentError, "type is not valid or stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
response = @client.layout_archive(archive_id, options)
(200..300).include? response.code
Expand Down
2 changes: 1 addition & 1 deletion lib/opentok/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def layout(broadcast_id, options = {})
type = options[:type]
raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!options.key? :stylesheet)
valid_non_custom_type = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""].include? type
raise ArgumentError, "type is not valid" if !valid_non_custom_type
raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom")
raise ArgumentError, "stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
response = @client.layout_broadcast(broadcast_id, options)
(200..300).include? response.code
Expand Down
26 changes: 25 additions & 1 deletion spec/opentok/broadcasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@
}.to raise_error(ArgumentError)
end

it "raise an error for non valid type" do
expect {
broadcast.layout(started_broadcast_id, {
type: "not-valid",
stylesheet: "stream {}"
})
}.to raise_error(ArgumentError)
end

it "change the layout to custom type with custom stylesheet" do
stub_request(:put, "https://api.opentok.com/v2/project/#{api_key}/broadcast/#{started_broadcast_id}/layout").
with(body: {type: 'custom', stylesheet: 'stream {float: left; height: 100%; width: 33.33%;}'}).
to_return(status: 200)

response = broadcast.layout(started_broadcast_id, {
type: "custom",
stylesheet: "stream {float: left; height: 100%; width: 33.33%;}"
})
expect(response).not_to be_nil
end

it "raise an error if invalid layout type" do
expect {
broadcast.layout(started_broadcast_id, {
Expand All @@ -162,10 +183,13 @@
}.to raise_error(ArgumentError)
end
it "changes the layout of a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
stub_request(:put, "https://api.opentok.com/v2/project/#{api_key}/broadcast/#{started_broadcast_id}/layout").
to_return(status: 200)

response = broadcast.layout(started_broadcast_id, {
:type => "verticalPresentation"
})
expect(response).not_to be_nil
end

end
end

0 comments on commit 928c40c

Please sign in to comment.