use new way of measuring for network speed, too

This commit is contained in:
Jakob Ketterl 2019-10-26 22:44:54 +02:00
parent 39120d9413
commit 13f27a76ff
2 changed files with 13 additions and 14 deletions

View File

@ -54,7 +54,8 @@ NetworkSpeedProgressBar = function(el) {
NetworkSpeedProgressBar.prototype = new ProgressBar(); NetworkSpeedProgressBar.prototype = new ProgressBar();
NetworkSpeedProgressBar.prototype.setSpeed = function(speed) { NetworkSpeedProgressBar.prototype.setSpeed = function(speed) {
this.set(speed * 8 / 2000, "Network usage [" + (speed * 8).toFixed(1) + " kbps]", false); var speedInKilobits = speed * 8 / 1000;
this.set(speedInKilobits / 2000, "Network usage [" + speedInKilobits.toFixed(1) + " kbps]", false);
}; };
AudioSpeedProgressBar = function(el) { AudioSpeedProgressBar = function(el) {

View File

@ -997,8 +997,7 @@ function zoom_calc() {
//console.log("zoom_calc || zopx:"+zoom_offset_px.toString()+ " maxoff:"+(winsize-canvases_new_width).toString()+" relval:"+(0.5+zoom_center_rel/bandwidth).toString() ); //console.log("zoom_calc || zopx:"+zoom_offset_px.toString()+ " maxoff:"+(winsize-canvases_new_width).toString()+" relval:"+(0.5+zoom_center_rel/bandwidth).toString() );
} }
var debug_ws_data_received = 0; var networkSpeedMeasurement;
var debug_ws_time_start;
var currentprofile; var currentprofile;
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
@ -1006,7 +1005,7 @@ var COMPRESS_FFT_PAD_N = 10; //should be the same as in csdr.c
function on_ws_recv(evt) { function on_ws_recv(evt) {
if (typeof evt.data === 'string') { if (typeof evt.data === 'string') {
// text messages // text messages
debug_ws_data_received += evt.data.length; networkSpeedMeasurement.add(evt.data.length);
if (evt.data.substr(0, 16) === "CLIENT DE SERVER") { if (evt.data.substr(0, 16) === "CLIENT DE SERVER") {
divlog("Server acknowledged WebSocket connection."); divlog("Server acknowledged WebSocket connection.");
@ -1127,7 +1126,7 @@ function on_ws_recv(evt) {
} }
} else if (evt.data instanceof ArrayBuffer) { } else if (evt.data instanceof ArrayBuffer) {
// binary messages // binary messages
debug_ws_data_received += evt.data.byteLength; networkSpeedMeasurement.add(evt.data.byteLength);
var type = new Uint8Array(evt.data, 0, 1)[0]; var type = new Uint8Array(evt.data, 0, 1)[0];
var data = evt.data.slice(1); var data = evt.data.slice(1);
@ -1386,8 +1385,14 @@ function waterfall_measure_minmax_do(what) {
function on_ws_opened() { function on_ws_opened() {
ws.send("SERVER DE CLIENT client=openwebrx.js type=receiver"); ws.send("SERVER DE CLIENT client=openwebrx.js type=receiver");
divlog("WebSocket opened to " + ws.url); divlog("WebSocket opened to " + ws.url);
debug_ws_data_received = 0; if (!networkSpeedMeasurement) {
debug_ws_time_start = new Date(); networkSpeedMeasurement = new Measurement();
networkSpeedMeasurement.report(60000, 1000, function(rate){
networkSpeedProgressBar.setSpeed(rate);
});
} else {
networkSpeedMeasurement.reset();
}
reconnect_timeout = false; reconnect_timeout = false;
ws.send(JSON.stringify({ ws.send(JSON.stringify({
"type": "dspcontrol", "type": "dspcontrol",
@ -1880,12 +1885,6 @@ function initProgressBars() {
cpuProgressBar = new CpuProgressBar($('#openwebrx-bar-server-cpu')); cpuProgressBar = new CpuProgressBar($('#openwebrx-bar-server-cpu'));
} }
function updateNetworkStats() {
var elapsed = (new Date() - debug_ws_time_start) / 1000;
var network_speed_value = (debug_ws_data_received / 1000) / elapsed;
networkSpeedProgressBar.setSpeed(network_speed_value);
}
function audioReporter(stats) { function audioReporter(stats) {
if (typeof(stats.buffersize) !== 'undefined') { if (typeof(stats.buffersize) !== 'undefined') {
audioBufferProgressBar.setBuffersize(stats.buffersize); audioBufferProgressBar.setBuffersize(stats.buffersize);
@ -1915,7 +1914,6 @@ function openwebrx_init() {
initProgressBars(); initProgressBars();
init_rx_photo(); init_rx_photo();
open_websocket(); open_websocket();
setInterval(updateNetworkStats, 1000);
secondary_demod_init(); secondary_demod_init();
digimodes_init(); digimodes_init();
initPanels(); initPanels();