mirror of
https://github.com/wled/WLED.git
synced 2025-07-16 15:26:31 +00:00
WS reconnect logic & WS memory leak protection
This commit is contained in:
parent
e9a05890a5
commit
3be4b69b44
@ -956,7 +956,7 @@ function cmpP(a, b) {
|
|||||||
function makeWS() {
|
function makeWS() {
|
||||||
if (ws) return;
|
if (ws) return;
|
||||||
ws = new WebSocket('ws://'+(loc?locip:window.location.hostname)+'/ws');
|
ws = new WebSocket('ws://'+(loc?locip:window.location.hostname)+'/ws');
|
||||||
ws.binaryType = "arraybuffer";
|
ws.binaryType = "arraybuffer";
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
if (event.data instanceof ArrayBuffer) return; //liveview packet
|
if (event.data instanceof ArrayBuffer) return; //liveview packet
|
||||||
var json = JSON.parse(event.data);
|
var json = JSON.parse(event.data);
|
||||||
@ -974,9 +974,15 @@ function makeWS() {
|
|||||||
displayRover(info, s);
|
displayRover(info, s);
|
||||||
readState(json.state);
|
readState(json.state);
|
||||||
};
|
};
|
||||||
ws.onclose = function(event) {
|
ws.onclose = (e)=>{
|
||||||
d.getElementById('connind').style.backgroundColor = "#831";
|
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) {
|
function readState(s,command=false) {
|
||||||
|
1580
wled00/html_ui.h
1580
wled00/html_ui.h
File diff suppressed because it is too large
Load Diff
@ -108,9 +108,12 @@ void sendDataWs(AsyncWebSocketClient * client)
|
|||||||
JsonObject info = doc.createNestedObject("info");
|
JsonObject info = doc.createNestedObject("info");
|
||||||
serializeInfo(info);
|
serializeInfo(info);
|
||||||
size_t len = measureJson(doc);
|
size_t len = measureJson(doc);
|
||||||
buffer = ws.makeBuffer(len);
|
size_t heap1 = ESP.getFreeHeap();
|
||||||
if (!buffer) {
|
buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes
|
||||||
|
size_t heap2 = ESP.getFreeHeap();
|
||||||
|
if (!buffer || heap1-heap2<len) {
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
|
ws.cleanupClients(0); // disconnect all clients to release memory
|
||||||
return; //out of memory
|
return; //out of memory
|
||||||
}
|
}
|
||||||
serializeJson(doc, (char *)buffer->get(), len +1);
|
serializeJson(doc, (char *)buffer->get(), len +1);
|
||||||
@ -155,7 +158,11 @@ void handleWs()
|
|||||||
{
|
{
|
||||||
if (millis() - wsLastLiveTime > WS_LIVE_INTERVAL)
|
if (millis() - wsLastLiveTime > WS_LIVE_INTERVAL)
|
||||||
{
|
{
|
||||||
|
#ifdef ESP8266
|
||||||
|
ws.cleanupClients(2);
|
||||||
|
#else
|
||||||
ws.cleanupClients();
|
ws.cleanupClients();
|
||||||
|
#endif
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if (wsLiveClientId)
|
if (wsLiveClientId)
|
||||||
success = sendLiveLedsWs(wsLiveClientId);
|
success = sendLiveLedsWs(wsLiveClientId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user