feat: Enhance connection handling and add debug logs feature; improve user experience and troubleshooting

This commit is contained in:
k1ngsterr1
2026-01-17 06:21:26 +05:00
parent a64ee04b55
commit a9e426506b
9 changed files with 148 additions and 145 deletions

View File

@@ -194,6 +194,18 @@ class Protocol(
val currentState = _state.value
log("🔌 CONNECT CALLED: currentState=$currentState, reconnectAttempts=$reconnectAttempts, isConnecting=$isConnecting")
// КРИТИЧНО: Если уже подключены и аутентифицированы - не переподключаемся!
if (currentState == ProtocolState.AUTHENTICATED || currentState == ProtocolState.HANDSHAKING) {
log("✅ Already authenticated or handshaking, skipping connect()")
return
}
// КРИТИЧНО: Если уже CONNECTED и есть credentials - тоже пропускаем
if (currentState == ProtocolState.CONNECTED && webSocket != null) {
log("✅ Already connected with valid socket, skipping connect()")
return
}
// КРИТИЧНО: проверяем флаг isConnecting, а не только состояние
if (isConnecting || currentState == ProtocolState.CONNECTING) {
log("⚠️ Already connecting, skipping... (preventing duplicate connect)")