mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2026-04-09 09:53:29 +00:00
Compare commits
39 Commits
dc8ac155ec
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c892623fa | |||
|
|
92b36ecce4 | ||
| 1dc8bf10f7 | |||
|
|
426a7d6628 | ||
| e1146913f9 | |||
|
|
78ca03e610 | ||
| 03174b9e40 | |||
|
|
63dd131d61 | ||
| 6ffae8e6c7 | |||
|
|
2878c31819 | ||
| 2e774ef185 | |||
|
|
3e661b23a3 | ||
| fac83a0dde | |||
| 4c4746fe8a | |||
| 3a0f298045 | |||
| a4b70b6a98 | |||
| 7c20063866 | |||
| 7cf05fbe08 | |||
| 587e861bbe | |||
| 3f255d6b45 | |||
| 9bd2b53b3d | |||
| 61c9a7b365 | |||
| daa8c6ada1 | |||
| 662f14282f | |||
| 2e0e584d3a | |||
| a8425cf7cd | |||
| 7e580dc91a | |||
| 92174219a7 | |||
| 0c71eb2398 | |||
| 3ea21cd371 | |||
| 70b60b3cac | |||
| c97d14abe2 | |||
| 123b9c55ca | |||
| 299351cac0 | |||
| 3ef4396885 | |||
| c6bb8d07ff | |||
| 48b94a2682 | |||
| 210d13ba1e | |||
| 59bcf2a338 |
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
obsws (0.5.3)
|
||||
obsws (0.6.2)
|
||||
waitutil (~> 0.2.1)
|
||||
websocket-driver (~> 0.7.5)
|
||||
|
||||
@@ -19,9 +19,9 @@ GEM
|
||||
racc
|
||||
racc (1.7.1)
|
||||
rainbow (3.1.1)
|
||||
rake (11.3.0)
|
||||
rake (13.0.6)
|
||||
regexp_parser (2.8.1)
|
||||
rexml (3.2.5)
|
||||
rexml (3.4.2)
|
||||
rubocop (1.52.1)
|
||||
json (~> 2.3)
|
||||
parallel (~> 1.10)
|
||||
@@ -58,11 +58,12 @@ GEM
|
||||
|
||||
PLATFORMS
|
||||
x64-mingw-ucrt
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
minitest (~> 5.16, >= 5.16.3)
|
||||
obsws!
|
||||
rake (~> 11.2, >= 11.2.2)
|
||||
rake (~> 13.0, >= 11.2.2)
|
||||
standard (~> 1.30)
|
||||
|
||||
BUNDLED WITH
|
||||
|
||||
48
README.md
48
README.md
@@ -30,13 +30,17 @@ Pass `host`, `port` and `password` as keyword arguments.
|
||||
require "obsws"
|
||||
|
||||
class Main
|
||||
INPUT = "Mic/Aux"
|
||||
|
||||
def run
|
||||
OBSWS::Requests::Client
|
||||
.new(host: "localhost", port: 4455, password: "strongpassword")
|
||||
.run do |client|
|
||||
# Toggle the mute state of your Mic input
|
||||
client.toggle_input_mute("Mic/Aux")
|
||||
end
|
||||
# Toggle the mute state of your Mic input and print its new mute state
|
||||
client.toggle_input_mute(INPUT)
|
||||
resp = client.get_input_mute(INPUT)
|
||||
puts "Input '#{INPUT}' was set to #{resp.input_muted}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,7 +67,9 @@ For a full list of requests refer to [Requests](https://github.com/obsproject/ob
|
||||
|
||||
### Events
|
||||
|
||||
Register `on_` callback methods. Method names should match the api event but snake cased.
|
||||
Register blocks with the Event client using the `on` method. Event tokens should match the event name but snake cased.
|
||||
|
||||
The event data will be passed to the block.
|
||||
|
||||
example:
|
||||
|
||||
@@ -71,23 +77,14 @@ example:
|
||||
class Observer
|
||||
def initialize
|
||||
@e_client = OBSWS::Events::Client.new(host: "localhost", port: 4455, password: "strongpassword")
|
||||
# register callback methods with the Event client
|
||||
@e_client.register(
|
||||
[
|
||||
method(:on_current_program_scene_changed),
|
||||
method(:on_input_mute_state_changed)
|
||||
]
|
||||
)
|
||||
# register blocks on event types.
|
||||
@e_client.on :current_program_scene_changed do |data|
|
||||
...
|
||||
end
|
||||
@e_client.on :input_mute_state_changed do |data|
|
||||
...
|
||||
end
|
||||
end
|
||||
|
||||
# define "on_" event methods.
|
||||
def on_current_program_scene_changed(data)
|
||||
...
|
||||
end
|
||||
def on_input_mute_state_changed(data)
|
||||
...
|
||||
end
|
||||
...
|
||||
end
|
||||
```
|
||||
|
||||
@@ -100,11 +97,12 @@ For both request responses and event data you may inspect the available attribut
|
||||
example:
|
||||
|
||||
```ruby
|
||||
resp = cl.get_version
|
||||
resp = @r_client.get_version
|
||||
p resp.attrs
|
||||
|
||||
def on_scene_created(data):
|
||||
p data.attrs
|
||||
@e_client.on :input_mute_state_changed do |data|
|
||||
p data.attrs
|
||||
end
|
||||
```
|
||||
|
||||
### Errors
|
||||
@@ -115,7 +113,9 @@ 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.
|
||||
|
||||
- The request name and code are retrievable through attributes {OBSWSRequestError}.req_name and {OBSWSRequestError}.code
|
||||
- The request name and code are retrievable through the following attributes:
|
||||
- `req_name`
|
||||
- `code`
|
||||
|
||||
For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus)
|
||||
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
require_relative "../../lib/obsws"
|
||||
require "yaml"
|
||||
|
||||
|
||||
class Main
|
||||
attr_reader :running
|
||||
|
||||
def initialize(**kwargs)
|
||||
@r_client = OBSWS::Requests::Client.new(**kwargs)
|
||||
@e_client = OBSWS::Events::Client.new(**kwargs)
|
||||
@e_client.add_observer(self)
|
||||
|
||||
@e_client.on :current_program_scene_changed do |data|
|
||||
puts "Switched to scene #{data.scene_name}"
|
||||
end
|
||||
@e_client.on :scene_created do |data|
|
||||
puts "scene #{data.scene_name} has been created"
|
||||
end
|
||||
@e_client.on :input_mute_state_changed do |data|
|
||||
puts "#{data.input_name} mute toggled"
|
||||
end
|
||||
@e_client.on :exit_started do
|
||||
puts "OBS closing!"
|
||||
@r_client.close
|
||||
@e_client.close
|
||||
@running = false
|
||||
end
|
||||
|
||||
puts infostring
|
||||
@running = true
|
||||
end
|
||||
|
||||
def run
|
||||
sleep(0.1) while running
|
||||
end
|
||||
|
||||
def infostring
|
||||
@@ -26,23 +33,9 @@ class Main
|
||||
].join(" ")
|
||||
end
|
||||
|
||||
def on_current_program_scene_changed(data)
|
||||
puts "Switched to scene #{data.scene_name}"
|
||||
end
|
||||
|
||||
def on_scene_created(data)
|
||||
puts "scene #{data.scene_name} has been created"
|
||||
end
|
||||
|
||||
def on_input_mute_state_changed(data)
|
||||
puts "#{data.input_name} mute toggled"
|
||||
end
|
||||
|
||||
def on_exit_started
|
||||
puts "OBS closing!"
|
||||
@r_client.close
|
||||
@e_client.close
|
||||
@running = false
|
||||
def run
|
||||
@running = true
|
||||
sleep(0.1) while @running
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -13,36 +13,29 @@ class Main
|
||||
def initialize(**kwargs)
|
||||
subs = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS
|
||||
@e_client = OBSWS::Events::Client.new(subs:, **kwargs)
|
||||
@e_client.register(
|
||||
[
|
||||
method(:on_input_mute_state_changed),
|
||||
method(:on_input_volume_meters)
|
||||
]
|
||||
)
|
||||
|
||||
@e_client.on :input_mute_state_changed do |data|
|
||||
if data.input_name == DEVICE
|
||||
puts "#{DEVICE} mute toggled"
|
||||
end
|
||||
end
|
||||
@e_client.on :input_volume_meters do |data|
|
||||
fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
|
||||
|
||||
data.inputs.each do |d|
|
||||
name = d[:inputName]
|
||||
if name == DEVICE && !d[:inputLevelsMul].empty?
|
||||
left, right = d[:inputLevelsMul]
|
||||
puts "#{name} [L: #{fget.call(left[LevelTypes::POSTFADER])}, R: #{fget.call(right[LevelTypes::POSTFADER])}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
puts "press <Enter> to quit"
|
||||
loop { break if gets.chomp.empty? }
|
||||
end
|
||||
|
||||
def on_input_mute_state_changed(data)
|
||||
if data.input_name == DEVICE
|
||||
puts "#{DEVICE} mute toggled"
|
||||
end
|
||||
end
|
||||
|
||||
def on_input_volume_meters(data)
|
||||
fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
|
||||
|
||||
data.inputs.each do |d|
|
||||
name = d[:inputName]
|
||||
if name == DEVICE && !d[:inputLevelsMul].empty?
|
||||
left, right = d[:inputLevelsMul]
|
||||
puts "#{name} [L: #{fget.call(left[LevelTypes::POSTFADER])}, R: #{fget.call(right[LevelTypes::POSTFADER])}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def conn_from_yaml
|
||||
|
||||
23
lib/obsws.rb
23
lib/obsws.rb
@@ -1,9 +1,10 @@
|
||||
require "digest/sha2"
|
||||
require "json"
|
||||
require "waitutil"
|
||||
require "socket"
|
||||
require "websocket/driver"
|
||||
require "logger"
|
||||
require "securerandom"
|
||||
require "socket"
|
||||
require "waitutil"
|
||||
require "websocket/driver"
|
||||
|
||||
require_relative "obsws/logger"
|
||||
require_relative "obsws/driver"
|
||||
@@ -17,26 +18,22 @@ require_relative "obsws/event"
|
||||
require_relative "obsws/version"
|
||||
|
||||
module OBSWS
|
||||
# Base OBSWS error class
|
||||
class OBSWSError < StandardError; end
|
||||
|
||||
# Raised when a connection fails or times out
|
||||
class OBSWSConnectionError < OBSWSError; end
|
||||
|
||||
# Raised when a request returns an error code
|
||||
class OBSWSRequestError < OBSWSError
|
||||
attr_reader :req_name, :code
|
||||
|
||||
def initialize(req_name, code, msg)
|
||||
def initialize(req_name, code, comment)
|
||||
@req_name = req_name
|
||||
@code = code
|
||||
@msg = msg
|
||||
message = "Request #{@req_name} returned code #{@code}."
|
||||
message << " With message: #{comment}" if comment
|
||||
super(message)
|
||||
end
|
||||
|
||||
def message
|
||||
msg = [
|
||||
"Request #{@req_name} returned code #{@code}."
|
||||
]
|
||||
msg << "With message: #{@msg}" if @msg
|
||||
msg.join(" ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
module OBSWS
|
||||
class Identified
|
||||
attr_accessor :state
|
||||
|
||||
def initialize
|
||||
@state = :pending
|
||||
end
|
||||
|
||||
def error_message
|
||||
case @state
|
||||
when :passwordless
|
||||
"auth enabled but no password provided"
|
||||
else
|
||||
"failed to identify client with the websocket server"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Base
|
||||
include Logging
|
||||
include Driver::Director
|
||||
include Mixin::OPCodes
|
||||
|
||||
attr_reader :closed
|
||||
attr_reader :closed, :identified
|
||||
attr_writer :updater
|
||||
|
||||
def initialize(**kwargs)
|
||||
@@ -12,13 +29,13 @@ module OBSWS
|
||||
port = kwargs[:port] || 4455
|
||||
@password = kwargs[:password] || ""
|
||||
@subs = kwargs[:subs] || 0
|
||||
@connect_timeout = kwargs[:connect_timeout] || 3
|
||||
@identified = Identified.new
|
||||
setup_driver(host, port) and start_driver
|
||||
WaitUtil.wait_for_condition(
|
||||
"successful identification",
|
||||
delay_sec: 0.01,
|
||||
timeout_sec: @connect_timeout
|
||||
) { @identified }
|
||||
timeout_sec: kwargs[:connect_timeout] || 3
|
||||
) { @identified.state != :pending }
|
||||
end
|
||||
|
||||
private
|
||||
@@ -39,7 +56,8 @@ module OBSWS
|
||||
}
|
||||
if auth
|
||||
if @password.empty?
|
||||
raise OBSWSError("auth enabled but no password provided")
|
||||
@identified.state = :passwordless
|
||||
return
|
||||
end
|
||||
logger.info("initiating authentication")
|
||||
payload[:d][:authentication] = auth_token(**auth)
|
||||
@@ -52,7 +70,7 @@ module OBSWS
|
||||
when Mixin::OPCodes::HELLO
|
||||
identify(data[:d][:authentication])
|
||||
when Mixin::OPCodes::IDENTIFIED
|
||||
@identified = true
|
||||
@identified.state = :identified
|
||||
when Mixin::OPCodes::EVENT, Mixin::OPCodes::REQUESTRESPONSE
|
||||
@updater.call(data[:op], data[:d])
|
||||
end
|
||||
|
||||
@@ -28,49 +28,46 @@ module OBSWS
|
||||
ALL = LOW_VOLUME | HIGH_VOLUME
|
||||
end
|
||||
|
||||
module Callbacks
|
||||
include Util::String
|
||||
module Director
|
||||
using Util::CoreExtensions
|
||||
|
||||
def observers
|
||||
@observers ||= []
|
||||
@observers ||= {}
|
||||
end
|
||||
|
||||
def add_observer(observer)
|
||||
observer = [observer] unless observer.respond_to? :each
|
||||
observer.each { |o| observers << o unless observers.include? o }
|
||||
def on(event, method = nil, &block)
|
||||
(observers[event] ||= []) << (block || method)
|
||||
end
|
||||
|
||||
def remove_observer(observer)
|
||||
observer = [observer] unless observer.respond_to? :each
|
||||
observers.reject! { |o| observer.include? o }
|
||||
def register(cbs)
|
||||
cbs = Array(cbs) unless cbs.respond_to? :each
|
||||
cbs.each { |cb| on(cb.name[3..].to_sym, cb) }
|
||||
end
|
||||
|
||||
private def notify_observers(event, data)
|
||||
observers.each do |o|
|
||||
if o.is_a? Method
|
||||
if o.name.to_s == "on_#{snakecase(event)}"
|
||||
data.empty? ? o.call : o.call(data)
|
||||
end
|
||||
elsif o.respond_to? "on_#{snakecase(event)}"
|
||||
data.empty? ? o.send("on_#{snakecase(event)}") : o.send("on_#{snakecase(event)}", data)
|
||||
end
|
||||
end
|
||||
def deregister(cbs)
|
||||
cbs = Array(cbs) unless cbs.respond_to? :each
|
||||
cbs.each { |cb| observers[cb.name[3..].to_sym]&.reject! { |o| cbs.include? o } }
|
||||
end
|
||||
|
||||
alias_method :callbacks, :observers
|
||||
alias_method :register, :add_observer
|
||||
alias_method :deregister, :remove_observer
|
||||
def fire(event, data)
|
||||
observers[event.snakecase.to_sym]&.each { |block| data.empty? ? block.call : block.call(data) }
|
||||
end
|
||||
end
|
||||
|
||||
class Client
|
||||
include Logging
|
||||
include Callbacks
|
||||
include Events::Director
|
||||
include Mixin::TearDown
|
||||
include Mixin::OPCodes
|
||||
|
||||
def initialize(**kwargs)
|
||||
kwargs[:subs] ||= SUBS::LOW_VOLUME
|
||||
@base_client = Base.new(**kwargs)
|
||||
unless @base_client.identified.state == :identified
|
||||
err_msg = @base_client.identified.error_message
|
||||
logger.error(err_msg)
|
||||
raise OBSWSConnectionError.new(err_msg)
|
||||
end
|
||||
logger.info("#{self} successfully identified with server")
|
||||
rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
|
||||
msg = "#{e.class.name}: #{e.message}"
|
||||
@@ -82,7 +79,7 @@ module OBSWS
|
||||
logger.debug("received: #{data}")
|
||||
event = data[:eventType]
|
||||
data = data.fetch(:eventData, {})
|
||||
notify_observers(event, Mixin::Data.new(data, data.keys))
|
||||
fire(event, Mixin::Data.new(data, data.keys))
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
module OBSWS
|
||||
module Mixin
|
||||
module Meta
|
||||
include Util::String
|
||||
using Util::CoreExtensions
|
||||
|
||||
def make_field_methods(*params)
|
||||
params.each do |param|
|
||||
define_singleton_method(snakecase(param.to_s)) { @resp[param] }
|
||||
define_singleton_method(param.to_s.snakecase) { @resp[param] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MetaObject
|
||||
using Util::CoreExtensions
|
||||
include Mixin::Meta
|
||||
|
||||
def initialize(resp, fields)
|
||||
@@ -21,14 +22,14 @@ module OBSWS
|
||||
|
||||
def empty? = @fields.empty?
|
||||
|
||||
def attrs = @fields.map { |f| snakecase(f.to_s) }
|
||||
def attrs = @fields.map { |f| f.to_s.snakecase }
|
||||
end
|
||||
|
||||
class Response < MetaObject; end
|
||||
# Represents a request response object
|
||||
class Response < MetaObject; end
|
||||
|
||||
class Data < MetaObject; end
|
||||
# Represents an event data object
|
||||
class Data < MetaObject; end
|
||||
|
||||
module TearDown
|
||||
def stop_driver
|
||||
|
||||
@@ -7,6 +7,11 @@ module OBSWS
|
||||
|
||||
def initialize(**kwargs)
|
||||
@base_client = Base.new(**kwargs)
|
||||
unless @base_client.identified.state == :identified
|
||||
err_msg = @base_client.identified.error_message
|
||||
logger.error(err_msg)
|
||||
raise OBSWSConnectionError.new(err_msg)
|
||||
end
|
||||
logger.info("#{self} successfully identified with server")
|
||||
rescue Errno::ECONNREFUSED, WaitUtil::TimeoutError => e
|
||||
logger.error("#{e.class.name}: #{e.message}")
|
||||
@@ -35,13 +40,13 @@ module OBSWS
|
||||
end
|
||||
|
||||
def call(req, data = nil)
|
||||
id = rand(1..1000)
|
||||
@base_client.req(id, req, data)
|
||||
uuid = SecureRandom.uuid
|
||||
@base_client.req(uuid, req, data)
|
||||
WaitUtil.wait_for_condition(
|
||||
"reponse id to match request id",
|
||||
delay_sec: 0.001,
|
||||
timeout_sec: 3
|
||||
) { @response[:requestId] == id }
|
||||
) { @response[:requestId] == uuid }
|
||||
unless @response[:requestStatus][:result]
|
||||
raise OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment])
|
||||
end
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
module OBSWS
|
||||
module Util
|
||||
module String
|
||||
def camelcase(s)
|
||||
s.split("_").map(&:capitalize).join
|
||||
end
|
||||
module CoreExtensions
|
||||
refine String do
|
||||
def camelcase
|
||||
split("_").map(&:capitalize).join
|
||||
end
|
||||
|
||||
def snakecase(s)
|
||||
s
|
||||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
.downcase
|
||||
def snakecase
|
||||
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
.downcase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,11 +7,11 @@ module OBSWS
|
||||
end
|
||||
|
||||
def minor
|
||||
5
|
||||
6
|
||||
end
|
||||
|
||||
def patch
|
||||
4
|
||||
2
|
||||
end
|
||||
|
||||
def to_a
|
||||
|
||||
16
main.rb
16
main.rb
@@ -1,14 +1,16 @@
|
||||
require "obsws"
|
||||
|
||||
class Main
|
||||
INPUT = "Mic/Aux"
|
||||
|
||||
def run
|
||||
OBSWS::Requests::Client.new(
|
||||
host: "localhost",
|
||||
port: 4455,
|
||||
password: "strongpassword"
|
||||
).run do |client|
|
||||
# Toggle the mute state of your Mic input
|
||||
client.toggle_input_mute("Mic/Aux")
|
||||
OBSWS::Requests::Client
|
||||
.new(host: "localhost", port: 4455, password: "strongpassword")
|
||||
.run do |client|
|
||||
# Toggle the mute state of your Mic input and print its new mute state
|
||||
client.toggle_input_mute(INPUT)
|
||||
resp = client.get_input_mute(INPUT)
|
||||
puts "Input '#{INPUT}' was set to #{resp.input_muted}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
||||
spec.add_runtime_dependency "waitutil", "~> 0.2.1"
|
||||
spec.add_development_dependency "standard", "~> 1.30"
|
||||
spec.add_development_dependency "minitest", "~> 5.16", ">= 5.16.3"
|
||||
spec.add_development_dependency "rake", "~> 11.2", ">= 11.2.2"
|
||||
spec.add_development_dependency "rake", ">= 11.2.2", "~> 13.0"
|
||||
spec.required_ruby_version = ">= 3.0"
|
||||
spec.metadata = {
|
||||
"source_code_uri" => "https://github.com/onyx-and-iris/obsws-ruby"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require_relative "../minitest_helper"
|
||||
|
||||
class AttrsTest < OBSWSTest
|
||||
class AttrsTest < Minitest::Test
|
||||
def test_get_version_attrs
|
||||
resp = OBSWSTest.r_client.get_version
|
||||
assert resp.attrs ==
|
||||
|
||||
@@ -2,16 +2,35 @@ 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)")
|
||||
e = assert_raises(OBSWS::OBSWSConnectionError) do
|
||||
OBSWS::Requests::Client
|
||||
.new(host: "localhost", port: 4455, password: "wrongpassword", connect_timeout: 0.1)
|
||||
end
|
||||
assert_equal("Timed out waiting for successful identification (0.1 seconds elapsed)", e.message)
|
||||
end
|
||||
|
||||
def test_it_raises_an_obsws_connection_error_on_auth_enabled_but_no_password_provided_for_request_client
|
||||
e = assert_raises(OBSWS::OBSWSConnectionError) do
|
||||
OBSWS::Requests::Client
|
||||
.new(host: "localhost", port: 4455, password: "")
|
||||
end
|
||||
assert_equal("auth enabled but no password provided", e.message)
|
||||
end
|
||||
|
||||
def test_it_raises_an_obsws_connection_error_on_auth_enabled_but_no_password_provided_for_event_client
|
||||
e = assert_raises(OBSWS::OBSWSConnectionError) do
|
||||
OBSWS::Events::Client
|
||||
.new(host: "localhost", port: 4455, password: "")
|
||||
end
|
||||
assert_equal("auth enabled but no password provided", e.message)
|
||||
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`.")
|
||||
assert_equal("ToggleInputMute", e.req_name)
|
||||
assert_equal(600, e.code)
|
||||
assert_equal("Request ToggleInputMute returned code 600. With message: No source was found by the name of `unknown`.", e.message)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require_relative "../minitest_helper"
|
||||
|
||||
class RequestTest < OBSWSTest
|
||||
class RequestTest < Minitest::Test
|
||||
def test_it_checks_obs_major_version
|
||||
resp = OBSWSTest.r_client.get_version
|
||||
ver = resp.obs_version.split(".").map(&:to_i)
|
||||
|
||||
Reference in New Issue
Block a user