From 9a1aa0312ad2300119363648b888dcdfcfc2c640 Mon Sep 17 00:00:00 2001 From: merijn Date: Fri, 1 Nov 2019 18:56:00 +0100 Subject: [PATCH] worker_specs --- www/worker_specs/script.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/www/worker_specs/script.js b/www/worker_specs/script.js index 4cd6701..ce775dd 100644 --- a/www/worker_specs/script.js +++ b/www/worker_specs/script.js @@ -27,6 +27,7 @@ spec_names.forEach(function(name){ let request_time = timeStamp(), + hit_started = false, elapsed_time, hit_finished = false @@ -36,15 +37,6 @@ let request_time = timeStamp(), let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws') -let test = `{"property": "os", "value": "213.127.20.197"}` - -// fakeWs(test) -// -// function fakeWs(json){ -// -// -// } - ws.addEventListener('open', () => { // ws.send('hi server') @@ -56,14 +48,21 @@ ws.addEventListener('message', (event) => { let data = JSON.parse(event.data) if(data.property === 'hit_opened') { - hit_finished = false - request_time = timeStamp() - divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}` + if(data.value != null){ + hit_started = true + hit_finished = false + request_time = timeStamp() + divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}` + }else{ + hit_started = false + } } else if(data.property === 'hit_submitted'){ hit_finished = true; } - else if(divs[data.property]) divs[data.property].innerHTML = `${data.value}` + else if(divs[data.property]){ + data.value === null ? divs[data.property].innerHTML = `—` : divs[data.property].innerHTML = `${data.value}` + } }) @@ -103,8 +102,11 @@ function makeAnimation(){ function update(step){ if(!hit_finished) elapsed_time = `${new Date((Date.now() - request_time)).format('MM"m "ss"s"')}` - - divs['elapsed_time'].innerHTML = elapsed_time + if(hit_started){ + divs['elapsed_time'].innerHTML = elapsed_time + }else{ + divs['elapsed_time'].innerHTML = `—` + } } @@ -112,3 +114,4 @@ makeAnimation() function timeStamp(){return window.performance && window.performance.now ? window.performance.now() : new Date().getTime()} +