request ids are now UUID's.

This commit is contained in:
onyx-and-iris 2023-08-11 17:04:38 +01:00
parent c6bb8d07ff
commit 3ef4396885
2 changed files with 10 additions and 10 deletions

View File

@ -1,9 +1,10 @@
require "digest/sha2" require "digest/sha2"
require "json" require "json"
require "waitutil"
require "socket"
require "websocket/driver"
require "logger" require "logger"
require "securerandom"
require "socket"
require "waitutil"
require "websocket/driver"
require_relative "obsws/logger" require_relative "obsws/logger"
require_relative "obsws/driver" require_relative "obsws/driver"

View File

@ -35,20 +35,19 @@ module OBSWS
end end
def call(req, data = nil) def call(req, data = nil)
id = rand(1..1000) uuid = SecureRandom.uuid
@base_client.req(id, req, data) @base_client.req(uuid, req, data)
WaitUtil.wait_for_condition( WaitUtil.wait_for_condition(
"reponse id to match 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] == uuid }
unless @response[:requestStatus][:result] unless @response[:requestStatus][:result]
raise OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment]) OBSWSRequestError.new(@response[:requestType], @response[:requestStatus][:code], @response[:requestStatus][:comment]) => e
logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
raise e
end end
@response[:responseData] @response[:responseData]
rescue OBSWSRequestError => e
logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
raise
rescue WaitUtil::TimeoutError => e rescue WaitUtil::TimeoutError => e
logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n")) logger.error(["#{e.class.name}: #{e.message}", *e.backtrace].join("\n"))
raise OBSWSError.new([e.message, *e.backtrace].join("\n")) raise OBSWSError.new([e.message, *e.backtrace].join("\n"))