From f0eb0acb2fd61fd0cd04b5bc0021877ff8e0b14c Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Thu, 21 Nov 2024 00:36:45 +0100 Subject: [PATCH] Added WS_PING event --- src/AsyncWebSocket.cpp | 3 ++- src/AsyncWebSocket.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index f92dbc9..b89c0d5 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -568,10 +568,11 @@ void AsyncWebSocketClient::_onData(void* pbuf, size_t plen) { _queueControl(WS_DISCONNECT, data, datalen); } } else if (_pinfo.opcode == WS_PING) { + _server->_handleEvent(this, WS_EVT_PING, NULL, NULL, 0); _queueControl(WS_PONG, data, datalen); } else if (_pinfo.opcode == WS_PONG) { if (datalen != AWSC_PING_PAYLOAD_LEN || memcmp(AWSC_PING_PAYLOAD, data, AWSC_PING_PAYLOAD_LEN) != 0) - _server->_handleEvent(this, WS_EVT_PONG, NULL, data, datalen); + _server->_handleEvent(this, WS_EVT_PONG, NULL, NULL, 0); } else if (_pinfo.opcode < WS_DISCONNECT) { // continuation or text/binary frame _server->_handleEvent(this, WS_EVT_DATA, (void*)&_pinfo, data, datalen); if (_pinfo.final) diff --git a/src/AsyncWebSocket.h b/src/AsyncWebSocket.h index 8ad06ea..671c866 100644 --- a/src/AsyncWebSocket.h +++ b/src/AsyncWebSocket.h @@ -104,6 +104,7 @@ typedef enum { WS_MSG_SENDING, WS_MSG_ERROR } AwsMessageStatus; typedef enum { WS_EVT_CONNECT, WS_EVT_DISCONNECT, + WS_EVT_PING, WS_EVT_PONG, WS_EVT_ERROR, WS_EVT_DATA } AwsEventType;