You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.
I have a similar issue after switching from esphome/ESPAsyncWebServer-esphome.
The issues is that socket.textAll() doesn't seem to work in a socket event handler.
Code looks like this:
AsyncWebSocket websocket("/ws");
int clients_connected = 0;
String test_msg = "A new client connected!";
// Socket event handlervoidonSocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
switch (type) {
case WS_EVT_CONNECT:
++clients_connected;
websocket.textAll(test_msg); // This message is not received by clients.// This is being executed correctly when a new client connects
Serial.print("[Websocket] Client ");
Serial.print(client->id());
Serial.print(" connected with IP: ");
Serial.println(client->remoteIP());
break;
case WS_EVT_DISCONNECT:
--clients_connected;
.
.
.
}
}
// Called in setup()voidinitWebsocket() {
websocket.onEvent(onSocketEvent);
}
With the esphome branch of ESPAsyncWebserver this worked fine with multiple clients connected. The message/s sent are also very small. It is only in the event handler that websocket.textAll() doesn't work. In the loop() it works just fine.
But I found out that it only affects the new socket client that just connected and caused the WS_EVT_CONNECTED event type.
All other previously connected clients receive the message. For example:
Client 1 and Client 2 are connected to websocket.
Now a third client, Client 3 connects and causes the text_msg to be sent from inside the event handler to all clients, but it is only received by Client 1 & 2.
If I send the message directly to the client from within the event handler, e.g.
WS_EVT_CONNECT callback is called from the AsyncWebSocketClient's constructor (which is probably wrong place for user code's callbacks) when object is not yet linked to a list of server's clients.
I have a similar issue after switching from esphome/ESPAsyncWebServer-esphome.
The issues is that
socket.textAll()
doesn't seem to work in a socket event handler.Code looks like this:
With the esphome branch of ESPAsyncWebserver this worked fine with multiple clients connected. The message/s sent are also very small. It is only in the event handler that
websocket.textAll()
doesn't work. In the loop() it works just fine.I tried both AsyncTCP and AsyncTCPSock.
Originally posted by @stefan-wr in #65 (reply in thread)
The text was updated successfully, but these errors were encountered: