Skip to content

Commit

Permalink
WS reconnect logic & WS memory leak protection
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Feb 17, 2022
1 parent e9a0589 commit 3be4b69
Show file tree
Hide file tree
Showing 3 changed files with 810 additions and 795 deletions.
14 changes: 10 additions & 4 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ function cmpP(a, b) {
function makeWS() {
if (ws) return;
ws = new WebSocket('ws://'+(loc?locip:window.location.hostname)+'/ws');
ws.binaryType = "arraybuffer";
ws.binaryType = "arraybuffer";
ws.onmessage = function(event) {
if (event.data instanceof ArrayBuffer) return; //liveview packet
var json = JSON.parse(event.data);
Expand All @@ -974,9 +974,15 @@ function makeWS() {
displayRover(info, s);
readState(json.state);
};
ws.onclose = function(event) {
d.getElementById('connind').style.backgroundColor = "#831";
}
ws.onclose = (e)=>{
d.getElementById('connind').style.backgroundColor = "#831";
ws = null;
if (lastinfo.ws > -1) setTimeout(makeWS,500); //retry WS connection
}
ws.onopen = (e)=>{
ws.send("{'v':true}");
reqsLegal = true;
}
}

function readState(s,command=false) {
Expand Down
Loading

0 comments on commit 3be4b69

Please sign in to comment.