mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2025-04-04 12:23:45 +01:00
Compare commits
7 Commits
976c8f19a8
...
dc8ac155ec
Author | SHA1 | Date | |
---|---|---|---|
dc8ac155ec | |||
23d64ef9d8 | |||
9be9dc80a2 | |||
a40ab77be9 | |||
b440ace20c | |||
f5a817ab4e | |||
13f57f79f6 |
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
obsws (0.5.0)
|
obsws (0.5.3)
|
||||||
waitutil (~> 0.2.1)
|
waitutil (~> 0.2.1)
|
||||||
websocket-driver (~> 0.7.5)
|
websocket-driver (~> 0.7.5)
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ If a connection attempt fails or times out an `OBSWSConnectionError` will be rai
|
|||||||
|
|
||||||
If a request fails an `OBSWSRequestError` will be raised with a status code.
|
If a request fails an `OBSWSRequestError` will be raised with a status code.
|
||||||
|
|
||||||
- The request name and code are retrievable through attributes {OBSWSRequestError}.name and {OBSWSRequestError}.code
|
- The request name and code are retrievable through attributes {OBSWSRequestError}.req_name and {OBSWSRequestError}.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)
|
||||||
|
|
||||||
|
30
Rakefile
30
Rakefile
@ -5,19 +5,25 @@ HERE = __dir__
|
|||||||
Minitest::TestTask.create(:test) do |t|
|
Minitest::TestTask.create(:test) do |t|
|
||||||
t.libs << "test"
|
t.libs << "test"
|
||||||
t.warning = false
|
t.warning = false
|
||||||
t.test_globs = ["test/**/*_test.rb"]
|
t.test_globs = ["test/**/test_*.rb"]
|
||||||
end
|
end
|
||||||
|
|
||||||
task default: :test
|
task default: :test
|
||||||
task :events do
|
|
||||||
filepath = File.join(HERE, "examples", "events", "main.rb")
|
namespace :e do
|
||||||
ruby filepath
|
desc "Runs the events example"
|
||||||
end
|
task :events do
|
||||||
task :levels do
|
filepath = File.join(HERE, "examples", "events", "main.rb")
|
||||||
filepath = File.join(HERE, "examples", "levels", "main.rb")
|
ruby filepath
|
||||||
ruby filepath
|
end
|
||||||
end
|
desc "Runs the levels example"
|
||||||
task :scene_rotate do
|
task :levels do
|
||||||
filepath = File.join(HERE, "examples", "scene_rotate", "main.rb")
|
filepath = File.join(HERE, "examples", "levels", "main.rb")
|
||||||
ruby filepath
|
ruby filepath
|
||||||
|
end
|
||||||
|
desc "Runs the scene_rotate example"
|
||||||
|
task :scene_rotate do
|
||||||
|
filepath = File.join(HERE, "examples", "scene_rotate", "main.rb")
|
||||||
|
ruby filepath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,10 +22,10 @@ module OBSWS
|
|||||||
class OBSWSConnectionError < OBSWSError; end
|
class OBSWSConnectionError < OBSWSError; end
|
||||||
|
|
||||||
class OBSWSRequestError < OBSWSError
|
class OBSWSRequestError < OBSWSError
|
||||||
attr_reader :name, :code
|
attr_reader :req_name, :code
|
||||||
|
|
||||||
def initialize(name, code, msg)
|
def initialize(req_name, code, msg)
|
||||||
@name = name
|
@req_name = req_name
|
||||||
@code = code
|
@code = code
|
||||||
@msg = msg
|
@msg = msg
|
||||||
super(message)
|
super(message)
|
||||||
@ -33,7 +33,7 @@ module OBSWS
|
|||||||
|
|
||||||
def message
|
def message
|
||||||
msg = [
|
msg = [
|
||||||
"Request #{@name} returned code #{@code}."
|
"Request #{@req_name} returned code #{@code}."
|
||||||
]
|
]
|
||||||
msg << "With message: #{@msg}" if @msg
|
msg << "With message: #{@msg}" if @msg
|
||||||
msg.join(" ")
|
msg.join(" ")
|
||||||
|
@ -12,11 +12,12 @@ module OBSWS
|
|||||||
port = kwargs[:port] || 4455
|
port = kwargs[:port] || 4455
|
||||||
@password = kwargs[:password] || ""
|
@password = kwargs[:password] || ""
|
||||||
@subs = kwargs[:subs] || 0
|
@subs = kwargs[:subs] || 0
|
||||||
|
@connect_timeout = kwargs[:connect_timeout] || 3
|
||||||
setup_driver(host, port) and start_driver
|
setup_driver(host, port) and start_driver
|
||||||
WaitUtil.wait_for_condition(
|
WaitUtil.wait_for_condition(
|
||||||
"successful identification",
|
"successful identification",
|
||||||
delay_sec: 0.01,
|
delay_sec: 0.01,
|
||||||
timeout_sec: 3
|
timeout_sec: @connect_timeout
|
||||||
) { @identified }
|
) { @identified }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,9 +9,8 @@ module OBSWS
|
|||||||
@base_client = Base.new(**kwargs)
|
@base_client = Base.new(**kwargs)
|
||||||
logger.info("#{self} successfully identified with server")
|
logger.info("#{self} successfully identified with server")
|
||||||
rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
|
rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
|
||||||
msg = "#{e.class.name}: #{e.message}"
|
logger.error("#{e.class.name}: #{e.message}")
|
||||||
logger.error(msg)
|
raise OBSWSConnectionError.new(e.message)
|
||||||
raise OBSWSConnectionError.new(msg)
|
|
||||||
else
|
else
|
||||||
@base_client.updater = ->(op_code, data) {
|
@base_client.updater = ->(op_code, data) {
|
||||||
logger.debug("response received: #{data}")
|
logger.debug("response received: #{data}")
|
||||||
@ -48,19 +47,11 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
@response[:responseData]
|
@response[:responseData]
|
||||||
rescue OBSWSRequestError => e
|
rescue OBSWSRequestError => e
|
||||||
err_msg = [
|
logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
|
||||||
"#{e.class.name}: #{e.message}",
|
|
||||||
*e.backtrace
|
|
||||||
]
|
|
||||||
logger.error(err_msg.join("\n"))
|
|
||||||
raise
|
raise
|
||||||
rescue WaitUtil::TimeoutError => e
|
rescue WaitUtil::TimeoutError => e
|
||||||
err_msg = [
|
logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
|
||||||
"#{e.class.name}: #{e.message}",
|
raise OBSWSError.new([e.message, *e.backtrace].join("\n"))
|
||||||
*e.backtrace
|
|
||||||
]
|
|
||||||
logger.error(err_msg)
|
|
||||||
raise OBSWSError.new(err_msg)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_version
|
def get_version
|
||||||
|
@ -11,7 +11,7 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def patch
|
def patch
|
||||||
0
|
4
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
|
2
main.rb
2
main.rb
@ -1,4 +1,4 @@
|
|||||||
require_relative "lib/obsws"
|
require "obsws"
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
def run
|
def run
|
||||||
|
17
test/obsws/test_error.rb
Normal file
17
test/obsws/test_error.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
require_relative "../minitest_helper"
|
||||||
|
|
||||||
|
class OBSWSConnectionErrorTest < Minitest::Test
|
||||||
|
def test_it_raises_an_obsws_connection_error_on_wrong_password
|
||||||
|
e = assert_raises(OBSWS::OBSWSConnectionError) { OBSWS::Requests::Client.new(host: "localhost", port: 4455, password: "wrongpassword", connect_timeout: 1).new }
|
||||||
|
assert_equal(e.message, "Timed out waiting for successful identification (1 seconds elapsed)")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class OBSWSRequestErrorTest < Minitest::Test
|
||||||
|
def test_it_raises_an_obsws_request_error_on_invalid_request
|
||||||
|
e = assert_raises(OBSWS::OBSWSRequestError) { OBSWSTest.r_client.toggle_input_mute("unknown") }
|
||||||
|
assert_equal(e.req_name, "ToggleInputMute")
|
||||||
|
assert_equal(e.code, 600)
|
||||||
|
assert_equal(e.message, "Request ToggleInputMute returned code 600. With message: No source was found by the name of `unknown`.")
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user