Optimised websockets UI refresh.

This commit is contained in:
Blaz Kristan 2021-03-19 16:09:24 +01:00
parent a30ce1c44d
commit df38f00cf2
3 changed files with 824 additions and 867 deletions

View File

@ -212,13 +212,10 @@ function onLoad()
} }
// Creatte UI update WS handler // Creatte UI update WS handler
var mySocket = new WebSocket('ws://'+loc?locip:window.location.hostname+'/ws'); var mySocket = new WebSocket('ws://'+(loc?locip:window.location.hostname)+'/ws');
mySocket.onmessage = function(event) { mySocket.onmessage = function(event) {
// event.data contains JSON state/info object var json = JSON.parse(event.data);
// we should parse it instead of calling requestJson() handleJson(json.state);
//requestJson(/*{'v':true},false*/);
console.log(event.data);
handleJson(event.data);
updateUI(true); updateUI(true);
} }
} }
@ -1051,12 +1048,13 @@ function requestJson(command, rinfo = true, verbose = true, callback = null)
jsonTimeout = null; jsonTimeout = null;
clearErrorToast(); clearErrorToast();
d.getElementById('connind').style.backgroundColor = "#070"; d.getElementById('connind').style.backgroundColor = "#070";
if (!json) showToast('Empty response', true); if (!json) { showToast('Empty response', true); return; }
if (json.error && json.error != 0) { showToast('Out of memory!', true); return; }
if (json.success) { if (json.success) {
if (callback) callback(); if (callback) callback();
return; return;
} }
var s = json; var s = json.state;
if (!command || rinfo) { if (!command || rinfo) {
if (!rinfo) { if (!rinfo) {
pmt = json.info.fs.pmt; pmt = json.info.fs.pmt;
@ -1082,7 +1080,6 @@ function requestJson(command, rinfo = true, verbose = true, callback = null)
d.getElementById('buttonNodes').style.display = (info.ndc > 0 && window.innerWidth > 770) ? "block":"none"; d.getElementById('buttonNodes').style.display = (info.ndc > 0 && window.innerWidth > 770) ? "block":"none";
lastinfo = info; lastinfo = info;
if (isInfo) populateInfo(info); if (isInfo) populateInfo(info);
s = json.state;
displayRover(info, s); displayRover(info, s);
} }
@ -1092,51 +1089,7 @@ function requestJson(command, rinfo = true, verbose = true, callback = null)
if (callback) callback(); if (callback) callback();
return; return;
} }
/*
isOn = s.on;
d.getElementById('sliderBri').value= s.bri;
nlA = s.nl.on;
nlDur = s.nl.dur;
nlTar = s.nl.tbri;
nlFade = s.nl.fade;
syncSend = s.udpn.send;
currentPreset = s.ps;
d.getElementById('cyToggle').checked = (s.pl >= 0);
d.getElementById('cycs').value = s.ccnf.min;
d.getElementById('cyce').value = s.ccnf.max;
d.getElementById('cyct').value = s.ccnf.time /10;
d.getElementById('cyctt').value = s.transition /10;
var selc=0; var ind=0;
populateSegments(s);
for (let i = 0; i < (s.seg||[]).length; i++)
{
if(s.seg[i].sel) {selc = ind; break;} ind++;
}
var i=s.seg[selc];
if (!i) {
showToast('No Segments!', true);
updateUI(false);
if (callback) callback();
return;
}
selColors = i.col;
var cd = d.getElementById('csl').children;
for (let e = 2; e >= 0; e--)
{
cd[e].style.backgroundColor = "rgb(" + i.col[e][0] + "," + i.col[e][1] + "," + i.col[e][2] + ")";
if (isRgbw) whites[e] = parseInt(i.col[e][3]);
selectSlot(csel);
}
d.getElementById('sliderSpeed').value = whites[csel];
d.getElementById('sliderSpeed').value = i.sx;
d.getElementById('sliderIntensity').value = i.ix;
selectedPal = i.pal;
selectedFx = i.fx;
*/
if (s.error && s.error != 0) { if (s.error && s.error != 0) {
var errstr = ""; var errstr = "";
switch (s.error) { switch (s.error) {

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2103190 #define VERSION 2103191
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG