Send state on new connection instead of fixed period

This commit is contained in:
Mashintime 2023-11-16 20:39:04 -05:00
parent 0e53b34ed6
commit 4318902f5a
2 changed files with 8 additions and 5 deletions

View file

@ -224,6 +224,7 @@ def sock_fft(sock):
@sock.route('/states')
def sock_states(sock):
sock_watchdog(sock, states_client_list, app.state_queue)
app.states.sendStateUpdate()
# websocket multi client support for using with queued information.
# our client set which contains all connected websocket clients

View file

@ -13,19 +13,21 @@ class STATES:
self.is_arq_session = False
self.arq_session_state = 'disconnected'
self.audio_dbfs = 0
self.last = time.time()
def sendStateUpdate (self):
self.statequeue.put(self.newstate)
def set(self, key, value):
setattr(self, key, value)
updateCandence = 3
# only process data if changed
# but also send an update if more than a 'updateCadence' second(s) has lapsed
# Otherwise GUI can't tell if modem is active due to lack of state messages on startup
new_state = self.getAsJSON()
if new_state != self.newstate or time.time() - self.last > updateCandence:
self.statequeue.put(new_state)
if new_state != self.newstate:
self.newstate = new_state
self.last=time.time()
self.sendStateUpdate()
def getAsJSON(self):
return json.dumps({