Skip to content

esp_websocket_client: filter client received PONG response (or add event...) (IDFGH-14804) #777

@microfoundry

Description

@microfoundry

Is your feature request related to a problem?

Currently when esp_websocket_client_recv() processes a PONG response it will be dispatched to the client event handler as a WEBSOCKET_EVENT_DATA with NULL data and zero length.

Describe the solution you'd like.

I would like to propose 3 options:

  1. Filter it out all together:
/**
* esp_websocket_client_recv()
*/
        if (client->last_opcode != WS_TRANSPORT_OPCODES_PONG) {
            esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_DATA, client->rx_buffer, rlen);
        } else {
            ESP_LOGD(TAG, "Skipping event dispatch for PONG frame.");
        }
  1. Add a specific WEBSOCKET_EVENT_PONG to esp_websocket_event_id_t to allow it to be properly identified and handled by the client event function:
        if (client->last_opcode != WS_TRANSPORT_OPCODES_PONG) {
            esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_DATA, client->rx_buffer, rlen);
        } else {
            esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_PONG, client->rx_buffer, rlen);
        }
  1. Add a define/config option for user choice.

Describe alternatives you've considered.

See above

Additional context.

I chose option 1 as I have no need to process PONG responses at an app level. But someone might find value in the distinct ability to process PONGs at an application level...

Just to note, the AsyncWebSocket (in EAPAsyncWebServer) bubbles up those events:

typedef enum {
  WS_EVT_CONNECT,
  WS_EVT_DISCONNECT,
  WS_EVT_PING,
  WS_EVT_PONG,
  WS_EVT_ERROR,
  WS_EVT_DATA
} AwsEventType;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions