Browse Source

Allow multi-packet websocket frames

fastled
Xose Pérez 8 years ago
parent
commit
cd591f70d6
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      code/espurna/web.ino

+ 23
- 1
code/espurna/web.ino View File

@ -382,6 +382,8 @@ bool _wsAuth(AsyncWebSocketClient * client) {
void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
static uint8_t * message;
// Authorize // Authorize
#ifndef NOWSAUTH #ifndef NOWSAUTH
if (!_wsAuth(client)) return; if (!_wsAuth(client)) return;
@ -398,7 +400,27 @@ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTy
} else if(type == WS_EVT_PONG) { } else if(type == WS_EVT_PONG) {
DEBUG_MSG("[WEBSOCKET] #%u pong(%u): %s\n", client->id(), len, len ? (char*) data : ""); DEBUG_MSG("[WEBSOCKET] #%u pong(%u): %s\n", client->id(), len, len ? (char*) data : "");
} else if(type == WS_EVT_DATA) { } else if(type == WS_EVT_DATA) {
_wsParse(client->id(), data, len);
AwsFrameInfo * info = (AwsFrameInfo*)arg;
// First packet
if (info->index == 0) {
//Serial.printf("Before malloc: %d\n", ESP.getFreeHeap());
message = (uint8_t*) malloc(info->len);
//Serial.printf("After malloc: %d\n", ESP.getFreeHeap());
}
// Store data
memcpy(message + info->index, data, len);
// Last packet
if (info->index + len == info->len) {
_wsParse(client->id(), message, info->len);
//Serial.printf("Before free: %d\n", ESP.getFreeHeap());
free(message);
//Serial.printf("After free: %d\n", ESP.getFreeHeap());
}
} }
} }


Loading…
Cancel
Save