cotestatnt / async-esp-fs-webserver

ESP32/ESP8266 WebServer, WiFi manager and ACE web editor Arduino library. Based on ESPAsyncWebServer
Apache License 2.0
33 stars 10 forks source link

Adding binary transfer option for websockets #37

Open j-nik opened 1 month ago

j-nik commented 1 month ago

In AsyncFsWebServer.h you have the following to allow a websocket broadcast of a text message:

/*
 * Broadcast a websocket message to all clients connected
*/
void wsBroadcast(const char * buffer) {
  m_ws->textAll(buffer);
}

I've added the following below this to allow broadcasts of an array of bytes, which I find quite useful:

/*
 * Broadcast a binary websocket message to all clients connected
*/
void wsBroadcastBinary(uint8_t * message, size_t len) {
  m_ws->binaryAll(message, len);
}
j-nik commented 1 month ago

If you do so augment your library, I've written an example you could consider adding.

https://forum.arduino.cc/t/binary-data-over-websockets-with-the-asyncespfswebserver-library/1258142/3