diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/obswebsocket.cr | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index 5f6e995..8c1061a 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -40,7 +40,7 @@ module OBS ORMCritical = Scenes|Inputs| Filters|Outputs|SceneItems|SceneItemTransformChanged end - def req( type : String, id : String = UUID.random.to_s, data : ( String | Nil | JSON::Any ) = nil ) + def req( type : String, data : ( String | Nil | JSON::Any ) = nil, id : String = UUID.random.to_s ) request = JSON.build do |json| json.object do json.field "op", 6 @@ -446,7 +446,7 @@ module OBS def initialize( @obs : OBS::WebSocket, @name : String ) end def populate - d = @obs.send_sync( OBS.req( "GetOutputStatus", data: JSON.parse( { "outputName" => @name }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "GetOutputStatus", JSON.parse( { "outputName" => @name }.to_json ) ) ) if ( rdata = d["responseData"]? ) @age = Time.utc.to_unix @status = Hash(String, String | Bool | Int64 | Float64 ).from_json(rdata.to_json) @@ -640,7 +640,7 @@ module OBS @filters = OBS::SourceFilters.new( @obs, @name ) end def populate - d = @obs.send_sync( OBS.req( "GetSceneItemList", data: JSON.parse( { "sceneName" => @name }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "GetSceneItemList", JSON.parse( { "sceneName" => @name }.to_json ) ) ) if ( rdata = d["responseData"]? ) # handle "sourceType": "OBS_SOURCE_TYPE_SCENE" rdata["sceneItems"].as_a.each_with_index{ | item, i | @@ -733,11 +733,11 @@ module OBS end def program! # we get weird behavior on transitions unless we block here - @obs.send_sync( OBS.req( "SetCurrentProgramScene", data: JSON.parse( { "sceneName" => @name }.to_json ) ) ) + @obs.send_sync( OBS.req( "SetCurrentProgramScene", JSON.parse( { "sceneName" => @name }.to_json ) ) ) end def preview! # we get weird behavior on transitions unless we block here - @obs.send_sync( OBS.req( "SetCurrentPreviewScene", data: JSON.parse( { "sceneName" => @name }.to_json ) ) ) + @obs.send_sync( OBS.req( "SetCurrentPreviewScene", JSON.parse( { "sceneName" => @name }.to_json ) ) ) end def createinput( iname : String, kind : String, settings : OBS::InputSettings | Hash( String, String | Bool | Int64 | Float64 ) | Nil = nil, enabled : Bool = true ) reqdata = ( Hash( String, String | Bool | Int64 | Float64 | Hash( String, String | Bool | Int64 | Float64 ) ) ).new @@ -751,7 +751,7 @@ module OBS reqdata["sceneItemEnabled"] = false end - d = @obs.send_sync( OBS.req( "CreateInput", data: JSON.parse(reqdata.to_json) ) ) + d = @obs.send_sync( OBS.req( "CreateInput", JSON.parse(reqdata.to_json) ) ) # maybe block until the event comes in? # will have to depend on the @eventsubscription state if d["requestStatus"]["result"].as_bool # success? @@ -812,17 +812,17 @@ module OBS end end def enable! - @obs.send_sync( OBS.req( "SetSceneItemEnabled", data: JSON.parse( { "sceneName" => @scenename, "sceneItemId" => @id, "sceneItemEnabled" => true }.to_json ) ) ) + @obs.send_sync( OBS.req( "SetSceneItemEnabled", JSON.parse( { "sceneName" => @scenename, "sceneItemId" => @id, "sceneItemEnabled" => true }.to_json ) ) ) end def disable! - @obs.send_sync( OBS.req( "SetSceneItemEnabled", data: JSON.parse( { "sceneName" => @scenename, "sceneItemId" => @id, "sceneItemEnabled" => false }.to_json ) ) ) + @obs.send_sync( OBS.req( "SetSceneItemEnabled", JSON.parse( { "sceneName" => @scenename, "sceneItemId" => @id, "sceneItemEnabled" => false }.to_json ) ) ) end def transform( newtransform : OBS::SceneItemTransform | Hash( String, String | Bool | Int64 | Float64 ) ) reqdata = ( Hash( String, String | Bool | Int64 | Float64 | Hash( String, String | Bool | Int64 | Float64 ) ) ).new reqdata["sceneItemId"] = @id.to_i64 reqdata["sceneName"] = @scenename reqdata["sceneItemTransform"] = Hash( String, String | Bool | Int64 | Float64).new.merge( newtransform.to_h ) - @obs.send_sync( OBS.req( "SetSceneItemTransform", data: JSON.parse(reqdata.to_json) ) ) + @obs.send_sync( OBS.req( "SetSceneItemTransform", JSON.parse(reqdata.to_json) ) ) end end @@ -832,7 +832,7 @@ module OBS @sceneitemtransform = Hash(String, String | Bool | Int64 | Float64 ).from_json(json.to_json) end def populate - d = @obs.send_sync( OBS.req( "GetSceneItemTransform", data: JSON.parse( { "sceneName" => @sceneitemname, "sceneItemId" => @sceneitemid }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "GetSceneItemTransform", JSON.parse( { "sceneName" => @sceneitemname, "sceneItemId" => @sceneitemid }.to_json ) ) ) if ( rdata = d["responseData"]? ) @sceneitemtransform = Hash(String, String | Bool | Int64 | Float64 ).from_json(rdata["sceneItemTransform"].to_json) else @@ -933,7 +933,7 @@ module OBS @filters = OBS::SourceFilters.new( @obs, @name ) end def delete!( ) - @obs.send_sync( OBS.req( "RemoveInput", data: JSON.parse({ "inputName" => @name }.to_json) ) ) + @obs.send_sync( OBS.req( "RemoveInput", JSON.parse({ "inputName" => @name }.to_json) ) ) end def namecache( name : String ) @name = name @@ -954,7 +954,7 @@ module OBS def initialize( @obs : OBS::WebSocket, @name : String, @inputkind : String, @inputsettings : Hash( String, String | Bool | Int64 | Float64 ) ) end def populate - d = @obs.send_sync( OBS.req( "GetInputSettings", data: JSON.parse( { "inputName" => @name }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "GetInputSettings", JSON.parse( { "inputName" => @name }.to_json ) ) ) if ( rdata = d["responseData"]? ) @inputsettings = Hash(String, String | Bool | Int64 | Float64 ).from_json(rdata["inputSettings"].to_json) @inputkind = rdata["inputKind"].as_s @@ -986,7 +986,7 @@ module OBS def initialize( @obs : OBS::WebSocket, @sourcename : String ) end def populate - d = @obs.send_sync( OBS.req( "GetSourceFilterList", data: JSON.parse( { "sourceName" => @sourcename }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "GetSourceFilterList", JSON.parse( { "sourceName" => @sourcename }.to_json ) ) ) if ( rdata = d["responseData"]? ) rdata["filters"].as_a.each do | filter | name = filter["filterName"].as_s @@ -1036,11 +1036,11 @@ module OBS end end def enable! - d = @obs.send_sync( OBS.req( "SetSourceFilterEnabled", data: JSON.parse( { "sourceName" => @sourcename, "filterName" => @name, "filterEnabled" => true }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "SetSourceFilterEnabled", JSON.parse( { "sourceName" => @sourcename, "filterName" => @name, "filterEnabled" => true }.to_json ) ) ) return d["requestStatus"]["result"].as_bool end def disable! - d = @obs.send_sync( OBS.req( "SetSourceFilterEnabled", data: JSON.parse( { "sourceName" => @sourcename, "filterName" => @name, "filterEnabled" => false }.to_json ) ) ) + d = @obs.send_sync( OBS.req( "SetSourceFilterEnabled", JSON.parse( { "sourceName" => @sourcename, "filterName" => @name, "filterEnabled" => false }.to_json ) ) ) return d["requestStatus"]["result"].as_bool end def enabledcache( bool : Bool ) |