From 2685cb0a5ff2736e7392a60436f762e67cdd104f Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Sat, 29 Oct 2022 16:45:30 -0700 Subject: Limit connection failure spam and add negotiated flag. --- src/obswebsocket.cr | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') 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 -- cgit v1.2.3