mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Send state on new connection instead of fixed period
This commit is contained in:
parent
0e53b34ed6
commit
4318902f5a
2 changed files with 8 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in a new issue