1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-22 14:20:53 +00:00

#5 fixing textThem to function properly

This commit is contained in:
Lukas Bachschwell 2017-12-26 21:10:54 +01:00
parent 679bf1a5c1
commit c72bff5b2e

View File

@ -95,12 +95,17 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
Serial.printf("Disconnected!\n"); Serial.printf("Disconnected!\n");
break; break;
case WS_EVT_CONNECT: { case WS_EVT_CONNECT: {
if (debug) if (debug){
Serial.println("Connected"); Serial.print("Connected: ");
Serial.println(client->id());
}
ESPUI.jsonDom(client); ESPUI.jsonDom(client);
if (debug) if (debug){
Serial.println("JSON Data Sent to Client!"); Serial.println("JSON Data Sent to Client!");
} break; }
}
break;
case WS_EVT_DATA: case WS_EVT_DATA:
String msg = ""; String msg = "";
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
@ -337,11 +342,17 @@ void ESPUIClass::updateSwitcher(String label, bool nValue, int clientId) {
updateSwitcher(getIdByLabel(label), nValue, clientId); updateSwitcher(getIdByLabel(label), nValue, clientId);
} }
// This is a hacky workaround because ESPAsyncWebServer does not have a function like this and it's clients array is private
void ESPUIClass::textThem(String text, int clientId){ void ESPUIClass::textThem(String text, int clientId){
for(int i = 1; i <= this->ws->count(); i++){ int tryId = 0;
if(clientId!=i){ for(int count = 0; count < this->ws->count();){
this->ws->client(i)->text(text); if(this->ws->hasClient(tryId)) {
if(clientId!=tryId){
this->ws->client(tryId)->text(text);
} }
count++;
}
tryId++;
} }
} }