2017-05-09 02:12:10 +02:00
|
|
|
var socket = {readyState:0};
|
2017-05-08 19:13:29 +02:00
|
|
|
|
|
|
|
(function(){
|
|
|
|
|
2017-05-09 01:03:44 +02:00
|
|
|
function onerror(err) {
|
|
|
|
console.warn(err);
|
2017-05-09 02:12:10 +02:00
|
|
|
if(socket.readyState !== 3){
|
2017-05-09 18:05:55 +02:00
|
|
|
notify.send("error","Es gibt Übertragungsprobleme!");
|
2017-05-09 02:12:10 +02:00
|
|
|
gui.render();
|
|
|
|
}
|
2017-05-09 01:03:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onopen() {
|
2017-05-09 02:12:10 +02:00
|
|
|
gui.render();
|
2017-05-09 01:03:44 +02:00
|
|
|
}
|
2017-05-08 19:13:29 +02:00
|
|
|
|
2017-05-09 01:03:44 +02:00
|
|
|
function onmessage(e) {
|
2017-05-08 19:13:29 +02:00
|
|
|
var msg = JSON.parse(e.data);
|
|
|
|
|
2017-05-09 01:03:44 +02:00
|
|
|
if(msg.type === "current") {
|
2017-05-08 19:13:29 +02:00
|
|
|
store.updateReal(msg.node);
|
2017-05-09 01:03:44 +02:00
|
|
|
} else if (msg.type === "to-update") {
|
2017-05-08 19:13:29 +02:00
|
|
|
store.update(msg.node);
|
|
|
|
} else {
|
|
|
|
gui.disable(e);
|
|
|
|
}
|
2017-05-09 02:12:10 +02:00
|
|
|
gui.render();
|
2017-05-09 01:03:44 +02:00
|
|
|
}
|
2017-05-08 19:13:29 +02:00
|
|
|
|
2017-05-09 01:03:44 +02:00
|
|
|
function onclose(){
|
|
|
|
console.log("socket closed by server");
|
2017-05-09 18:05:55 +02:00
|
|
|
notify.send("warn","Es besteht ein Verbindungsproblem!");
|
2017-05-09 02:12:10 +02:00
|
|
|
gui.render();
|
2017-05-09 01:03:44 +02:00
|
|
|
setTimeout(connect, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendnode(node) {
|
2017-05-08 19:13:29 +02:00
|
|
|
var msg = {node:node};
|
|
|
|
var string = JSON.stringify(msg);
|
2017-05-09 02:12:10 +02:00
|
|
|
if(socket.send(string)){
|
2017-05-09 18:05:55 +02:00
|
|
|
notify.send("success","Node '"+node.node_id+"' mit neuen Werten wurde gespeichert.");
|
2017-05-09 02:12:10 +02:00
|
|
|
}else{
|
2017-05-09 18:05:55 +02:00
|
|
|
notify.send("error","Node '"+node.node_id+"' konnte nicht gespeichert werden!");
|
2017-05-09 02:12:10 +02:00
|
|
|
}
|
2017-05-09 01:03:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function connect() {
|
|
|
|
socket = new WebSocket(config.backend);
|
|
|
|
socket.onopen = onopen;
|
|
|
|
socket.onerror = onerror;
|
|
|
|
socket.onmessage = onmessage;
|
|
|
|
socket.onclose = onclose;
|
|
|
|
socket.sendnode = sendnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect();
|
2017-05-08 19:13:29 +02:00
|
|
|
})();
|