summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2022-10-29 16:45:30 -0700
committerJoe Rayhawk <jrayhawk@fairlystable.org>2022-10-29 16:45:30 -0700
commit2685cb0a5ff2736e7392a60436f762e67cdd104f (patch)
treef1bcf18f17eafeca9b7cd2f9240342fa43b92bf3
parent7819ebe6c22e92b4d9bb2e6d9ec6ed8d864f0c0c (diff)
downloadcrystal-obs-websocket-2685cb0a5ff2736e7392a60436f762e67cdd104f.tar.gz
crystal-obs-websocket-2685cb0a5ff2736e7392a60436f762e67cdd104f.zip
Limit connection failure spam and add negotiated flag.
-rw-r--r--src/obswebsocket.cr22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr
index 3dfa5cc..f758632 100644
--- a/src/obswebsocket.cr
+++ b/src/obswebsocket.cr
@@ -45,6 +45,10 @@ module OBSWebSocket
@video = OBSWebSocket::VideoSettings.new( @@reqchan )
@stats = OBSWebSocket::Stats.new( @@reqchan )
@negotiated = false
+ @connecterror = 0
+ def negotiated?
+ return @negotiated
+ end
def reqchan
return @@reqchan
end
@@ -177,6 +181,7 @@ module OBSWebSocket
self.send( json_text )
when 2 # identified
@negotiated = true
+ @connecterror = 0
self.reqchan.send( { nil, "clear queue" } )
when 5 # event
eventsubs.each do | eventchan |
@@ -244,6 +249,23 @@ module OBSWebSocket
obs_pubsub.run
sleep 10
next
+ rescue ex : Socket::ConnectError | IO::Error
+ if @connecterror < 3
+ print ex.message
+ @connecterror += 1
+ ( @connecterror == 3 ) && ( @connecterror += 1 ) && print ". Suppressing further repeat errors."
+ print "\n"
+ end
+ obs_pubsub && obs_pubsub.close
+ @negotiated = false
+ sleep 10
+ next
+ rescue ex
+ pp ex
+ pp ex.backtrace?
+ obs_pubsub && obs_pubsub.close
+ @negotiated = false
+ next
end
end
end