rt-sim-training-client/static/workertest/trafficplan/trafficstation.js

35 lines
546 B
JavaScript

var i=0;
var update = null;
function timedCount(){
onmessage = (e) => {
if(e.data[0] == "on"){
// console.log("on");
update = setInterval("stationupdate()", 2000);
}
if(e.data[0] == "off"){
clearInterval(update);
}
// console.log(e.data);
if(e.data[0] == "changespeed"){
if(update){
clearInterval(update);
let speed = 1000/e.data[1];
update = setInterval("stationupdate()", speed);
}
}
}
}
function stationupdate(){
postMessage("up");
}
timedCount();