frontend store data from pinger

This commit is contained in:
Martin/Geno 2019-06-05 16:04:51 +02:00 committed by genofire
parent 4f346355d4
commit 0db00ad76e
2 changed files with 24 additions and 3 deletions

View File

@ -202,5 +202,7 @@ addEvent('channels_wifi24', (msg) => {
addEvent('channels_wifi5', (msg) => {
store.channelsWifi5 = msg.body.sort((a, b) => a - b);
});
addEvent('ping', (msg) => {
store.updateNodePing(msg.body);
});
connect();

View File

@ -1,6 +1,7 @@
import config from './config';
const list = {};
const list = {},
storeMaxPing = 5,
// Returns the node with specified id (or null if node doesn't exist).
export function getNode (nodeid) {
@ -24,7 +25,8 @@ export function createNode (nodeid) {
'channel24': config.node.channel24,
'channel5': config.node.channel5,
},
'location': {}
'location': {},
'pingstate':[]
};
};
@ -33,6 +35,23 @@ export function updateNode (node) {
list[node.node_id] = node;
};
function updateNodePingTo(value){
return (nodeid) => {
if (!list[nodeid]) {
return;
}
list[nodeid]['pingstate'].unshift(value);
if (list[nodeid]['pingstate'].length > storeMaxPing) {
list[nodeid]['pingstate'].length = storeMaxPing;
}
}
}
export function updateNodePing(ping) {
ping["true"].forEach(updateNodePingTo(true));
ping["false"].forEach(updateNodePingTo(false));
};
// Returns a list of all known nodes.
export function getNodes () {
return Object.keys(list).map(getNode);