report client numbers on change only

This commit is contained in:
Jakob Ketterl 2019-05-15 19:51:50 +02:00
parent cffb65e37d
commit 4496fcc8b0
2 changed files with 7 additions and 22 deletions

View File

@ -1157,6 +1157,7 @@ function audio_calculate_resampling(targetRate)
debug_ws_data_received=0; debug_ws_data_received=0;
max_clients_num=0; max_clients_num=0;
clients_num = 0;
var COMPRESS_FFT_PAD_N=10; //should be the same as in csdr.c var COMPRESS_FFT_PAD_N=10; //should be the same as in csdr.c
@ -1192,7 +1193,8 @@ function on_ws_recv(evt)
fft_compression = config.fft_compression; fft_compression = config.fft_compression;
divlog( "FFT stream is "+ ((fft_compression=="adpcm")?"compressed":"uncompressed")+"." ) divlog( "FFT stream is "+ ((fft_compression=="adpcm")?"compressed":"uncompressed")+"." )
max_clients_num = config.max_clients; max_clients_num = config.max_clients;
mathbox_waterfall_colors = config.mathbox_waterfall_colors; progressbar_set(e("openwebrx-bar-clients"), client_num / max_clients_num, "Clients [" + client_num + "]", client_num > max_clients_num*0.85);
mathbox_waterfall_colors = config.mathbox_waterfall_colors;
mathbox_waterfall_frequency_resolution = config.mathbox_waterfall_frequency_resolution; mathbox_waterfall_frequency_resolution = config.mathbox_waterfall_frequency_resolution;
mathbox_waterfall_history_length = config.mathbox_waterfall_history_length; mathbox_waterfall_history_length = config.mathbox_waterfall_history_length;
@ -1224,8 +1226,8 @@ function on_ws_recv(evt)
progressbar_set(e("openwebrx-bar-server-cpu"),server_cpu_usage,"Server CPU [" + Math.round(server_cpu_usage * 100) + "%]",server_cpu_usage>85); progressbar_set(e("openwebrx-bar-server-cpu"),server_cpu_usage,"Server CPU [" + Math.round(server_cpu_usage * 100) + "%]",server_cpu_usage>85);
break; break;
case "clients": case "clients":
var clients = json.value; client_num = json.value;
progressbar_set(e("openwebrx-bar-clients"), clients / max_clients_num, "Clients [" + clients + "]", clients > max_clients_num*0.85); progressbar_set(e("openwebrx-bar-clients"), client_num / max_clients_num, "Clients [" + client_num + "]", client_num > max_clients_num*0.85);
break; break;
case "profiles": case "profiles":
var listbox = e("openwebrx-sdr-profiles-listbox"); var listbox = e("openwebrx-sdr-profiles-listbox");

View File

@ -487,18 +487,6 @@ class CpuUsageThread(threading.Thread):
CpuUsageThread.sharedInstance = None CpuUsageThread.sharedInstance = None
self.doRun = False self.doRun = False
class ClientReportingThread(threading.Thread):
def __init__(self, registry):
self.doRun = True
self.registry = registry
super().__init__()
def run(self):
while self.doRun:
self.registry.broadcast()
time.sleep(3)
def stop(self):
self.doRun = False
class TooManyClientsException(Exception): class TooManyClientsException(Exception):
pass pass
@ -512,7 +500,6 @@ class ClientRegistry(object):
def __init__(self): def __init__(self):
self.clients = [] self.clients = []
self.reporter = None
super().__init__() super().__init__()
def broadcast(self): def broadcast(self):
@ -525,9 +512,7 @@ class ClientRegistry(object):
if len(self.clients) >= pm["max_clients"]: if len(self.clients) >= pm["max_clients"]:
raise TooManyClientsException() raise TooManyClientsException()
self.clients.append(client) self.clients.append(client)
if self.reporter is None: self.broadcast()
self.reporter = ClientReportingThread(self)
self.reporter.start()
def clientCount(self): def clientCount(self):
return len(self.clients) return len(self.clients)
@ -537,6 +522,4 @@ class ClientRegistry(object):
self.clients.remove(client) self.clients.remove(client)
except ValueError: except ValueError:
pass pass
if not self.clients and self.reporter is not None: self.broadcast()
self.reporter.stop()
self.reporter = None