Add methods to allow get/set of websocket client ping interval

This commit is contained in:
2022-04-26 11:06:20 +02:00
parent 6e4d8a19ed
commit e55f54b69e
2 changed files with 51 additions and 0 deletions

View File

@ -902,6 +902,38 @@ bool esp_websocket_client_is_connected(esp_websocket_client_handle_t client)
return client->state == WEBSOCKET_STATE_CONNECTED;
}
size_t esp_websocket_client_get_ping_interval_sec(esp_websocket_client_handle_t client)
{
if (client == NULL) {
ESP_LOGW(TAG, "Client was not initialized");
return 0;
}
if (client->config == NULL) {
ESP_LOGW(TAG, "No config available to change the ping interval");
return 0;
}
return client->config->ping_interval_sec;
}
esp_err_t esp_websocket_client_set_ping_interval_sec(esp_websocket_client_handle_t client, size_t ping_interval_sec)
{
if (client == NULL) {
ESP_LOGW(TAG, "Client was not initialized");
return ESP_ERR_INVALID_ARG;
}
if (client->config == NULL) {
ESP_LOGW(TAG, "No config available to change the ping interval");
return ESP_ERR_INVALID_STATE;
}
client->config->ping_interval_sec = ping_interval_sec == 0 ? WEBSOCKET_PING_INTERVAL_SEC : ping_interval_sec;
return ESP_OK;
}
esp_err_t esp_websocket_register_events(esp_websocket_client_handle_t client,
esp_websocket_event_id_t event,
esp_event_handler_t event_handler,