From 37a07c0c122ff1f8f430f4c5e61106b7eb46d962 Mon Sep 17 00:00:00 2001 From: padreug Date: Thu, 18 Sep 2025 11:21:44 +0200 Subject: [PATCH] Refactor ping mechanism in WalletWebSocketService for improved connection stability - Updated the ping method to send a simple text message instead of using the unsupported ping method in browser WebSocket implementations. - Enhanced logging to indicate potential connection instability when ping fails. These changes improve the reliability of the WebSocket connection management, contributing to a more stable user experience. --- src/modules/wallet/services/WalletWebSocketService.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/wallet/services/WalletWebSocketService.ts b/src/modules/wallet/services/WalletWebSocketService.ts index 0192d19..31518be 100644 --- a/src/modules/wallet/services/WalletWebSocketService.ts +++ b/src/modules/wallet/services/WalletWebSocketService.ts @@ -406,10 +406,11 @@ export class WalletWebSocketService extends BaseService { private sendPing(): void { if (this.ws && this.ws.readyState === WebSocket.OPEN) { try { - // Send a ping frame (most WebSocket implementations support this) - this.ws.ping?.() + // Send a simple ping message (browser WebSocket doesn't have ping method) + // Most WebSocket servers respond to text messages as keepalive + this.ws.send(JSON.stringify({ type: 'ping' })) } catch (error) { - console.log('WalletWebSocketService: Ping not supported, connection seems stable') + console.log('WalletWebSocketService: Ping failed, connection may be unstable') } } }