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;
max_clients_num=0;
clients_num = 0;
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;
divlog( "FFT stream is "+ ((fft_compression=="adpcm")?"compressed":"uncompressed")+"." )
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_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);
break;
case "clients":
var clients = json.value;
progressbar_set(e("openwebrx-bar-clients"), clients / max_clients_num, "Clients [" + clients + "]", clients > max_clients_num*0.85);
client_num = json.value;
progressbar_set(e("openwebrx-bar-clients"), client_num / max_clients_num, "Clients [" + client_num + "]", client_num > max_clients_num*0.85);
break;
case "profiles":
var listbox = e("openwebrx-sdr-profiles-listbox");

View File

@ -487,18 +487,6 @@ class CpuUsageThread(threading.Thread):
CpuUsageThread.sharedInstance = None
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):
pass
@ -512,7 +500,6 @@ class ClientRegistry(object):
def __init__(self):
self.clients = []
self.reporter = None
super().__init__()
def broadcast(self):
@ -525,9 +512,7 @@ class ClientRegistry(object):
if len(self.clients) >= pm["max_clients"]:
raise TooManyClientsException()
self.clients.append(client)
if self.reporter is None:
self.reporter = ClientReportingThread(self)
self.reporter.start()
self.broadcast()
def clientCount(self):
return len(self.clients)
@ -537,6 +522,4 @@ class ClientRegistry(object):
self.clients.remove(client)
except ValueError:
pass
if not self.clients and self.reporter is not None:
self.reporter.stop()
self.reporter = None
self.broadcast()