implement client reconnect; remove some old code
This commit is contained in:
parent
efb6e9c6cd
commit
e937f2bca3
@ -52,6 +52,7 @@ var waterfall_setup_done=0;
|
|||||||
var waterfall_queue = [];
|
var waterfall_queue = [];
|
||||||
var waterfall_timer;
|
var waterfall_timer;
|
||||||
var secondary_fft_size;
|
var secondary_fft_size;
|
||||||
|
var audio_allowed;
|
||||||
|
|
||||||
/*function fade(something,from,to,time_ms,fps)
|
/*function fade(something,from,to,time_ms,fps)
|
||||||
{
|
{
|
||||||
@ -1181,6 +1182,9 @@ function on_ws_recv(evt)
|
|||||||
max_clients_num = config.max_clients;
|
max_clients_num = config.max_clients;
|
||||||
waterfall_init();
|
waterfall_init();
|
||||||
audio_preinit();
|
audio_preinit();
|
||||||
|
|
||||||
|
if (audio_allowed) audio_init();
|
||||||
|
waterfall_clear();
|
||||||
break;
|
break;
|
||||||
case "secondary_config":
|
case "secondary_config":
|
||||||
window.secondary_fft_size = json.value.secondary_fft_size;
|
window.secondary_fft_size = json.value.secondary_fft_size;
|
||||||
@ -1263,119 +1267,6 @@ function on_ws_recv(evt)
|
|||||||
console.warn('unknown type of binary message: ' + type)
|
console.warn('unknown type of binary message: ' + type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
if(!(evt.data instanceof ArrayBuffer)) { divlog("on_ws_recv(): Not ArrayBuffer received...",1); return; }
|
|
||||||
//
|
|
||||||
debug_ws_data_received+=evt.data.byteLength/1000;
|
|
||||||
first4Chars=getFirstChars(evt.data,4);
|
|
||||||
first3Chars=first4Chars.slice(0,3);
|
|
||||||
if(first3Chars=="CLI")
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
if(first3Chars=="AUD")
|
|
||||||
{
|
|
||||||
var audio_data;
|
|
||||||
if(audio_compression=="adpcm") audio_data=new Uint8Array(evt.data,4)
|
|
||||||
else audio_data=new Int16Array(evt.data,4);
|
|
||||||
audio_prepare(audio_data);
|
|
||||||
audio_buffer_current_size_debug+=audio_data.length;
|
|
||||||
audio_buffer_all_size_debug+=audio_data.length;
|
|
||||||
if(!(ios||is_chrome) && (audio_initialized==0 && audio_prepared_buffers.length>audio_buffering_fill_to)) audio_init()
|
|
||||||
}
|
|
||||||
else if(first3Chars=="FFT")
|
|
||||||
{
|
|
||||||
//alert("Yupee! Doing FFT");
|
|
||||||
//if(first4Chars=="FFTS") console.log("FFTS");
|
|
||||||
if(fft_compression=="none") waterfall_add_queue(new Float32Array(evt.data,4));
|
|
||||||
else if(fft_compression="adpcm")
|
|
||||||
{
|
|
||||||
fft_codec.reset();
|
|
||||||
|
|
||||||
var waterfall_i16=fft_codec.decode(new Uint8Array(evt.data,4));
|
|
||||||
var waterfall_f32=new Float32Array(waterfall_i16.length-COMPRESS_FFT_PAD_N);
|
|
||||||
for(var i=0;i<waterfall_i16.length;i++) waterfall_f32[i]=waterfall_i16[i+COMPRESS_FFT_PAD_N]/100;
|
|
||||||
if(first4Chars=="FFTS") secondary_demod_waterfall_add_queue(waterfall_f32); //TODO digimodes
|
|
||||||
else waterfall_add_queue(waterfall_f32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(first3Chars=="DAT")
|
|
||||||
{
|
|
||||||
//secondary_demod_push_binary_data(new Uint8Array(evt.data,4));
|
|
||||||
secondary_demod_push_data(arrayBufferToString(evt.data).substring(4));
|
|
||||||
//console.log("DAT");
|
|
||||||
}
|
|
||||||
else if(first3Chars=="MSG")
|
|
||||||
{
|
|
||||||
/*try
|
|
||||||
{*/
|
|
||||||
var stringData=arrayBufferToString(evt.data);
|
|
||||||
params=stringData.substring(4).split(" ");
|
|
||||||
for(i=0;i<params.length;i++)
|
|
||||||
{
|
|
||||||
param=params[i].split("=");
|
|
||||||
switch(param[0])
|
|
||||||
{
|
|
||||||
case "setup":
|
|
||||||
waterfall_init();
|
|
||||||
audio_preinit();
|
|
||||||
break;
|
|
||||||
case "bandwidth":
|
|
||||||
bandwidth=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "center_freq":
|
|
||||||
center_freq=parseInt(param[1]); //there was no ; and it was no problem... why?
|
|
||||||
break;
|
|
||||||
case "fft_size":
|
|
||||||
fft_size=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "secondary_fft_size":
|
|
||||||
secondary_fft_size=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "secondary_setup":
|
|
||||||
secondary_demod_init_canvases();
|
|
||||||
break;
|
|
||||||
case "if_samp_rate":
|
|
||||||
if_samp_rate=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "secondary_bw":
|
|
||||||
secondary_bw=parseFloat(param[1]);
|
|
||||||
break;
|
|
||||||
case "fft_fps":
|
|
||||||
fft_fps=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "audio_compression":
|
|
||||||
audio_compression=param[1];
|
|
||||||
divlog( "Audio stream is "+ ((audio_compression=="adpcm")?"compressed":"uncompressed")+"." )
|
|
||||||
break;
|
|
||||||
case "fft_compression":
|
|
||||||
fft_compression=param[1];
|
|
||||||
divlog( "FFT stream is "+ ((fft_compression=="adpcm")?"compressed":"uncompressed")+"." )
|
|
||||||
break;
|
|
||||||
case "cpu_usage":
|
|
||||||
var server_cpu_usage=parseInt(param[1]);
|
|
||||||
progressbar_set(e("openwebrx-bar-server-cpu"),server_cpu_usage/100,"Server CPU ["+param[1]+"%]",server_cpu_usage>85);
|
|
||||||
break;
|
|
||||||
case "clients":
|
|
||||||
var clients_num=parseInt(param[1]);
|
|
||||||
progressbar_set(e("openwebrx-bar-clients"),clients_num/max_clients_num,"Clients ["+param[1]+"]",clients_num>max_clients_num*0.85);
|
|
||||||
break;
|
|
||||||
case "max_clients":
|
|
||||||
max_clients_num=parseInt(param[1]);
|
|
||||||
break;
|
|
||||||
case "s":
|
|
||||||
smeter_level=parseFloat(param[1]);
|
|
||||||
setSmeterAbsoluteValue(smeter_level);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*}
|
|
||||||
catch(err)
|
|
||||||
{
|
|
||||||
divlog("Received invalid message over WebSocket.");
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_problem(what)
|
function add_problem(what)
|
||||||
@ -1799,7 +1690,9 @@ function on_ws_closed()
|
|||||||
audio_node.disconnect();
|
audio_node.disconnect();
|
||||||
}
|
}
|
||||||
catch (dont_care) {}
|
catch (dont_care) {}
|
||||||
divlog("WebSocket has closed unexpectedly. Please reload the page.", 1);
|
divlog("WebSocket has closed unexpectedly. Attempting to reconnect in 5 seconds...", 1);
|
||||||
|
|
||||||
|
setTimeout(open_websocket, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_ws_error(event)
|
function on_ws_error(event)
|
||||||
@ -2316,6 +2209,7 @@ function iosPlayButtonClick()
|
|||||||
audio_init();
|
audio_init();
|
||||||
e("openwebrx-big-grey").style.opacity=0;
|
e("openwebrx-big-grey").style.opacity=0;
|
||||||
window.setTimeout(function(){ e("openwebrx-big-grey").style.display="none"; },1100);
|
window.setTimeout(function(){ e("openwebrx-big-grey").style.display="none"; },1100);
|
||||||
|
audio_allowed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,7 +46,7 @@ class AssetsController(Controller):
|
|||||||
filename = self.matches.group(1)
|
filename = self.matches.group(1)
|
||||||
self.serve_file(filename)
|
self.serve_file(filename)
|
||||||
|
|
||||||
class ClientDataForwarder(object):
|
class OpenWebRxClient(object):
|
||||||
def __init__(self, conn):
|
def __init__(self, conn):
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
def write_spectrum_data(self, data):
|
def write_spectrum_data(self, data):
|
||||||
@ -63,17 +63,23 @@ class ClientDataForwarder(object):
|
|||||||
self.conn.send(bytes([0x04]) + data)
|
self.conn.send(bytes([0x04]) + data)
|
||||||
def write_secondary_dsp_config(self, cfg):
|
def write_secondary_dsp_config(self, cfg):
|
||||||
self.conn.send({"type":"secondary_config", "value":cfg})
|
self.conn.send({"type":"secondary_config", "value":cfg})
|
||||||
|
def write_config(self, cfg):
|
||||||
|
self.conn.send({"type":"config","value":cfg})
|
||||||
|
def write_receiver_details(self, details):
|
||||||
|
self.conn.send({"type":"receiver_details","value":details})
|
||||||
|
|
||||||
class WebSocketMessageHandler(object):
|
class WebSocketMessageHandler(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.handshake = None
|
self.handshake = None
|
||||||
self.forwarder = None
|
self.client = None
|
||||||
|
|
||||||
def handleTextMessage(self, conn, message):
|
def handleTextMessage(self, conn, message):
|
||||||
if (message[:16] == "SERVER DE CLIENT"):
|
if (message[:16] == "SERVER DE CLIENT"):
|
||||||
# maybe put some more info in there? nothing to store yet.
|
# maybe put some more info in there? nothing to store yet.
|
||||||
self.handshake = "completed"
|
self.handshake = "completed"
|
||||||
|
|
||||||
|
self.client = OpenWebRxClient(conn)
|
||||||
|
|
||||||
pm = PropertyManager.getSharedInstance()
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
|
||||||
config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level",
|
config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level",
|
||||||
@ -82,19 +88,18 @@ class WebSocketMessageHandler(object):
|
|||||||
"client_audio_buffer_size"]
|
"client_audio_buffer_size"]
|
||||||
config = dict((key, pm.getPropertyValue(key)) for key in config_keys)
|
config = dict((key, pm.getPropertyValue(key)) for key in config_keys)
|
||||||
config["start_offset_freq"] = pm.getPropertyValue("start_freq") - pm.getPropertyValue("center_freq")
|
config["start_offset_freq"] = pm.getPropertyValue("start_freq") - pm.getPropertyValue("center_freq")
|
||||||
conn.send({"type":"config","value":config})
|
self.client.write_config(config)
|
||||||
print("client connection intitialized")
|
print("client connection intitialized")
|
||||||
|
|
||||||
receiver_keys = ["receiver_name", "receiver_location", "receiver_qra", "receiver_asl", "receiver_gps",
|
receiver_keys = ["receiver_name", "receiver_location", "receiver_qra", "receiver_asl", "receiver_gps",
|
||||||
"photo_title", "photo_desc"]
|
"photo_title", "photo_desc"]
|
||||||
receiver_details = dict((key, pm.getPropertyValue(key)) for key in receiver_keys)
|
receiver_details = dict((key, pm.getPropertyValue(key)) for key in receiver_keys)
|
||||||
conn.send({"type":"receiver_details","value":receiver_details})
|
self.client.write_receiver_details(receiver_details)
|
||||||
|
|
||||||
self.forwarder = ClientDataForwarder(conn)
|
SpectrumThread.getSharedInstance().add_client(self.client)
|
||||||
SpectrumThread.getSharedInstance().add_client(self.forwarder)
|
CpuUsageThread.getSharedInstance().add_client(self.client)
|
||||||
CpuUsageThread.getSharedInstance().add_client(self.forwarder)
|
|
||||||
|
|
||||||
self.dsp = DspManager(self.forwarder)
|
self.dsp = DspManager(self.client)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -119,9 +124,9 @@ class WebSocketMessageHandler(object):
|
|||||||
print("unsupported binary message, discarding")
|
print("unsupported binary message, discarding")
|
||||||
|
|
||||||
def handleClose(self, conn):
|
def handleClose(self, conn):
|
||||||
if self.forwarder:
|
if self.client:
|
||||||
SpectrumThread.getSharedInstance().remove_client(self.forwarder)
|
SpectrumThread.getSharedInstance().remove_client(self.client)
|
||||||
CpuUsageThread.getSharedInstance().remove_client(self.forwarder)
|
CpuUsageThread.getSharedInstance().remove_client(self.client)
|
||||||
if self.dsp:
|
if self.dsp:
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
|
|
||||||
|
@ -67,9 +67,11 @@ class SpectrumThread(threading.Thread):
|
|||||||
bytes_to_read=int(dsp.get_fft_bytes_to_read())
|
bytes_to_read=int(dsp.get_fft_bytes_to_read())
|
||||||
while self.doRun:
|
while self.doRun:
|
||||||
data=dsp.read(bytes_to_read)
|
data=dsp.read(bytes_to_read)
|
||||||
#print("gotcha",len(data),"bytes of spectrum data via spectrum_thread_function()")
|
if len(data) == 0:
|
||||||
for c in self.clients:
|
self.shutdown()
|
||||||
c.write_spectrum_data(data)
|
else:
|
||||||
|
for c in self.clients:
|
||||||
|
c.write_spectrum_data(data)
|
||||||
|
|
||||||
print("spectrum thread shut down")
|
print("spectrum thread shut down")
|
||||||
|
|
||||||
@ -136,9 +138,11 @@ class DspManager(object):
|
|||||||
|
|
||||||
if (pm.getPropertyValue("digimodes_enable")):
|
if (pm.getPropertyValue("digimodes_enable")):
|
||||||
def set_secondary_mod(mod):
|
def set_secondary_mod(mod):
|
||||||
|
if mod == False: mod = None
|
||||||
|
if self.dsp.get_secondary_demodulator() == mod: return
|
||||||
self.stopSecondaryThreads()
|
self.stopSecondaryThreads()
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
if mod == False:
|
if mod is None:
|
||||||
self.dsp.set_secondary_demodulator(None)
|
self.dsp.set_secondary_demodulator(None)
|
||||||
else:
|
else:
|
||||||
self.dsp.set_secondary_demodulator(mod)
|
self.dsp.set_secondary_demodulator(mod)
|
||||||
@ -147,8 +151,6 @@ class DspManager(object):
|
|||||||
"if_samp_rate":self.dsp.if_samp_rate(),
|
"if_samp_rate":self.dsp.if_samp_rate(),
|
||||||
"secondary_bw":self.dsp.secondary_bw()
|
"secondary_bw":self.dsp.secondary_bw()
|
||||||
})
|
})
|
||||||
# TODO frontend will probably miss this
|
|
||||||
#rxws.send(self, "MSG secondary_fft_size={0} if_samp_rate={1} secondary_bw={2} secondary_setup".format(cfg.digimodes_fft_size, dsp.if_samp_rate(), dsp.secondary_bw()))
|
|
||||||
self.dsp.start()
|
self.dsp.start()
|
||||||
|
|
||||||
if mod:
|
if mod:
|
||||||
@ -180,7 +182,10 @@ class DspManager(object):
|
|||||||
def readDspOutput(self):
|
def readDspOutput(self):
|
||||||
while (self.doRun):
|
while (self.doRun):
|
||||||
data = self.dsp.read(256)
|
data = self.dsp.read(256)
|
||||||
self.handler.write_dsp_data(data)
|
if len(data) != 256:
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
self.handler.write_dsp_data(data)
|
||||||
|
|
||||||
def readSMeterOutput(self):
|
def readSMeterOutput(self):
|
||||||
while (self.doRun):
|
while (self.doRun):
|
||||||
@ -199,6 +204,7 @@ class DspManager(object):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.doRun = False
|
self.doRun = False
|
||||||
|
self.runSecondary = False
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
|
|
||||||
def setProperty(self, prop, value):
|
def setProperty(self, prop, value):
|
||||||
|
Loading…
Reference in New Issue
Block a user