From af60e018f7a1e46c41bbbd222bb195ddb681efc1 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Fri, 10 Oct 2025 10:57:37 +0300 Subject: [PATCH] add getUrl method --- src/WebSocketsClient.cpp | 13 +++++++++++++ src/WebSocketsClient.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 60a47d3..ea0de6b 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -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; +} + // ################################################################################# // ################################################################################# // ################################################################################# diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index 8294b3c..e1a7a00 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -112,6 +112,7 @@ class WebSocketsClient : protected WebSockets { void disableHeartbeat(); bool isConnected(void); + String getUrl(void); protected: String _host;