@@ -967,49 +967,17 @@ void handleNotFound(MongooseHttpServerRequest *request)
967967 }
968968}
969969
970- /*
971- void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
972- if(type == WS_EVT_CONNECT) {
973- DBUGF("ws[%s][%u] connect", server->url(), client->id());
974- client->ping();
975- } else if(type == WS_EVT_DISCONNECT) {
976- DBUGF("ws[%s][%u] disconnect: %u", server->url(), client->id());
977- } else if(type == WS_EVT_ERROR) {
978- DBUGF("ws[%s][%u] error(%u): %s", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
979- } else if(type == WS_EVT_PONG) {
980- DBUGF("ws[%s][%u] pong[%u]: %s", server->url(), client->id(), len, (len)?(char*)data:"");
981- } else if(type == WS_EVT_DATA) {
982- AwsFrameInfo * info = (AwsFrameInfo*)arg;
983- String msg = "";
984- if(info->final && info->index == 0 && info->len == len)
985- {
986- //the whole message is in a single frame and we got all of it's data
987- DBUGF("ws[%s][%u] %s-message[%u]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", len);
988- } else {
989- // TODO: handle messages that are comprised of multiple frames or the frame is split into multiple packets
990- }
991- }
970+ void onWsFrame (MongooseHttpWebSocketConnection *connection, int flags, uint8_t *data, size_t len)
971+ {
972+ DBUGF (" Got message %.*s" , len, (const char *)data);
992973}
993- */
994974
995975void
996976web_server_setup () {
997977// SPIFFS.begin(); // mount the fs
998978
999979 server.begin (80 );
1000980
1001- // Setup the static files
1002- // server.serveStatic("/", SPIFFS, "/")
1003- // .setDefaultFile("index.html");
1004-
1005- // Add the Web Socket server
1006- // ws.onEvent(onWsEvent);
1007- // server.addHandler(&ws);
1008- // server.addHandler(&staticFile);
1009-
1010- // Start server & server root html /
1011- // server.on("/", handleHome);
1012-
1013981 // Handle status updates
1014982 server.on (" /status$" , handleStatus);
1015983 server.on (" /config$" , handleConfig);
@@ -1042,6 +1010,8 @@ web_server_setup() {
10421010 onUpload (handleUpdateUpload)->
10431011 onClose (handleUpdateClose);
10441012
1013+ server.on (" /ws$" )->onFrame (onWsFrame);
1014+
10451015 server.onNotFound (handleNotFound);
10461016
10471017 DEBUG.println (" Server started" );
@@ -1081,5 +1051,5 @@ web_server_loop() {
10811051
10821052void web_server_event (String &event)
10831053{
1084- // ws.textAll (event);
1054+ server. sendAll (event);
10851055}
0 commit comments