Additional traces of v2 API removed in WS.

JS cleanup.
This commit is contained in:
Blaz Kristan 2021-06-20 21:56:25 +02:00
parent 6f0e944c7e
commit e9d07eadaa
4 changed files with 540 additions and 582 deletions

View File

@ -237,7 +237,6 @@ function onLoad()
if (localStorage.getItem('pcm') == "true") togglePcMode(true);
var sls = d.querySelectorAll('input[type="range"]');
for (var sl of sls) {
//sl.addEventListener('input', updateBubble, true);
sl.addEventListener('touchstart', toggleBubble);
sl.addEventListener('touchend', toggleBubble);
}
@ -1085,13 +1084,15 @@ function handleJson(s)
selectedPal = i.pal;
selectedFx = i.fx;
//if (!gId('fxlist').querySelector(`input[name="fx"][value="${i.fx}"]`)) location.reload(); //effect list is gone (e.g. if restoring tab). Reload.
displayRover(lastinfo, s);
clearErrorToast();
return true;
}
var jsonTimeout, refreshTimer;
var jsonTimeout;
function requestJson(command, rinfo = true, verbose = true, callback = null)
{
gId('connind').style.backgroundColor = "#a90";

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -8,11 +8,6 @@
uint16_t wsLiveClientId = 0;
unsigned long wsLastLiveTime = 0;
//uint8_t* wsFrameBuffer = nullptr;
uint8_t vAPI = 2;
struct client_api {
uint32_t c = 0;
uint8_t vAPI = 1;
} ClientApis[DEFAULT_MAX_WS_CLIENTS];
#define WS_LIVE_INTERVAL 40
@ -20,25 +15,11 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
{
if(type == WS_EVT_CONNECT){
//client connected
for (uint8_t i=0; i<DEFAULT_MAX_WS_CLIENTS; i++) {
if (ClientApis[i].c) continue; // used slot
ClientApis[i].c = client->id();
ClientApis[i].vAPI = 1;
DEBUG_PRINTF("New WS client [%d]: %d\n", (int)i, client->id());
break;
}
sendDataWs(client);
//client->ping();
} else if(type == WS_EVT_DISCONNECT){
//client disconnected
if (client->id() == wsLiveClientId) wsLiveClientId = 0;
for (uint8_t i=0; i<DEFAULT_MAX_WS_CLIENTS; i++) {
if (ClientApis[i].c != client->id()) continue;
ClientApis[i].c = 0; // clear slot
ClientApis[i].vAPI = 1;
DEBUG_PRINTF("Removed WS client [%d]: %d\n", (int)i, client->id());
break;
}
} else if(type == WS_EVT_DATA){
//data packet
AwsFrameInfo * info = (AwsFrameInfo*)arg;
@ -57,15 +38,6 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
{
wsLiveClientId = root["lv"] ? client->id() : 0;
}
if (root.containsKey("rev"))
{
for (uint8_t i=0; i<DEFAULT_MAX_WS_CLIENTS; i++) {
if (ClientApis[i].c != client->id()) continue;
ClientApis[i].vAPI = root["rev"];
DEBUG_PRINTF("API for WS client [%d]: %d\n", (int)i, (int)ClientApis[i].vAPI);
break;
}
}
verboseResponse = deserializeState(root);
}
if (verboseResponse || millis() - lastInterfaceUpdate < 1900) sendDataWs(client); //update if it takes longer than 100ms until next "broadcast"
@ -106,21 +78,6 @@ void sendDataWs(AsyncWebSocketClient * client)
{ //scope JsonDocument so it releases its buffer
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
JsonObject state = doc.createNestedObject("state");
if (client) {
for (uint8_t i=0; i<DEFAULT_MAX_WS_CLIENTS; i++) {
if (ClientApis[i].c != client->id()) continue;
state["rev"] = ClientApis[i].vAPI;
break;
}
} else {
uint8_t minAPI = 2;
for (uint8_t i=0; i<DEFAULT_MAX_WS_CLIENTS; i++) {
if (!ClientApis[i].c) continue;
if (minAPI > ClientApis[i].vAPI) minAPI = ClientApis[i].vAPI;
}
state["rev"] = minAPI;
}
DEBUG_PRINTF("Actual API used: %d\n", (int)state["rev"]);
serializeState(state);
JsonObject info = doc.createNestedObject("info");
serializeInfo(info);