summaryrefslogtreecommitdiff
path: root/src/obswebsocket.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-23 23:26:08 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-23 23:26:08 -0800
commitc3345cfdbb16c0396f5ddb5898d9f934fe6fde5d (patch)
tree5c9ea535c6698e9223030c4ae7bd099e9b8671c6 /src/obswebsocket.cr
parent63e64a9c3600120933f7295d46c9ca66222cd497 (diff)
downloadcrystal-obs-websocket-c3345cfdbb16c0396f5ddb5898d9f934fe6fde5d.tar.gz
crystal-obs-websocket-c3345cfdbb16c0396f5ddb5898d9f934fe6fde5d.zip
create block_until_negotiated() method
Diffstat (limited to 'src/obswebsocket.cr')
-rw-r--r--src/obswebsocket.cr15
1 files 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