fix local time logic
diff --git a/web/ons-demo/js/flows.js b/web/ons-demo/js/flows.js
index c7bdf53..e21af0d 100644
--- a/web/ons-demo/js/flows.js
+++ b/web/ons-demo/js/flows.js
@@ -209,6 +209,8 @@
function makeGraph(iperfData) {
var d = 'M0,0';
+ var now = flow.iperfData.startTime + (Date.now() - flow.iperfData.localNow)/1000;
+
if (iperfData.samples && iperfData.samples.length) {
var lastX;
@@ -216,7 +218,7 @@
while (i) {
var sample = iperfData.samples[i];
- var x = (1000 - (iperfData.now - sample.time)*10);
+ var x = (1000 - (now - sample.time)*10);
// workaround for discontinuity in iperf data
if (x < 0) {
i -= 1;
@@ -255,7 +257,6 @@
if (flow.iperfData) {
var iperfPath = d3.select(document.getElementById(makeSelectedFlowKey(flow))).select('path');
iperfPath.attr('d', makeGraph(flow.iperfData));
- flow.iperfData.now += interval/1000;
}
@@ -290,8 +291,9 @@
var startTime = endTime - (iperfData.samples.length * interval/1000);
// set now on the first buffer
- if (!flow.iperfData.now) {
- flow.iperfData.now = startTime;
+ if (!flow.iperfData.startTime) {
+ flow.iperfData.startTime = startTime;
+ flow.iperfData.localNow = Date.now();
}
console.log('iperf buffer start time: ' + startTime);
@@ -306,8 +308,11 @@
}
// if the client gets too out of sync, resynchronize
- if (Math.abs(flow.iperfData.now - startTime) > (updateRate/1000) * 1.25) {
- flow.iperfData.now = startTime;
+ var clientNow = flow.iperfData.startTime + (Date.now() - flow.iperfData.localNow)/1000;
+ if (Math.abs(clientNow - startTime) > (updateRate/1000) * 2) {
+ console.log('resynchronizing now: ' + clientNow + ' => ' + startTime);
+ flow.iperfData.startTime = startTime;
+ flow.iperfData.localNow = Date.now();
}
var time = startTime;