feat: Refactor RecentSearchesManager to support multiple accounts and improve user management
This commit is contained in:
@@ -110,8 +110,9 @@ class Protocol(
|
||||
private fun startHeartbeat(intervalSeconds: Int) {
|
||||
heartbeatJob?.cancel()
|
||||
|
||||
val intervalMs = (intervalSeconds * 1000L) / 2 // Send at half the interval
|
||||
log("💓 Starting heartbeat with interval: ${intervalSeconds}s (sending every ${intervalMs}ms)")
|
||||
// Отправляем чаще - каждые 1/3 интервала (чтобы не терять соединение)
|
||||
val intervalMs = (intervalSeconds * 1000L) / 3
|
||||
log("💓 Starting heartbeat with server interval: ${intervalSeconds}s (sending every ${intervalMs}ms = ${intervalMs/1000}s)")
|
||||
|
||||
heartbeatJob = scope.launch {
|
||||
// ⚡ СРАЗУ отправляем первый heartbeat (как в Архиве)
|
||||
@@ -200,16 +201,17 @@ class Protocol(
|
||||
}
|
||||
|
||||
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
|
||||
log("⚠️ WebSocket closing: code=$code reason='$reason'")
|
||||
log("⚠️ Stack trace at closing:")
|
||||
Thread.currentThread().stackTrace.take(10).forEach {
|
||||
log(" at $it")
|
||||
// Code 3887 - кастомный код сервера, просто делаем reconnect тихо
|
||||
if (code != 3887) {
|
||||
log("⚠️ WebSocket closing: code=$code reason='$reason'")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
|
||||
log("❌ WebSocket closed: code=$code reason='$reason'")
|
||||
log("❌ State was: ${_state.value}")
|
||||
// Для кода 3887 не логируем - это частое закрытие сервером
|
||||
if (code != 3887) {
|
||||
log("❌ WebSocket closed: code=$code reason='$reason'")
|
||||
}
|
||||
handleDisconnect()
|
||||
}
|
||||
|
||||
@@ -358,20 +360,13 @@ class Protocol(
|
||||
|
||||
// Автоматический reconnect (простая логика как в Архиве - без счётчиков)
|
||||
if (!isManuallyClosed) {
|
||||
log("🔄 Connection lost from $previousState, attempting to reconnect...")
|
||||
log("🔄 Reconnecting in ${RECONNECT_INTERVAL}ms")
|
||||
log("🔄 Reconnecting silently...")
|
||||
|
||||
scope.launch {
|
||||
delay(RECONNECT_INTERVAL)
|
||||
// Быстрый reconnect - 1 секунда
|
||||
delay(1000L)
|
||||
if (!isManuallyClosed) {
|
||||
connect()
|
||||
// В Desktop проверяется socket?.readyState == WebSocket.OPEN
|
||||
// В Android аналог - проверка state
|
||||
if (_state.value == ProtocolState.CONNECTED ||
|
||||
_state.value == ProtocolState.AUTHENTICATED) {
|
||||
return@launch
|
||||
}
|
||||
// В Desktop emit('reconnect') происходит здесь
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user