Compare commits

...

4 Commits

Author SHA1 Message Date
dependabot[bot]
fa150b41c9 Bump actions/cache from 4 to 5 (#967)
Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-15 11:58:43 +01:00
dependabot[bot]
c97b15e575 Bump actions/upload-artifact from 4 to 6 (#968)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-15 11:58:17 +01:00
Razvan Grigore
84f379474d add client disconnect reason text in events (#957) 2025-10-24 16:28:16 +02:00
Razvan Grigore
6801736f98 add getUrl method (#955) 2025-10-17 17:22:47 +02:00
6 changed files with 42 additions and 14 deletions

View File

@@ -62,7 +62,7 @@ jobs:
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
- name: Save sketches report as workflow artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
path: ${{ env.SKETCHES_REPORTS_PATH }}

View File

@@ -74,7 +74,7 @@ jobs:
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
- name: Save sketches report as workflow artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
path: ${{ env.SKETCHES_REPORTS_PATH }}

View File

@@ -53,7 +53,7 @@ jobs:
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
- name: Save sketches report as workflow artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
path: ${{ env.SKETCHES_REPORTS_PATH }}

View File

@@ -69,7 +69,7 @@ jobs:
echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
- uses: actions/cache@v5
id: cache_all
with:
path: |
@@ -128,7 +128,7 @@ jobs:
echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
- uses: actions/cache@v5
id: cache_all
with:
path: |

View File

@@ -478,6 +478,19 @@ bool WebSocketsClient::isConnected(void) {
return (_client.status == WSC_CONNECTED);
}
/**
* RFC 6455
* get the full URL/URI of the connection
*/
String WebSocketsClient::getUrl(void) {
#if defined(HAS_SSL)
String protocol = (_client.isSSL) ? WEBSOCKETS_STRING("wss://") : WEBSOCKETS_STRING("ws://");
#else
String protocol = WEBSOCKETS_STRING("ws://");
#endif
return protocol + _host + ":" + String(_port) + _client.cUrl;
}
// #################################################################################
// #################################################################################
// #################################################################################
@@ -519,10 +532,11 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
}
/**
* Disconnect an client
* Disconnect a client
* @param client WSclient_t * ptr to the client struct
* @param reason const char * disconnect reason (optional, defaults to NULL)
*/
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
void WebSocketsClient::clientDisconnect(WSclient_t * client, const char * reason) {
bool event = false;
#ifdef HAS_SSL
@@ -571,7 +585,11 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
DEBUG_WEBSOCKETS("[WS-Client] client disconnected.\n");
if(event) {
runCbEvent(WStype_DISCONNECTED, NULL, 0);
if(reason && strlen(reason) > 0) {
runCbEvent(WStype_DISCONNECTED, (uint8_t *)reason, strlen(reason));
} else {
runCbEvent(WStype_DISCONNECTED, NULL, 0);
}
}
}
@@ -594,13 +612,13 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
if(client->status != WSC_NOT_CONNECTED) {
DEBUG_WEBSOCKETS("[WS-Client] connection lost.\n");
// do cleanup
clientDisconnect(client);
clientDisconnect(client, "Connection lost");
}
}
if(client->tcp) {
// do cleanup
clientDisconnect(client);
clientDisconnect(client, "TCP connection cleanup");
}
return false;
@@ -612,7 +630,7 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
void WebSocketsClient::handleClientData(void) {
if((_client.status == WSC_HEADER || _client.status == WSC_BODY) && _lastHeaderSent + WEBSOCKETS_TCP_TIMEOUT < millis()) {
DEBUG_WEBSOCKETS("[WS-Client][handleClientData] header response timeout.. disconnecting!\n");
clientDisconnect(&_client);
clientDisconnect(&_client, "Header response timeout");
WEBSOCKETS_YIELD();
return;
}
@@ -847,7 +865,9 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
default: ///< Server dont unterstand requrst
ok = false;
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] serverCode is not 101 (%d)\n", client->cCode);
clientDisconnect(client);
// Create disconnect reason with HTTP status code
String reason = "HTTP " + String(client->cCode);
clientDisconnect(client, reason.c_str());
_lastConnectionFail = millis();
break;
}
@@ -891,7 +911,11 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
if(clientIsConnected(client)) {
write(client, "This is a webSocket client!");
}
clientDisconnect(client);
String reason = "WebSocket handshake failed";
if(client->cCode > 0) {
reason += " - HTTP " + String(client->cCode);
}
clientDisconnect(client, reason.c_str());
}
}
}

View File

@@ -112,6 +112,7 @@ class WebSocketsClient : protected WebSockets {
void disableHeartbeat();
bool isConnected(void);
String getUrl(void);
protected:
String _host;
@@ -156,7 +157,10 @@ class WebSocketsClient : protected WebSockets {
void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin);
void clientDisconnect(WSclient_t * client);
void clientDisconnect(WSclient_t * client) {
clientDisconnect(client, NULL);
}
void clientDisconnect(WSclient_t * client, const char * reason = NULL);
bool clientIsConnected(WSclient_t * client);
#if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)