mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2024-11-15 18:50:47 +00:00
patch bump
add full request payload to logger. raise OBSWSError if auth enabled but no password provided add example tasks to rake file add logging section to README
This commit is contained in:
parent
43ecfb37f5
commit
aafcd185d0
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
obsws (0.1.1)
|
obsws (0.1.2)
|
||||||
observer (~> 0.1.1)
|
observer (~> 0.1.1)
|
||||||
waitutil (~> 0.2.1)
|
waitutil (~> 0.2.1)
|
||||||
websocket-driver (~> 0.7.5)
|
websocket-driver (~> 0.7.5)
|
||||||
|
13
README.md
13
README.md
@ -115,6 +115,19 @@ If a request fails an `OBSWSError` will be raised with a status code.
|
|||||||
|
|
||||||
For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
|
||||||
|
To see the raw messages set log level to debug
|
||||||
|
|
||||||
|
example:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
require "obsws"
|
||||||
|
|
||||||
|
OBSWS::LOGGER.debug!
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
To run all tests:
|
To run all tests:
|
||||||
|
14
Rakefile
14
Rakefile
@ -1,5 +1,7 @@
|
|||||||
require "minitest/test_task"
|
require "minitest/test_task"
|
||||||
|
|
||||||
|
HERE = File.expand_path File.dirname(__FILE__)
|
||||||
|
|
||||||
Minitest::TestTask.create(:test) do |t|
|
Minitest::TestTask.create(:test) do |t|
|
||||||
t.libs << "test"
|
t.libs << "test"
|
||||||
t.warning = false
|
t.warning = false
|
||||||
@ -7,3 +9,15 @@ Minitest::TestTask.create(:test) do |t|
|
|||||||
end
|
end
|
||||||
|
|
||||||
task default: :test
|
task default: :test
|
||||||
|
task :events do
|
||||||
|
filepath = File.join(HERE, "examples", "events", "main.rb")
|
||||||
|
ruby filepath
|
||||||
|
end
|
||||||
|
task :levels do
|
||||||
|
filepath = File.join(HERE, "examples", "levels", "main.rb")
|
||||||
|
ruby filepath
|
||||||
|
end
|
||||||
|
task :scene_rotate do
|
||||||
|
filepath = File.join(HERE, "examples", "scene_rotate", "main.rb")
|
||||||
|
ruby filepath
|
||||||
|
end
|
||||||
|
@ -45,12 +45,12 @@ module OBSWS
|
|||||||
@closed = true
|
@closed = true
|
||||||
end
|
end
|
||||||
@driver.on :message do |msg|
|
@driver.on :message do |msg|
|
||||||
LOGGER.debug("received [#{msg}] passing to handler")
|
LOGGER.debug("received: #{msg.data}")
|
||||||
msg_handler(JSON.parse(msg.data, symbolize_names: true))
|
msg_handler(JSON.parse(msg.data, symbolize_names: true))
|
||||||
end
|
end
|
||||||
start_driver
|
start_driver
|
||||||
WaitUtil.wait_for_condition(
|
WaitUtil.wait_for_condition(
|
||||||
"waiting successful identification",
|
"successful identification",
|
||||||
delay_sec: 0.01,
|
delay_sec: 0.01,
|
||||||
timeout_sec: 3
|
timeout_sec: 3
|
||||||
) { @identified }
|
) { @identified }
|
||||||
@ -75,7 +75,11 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def identify(auth)
|
def identify(auth)
|
||||||
LOGGER.info("initiating authentication") if auth
|
if auth
|
||||||
|
if @password.empty?
|
||||||
|
raise OBSWSError("auth enabled but no password provided")
|
||||||
|
end
|
||||||
|
LOGGER.info("initiating authentication")
|
||||||
payload = {
|
payload = {
|
||||||
op: Mixin::OPCodes::IDENTIFY,
|
op: Mixin::OPCodes::IDENTIFY,
|
||||||
d: {
|
d: {
|
||||||
@ -83,7 +87,8 @@ module OBSWS
|
|||||||
eventSubscriptions: @subs
|
eventSubscriptions: @subs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
payload[:d][:authentication] = auth_token(**auth) if auth
|
payload[:d][:authentication] = auth_token(**auth)
|
||||||
|
end
|
||||||
@driver.text(JSON.generate(payload))
|
@driver.text(JSON.generate(payload))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -108,8 +113,8 @@ module OBSWS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
payload[:d][:requestData] = data if data
|
payload[:d][:requestData] = data if data
|
||||||
|
LOGGER.debug("sending request: #{payload}")
|
||||||
queued = @driver.text(JSON.generate(payload))
|
queued = @driver.text(JSON.generate(payload))
|
||||||
LOGGER.debug("request with id #{id} queued? #{queued}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ module OBSWS
|
|||||||
ensure
|
ensure
|
||||||
close
|
close
|
||||||
WaitUtil.wait_for_condition(
|
WaitUtil.wait_for_condition(
|
||||||
"driver has closed",
|
"driver to close",
|
||||||
delay_sec: 0.01,
|
delay_sec: 0.01,
|
||||||
timeout_sec: 1
|
timeout_sec: 1
|
||||||
) { @base_client.closed }
|
) { @base_client.closed }
|
||||||
@ -42,7 +42,7 @@ module OBSWS
|
|||||||
id = rand(1..1000)
|
id = rand(1..1000)
|
||||||
@base_client.req(id, req, data)
|
@base_client.req(id, req, data)
|
||||||
WaitUtil.wait_for_condition(
|
WaitUtil.wait_for_condition(
|
||||||
"reponse id matches request id",
|
"reponse id to match request id",
|
||||||
delay_sec: 0.001,
|
delay_sec: 0.001,
|
||||||
timeout_sec: 3
|
timeout_sec: 3
|
||||||
) { @response[:requestId] == id }
|
) { @response[:requestId] == id }
|
||||||
|
@ -11,7 +11,7 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def patch
|
def patch
|
||||||
1
|
2
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
|
Loading…
Reference in New Issue
Block a user