diff --git a/it0_app/lib/core/network/websocket_client.dart b/it0_app/lib/core/network/websocket_client.dart index 5633e8a..efed8bb 100644 --- a/it0_app/lib/core/network/websocket_client.dart +++ b/it0_app/lib/core/network/websocket_client.dart @@ -30,6 +30,18 @@ class WebSocketClient { _lastPath = path; _lastToken = token; + // Close previous connection to prevent duplicate event delivery + if (_channel != null) { + _heartbeatTimer?.cancel(); + try { + await _channel!.sink.close(); + } catch (_) { + // Ignore errors when closing stale connections + } + _channel = null; + _isConnected = false; + } + final uri = Uri.parse('$baseUrl$path'); try { _channel = IOWebSocketChannel.connect(