Added WS_PING event

This commit is contained in:
Mathieu Carbou
2024-11-21 00:36:45 +01:00
parent 0eba19d8bf
commit f0eb0acb2f
2 changed files with 3 additions and 1 deletions

View File

@ -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)

View File

@ -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;