From c3345cfdbb16c0396f5ddb5898d9f934fe6fde5d Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Wed, 23 Nov 2022 23:26:08 -0800 Subject: create block_until_negotiated() method --- src/obswebsocket.cr | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index aea6eed..9af1856 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -127,8 +127,7 @@ module OBS def transition! self.send_sync( OBS.req( "TriggerStudioModeTransition" ) ) end - # Asynchronous send - def send( json : String ) + def block_until_negotiated unless @negotiated @negotiationdelayqueue += 1 negotiationresult = @negotiationdelay.receive @@ -137,18 +136,16 @@ module OBS end @negotiated || return false # not sure why this condition would occur without an exception end + end + # Asynchronous send + def send( json : String ) + self.block_until_negotiated() STDERR.puts( "SENT: #{JSON.parse(json).pretty_inspect}" ) @websocket && @websocket.not_nil!.send( json ) end # Block until response def send_sync( json : String ) - unless @negotiated - @negotiationdelayqueue += 1 - negotiationresult = @negotiationdelay.receive - if negotiationresult.is_a?( Exception ) - raise negotiationresult - end - end + self.block_until_negotiated() reschan = Channel( JSON::Any ).new STDERR.puts( "SENT: #{JSON.parse(json).pretty_inspect}" ) @openrequests[ JSON.parse( json )["d"]["requestId"].as_s ] = reschan -- cgit v1.2.3