mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-15 23:00:48 +00:00
added a timeout to the login method
module Util::Timeout added, prepends Base
This commit is contained in:
parent
aaee848962
commit
57112fd90a
@ -4,18 +4,21 @@ module Voicemeeter
|
|||||||
include Logging
|
include Logging
|
||||||
include Worker
|
include Worker
|
||||||
include Events::Director
|
include Events::Director
|
||||||
|
prepend Util::Timeout
|
||||||
prepend Util::Cache
|
prepend Util::Cache
|
||||||
|
|
||||||
attr_reader :kind, :midi, :event, :delay, :cache
|
attr_reader :kind, :midi, :event, :delay, :cache
|
||||||
|
|
||||||
RATELIMIT = 0.033
|
RATELIMIT = 0.033
|
||||||
DELAY = 0.001
|
DELAY = 0.001
|
||||||
|
LOGIN_TIMEOUT = 2
|
||||||
|
|
||||||
def initialize(kind, **kwargs)
|
def initialize(kind, **kwargs)
|
||||||
@kind = kind
|
@kind = kind
|
||||||
@sync = kwargs[:sync] || false
|
@sync = kwargs[:sync] || false
|
||||||
@ratelimit = kwargs[:ratelimit] || RATELIMIT
|
@ratelimit = kwargs[:ratelimit] || RATELIMIT
|
||||||
@delay = kwargs[:delay] || DELAY
|
@delay = kwargs[:delay] || DELAY
|
||||||
|
@login_timeout = kwargs[:login_timeout] || LOGIN_TIMEOUT
|
||||||
@event =
|
@event =
|
||||||
Events::Tracker.new(
|
Events::Tracker.new(
|
||||||
**(kwargs.select { |k, _| %i[pdirty mdirty ldirty midi].include? k })
|
**(kwargs.select { |k, _| %i[pdirty mdirty ldirty midi].include? k })
|
||||||
@ -30,8 +33,6 @@ module Voicemeeter
|
|||||||
|
|
||||||
def login
|
def login
|
||||||
CBindings.call(:bind_login, ok: [0, 1]) == 1 and run_voicemeeter(kind.name)
|
CBindings.call(:bind_login, ok: [0, 1]) == 1 and run_voicemeeter(kind.name)
|
||||||
clear_dirty
|
|
||||||
logger.info "Successfully logged into #{self} version #{version}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def logout
|
def logout
|
||||||
@ -72,7 +73,6 @@ module Voicemeeter
|
|||||||
logger.debug "Voicemeeter engine running but the GUI appears to be down... launching."
|
logger.debug "Voicemeeter engine running but the GUI appears to be down... launching."
|
||||||
end
|
end
|
||||||
CBindings.call(:bind_run_voicemeeter, kinds[kind_id])
|
CBindings.call(:bind_run_voicemeeter, kinds[kind_id])
|
||||||
sleep(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
|
@ -18,6 +18,26 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Timeout
|
||||||
|
def login
|
||||||
|
super
|
||||||
|
|
||||||
|
err = nil
|
||||||
|
start = Time.now
|
||||||
|
begin
|
||||||
|
sleep 0.1
|
||||||
|
logger.info "Successfully logged into #{self} version #{version}"
|
||||||
|
logger.debug "login time: #{(Time.now - start).round(2)}"
|
||||||
|
err = nil
|
||||||
|
rescue Errors::VMCAPIError => e
|
||||||
|
err = e
|
||||||
|
retry if Time.now < start + @login_timeout
|
||||||
|
end
|
||||||
|
raise Errors::VMError.new "Timeout logging into the api" if err
|
||||||
|
clear_dirty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module Cache
|
module Cache
|
||||||
def get(name, is_string = false)
|
def get(name, is_string = false)
|
||||||
return cache.delete(name) if cache.key? name
|
return cache.delete(name) if cache.key? name
|
||||||
|
Loading…
Reference in New Issue
Block a user