From 218d905e63cee7a0a6dc26e019c7c9de611f964f Mon Sep 17 00:00:00 2001 From: zenord Date: Sun, 11 Oct 2026 11:38:13 +0800 Subject: [PATCH] fix: wait for server auth-ok before sending hello Client sent hello immediately on WebSocket open, but server sends auth-ok first (LAN direct / guest cookie / admin bearer) and expects hello only after that. Client hello was parsed as auth message, causing silent rejection and permanent disconnected state. Fix: track authReceived, send hello only after AUTH event arrives. Also add manual reconnect button and failure reason display. Version 0.2.1-m5-fix1 --- .../com/gorios/lanvoice/net/DialogueClient.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/gorios/lanvoice/net/DialogueClient.kt b/app/src/main/java/com/gorios/lanvoice/net/DialogueClient.kt index 4ade65b..932b042 100644 --- a/app/src/main/java/com/gorios/lanvoice/net/DialogueClient.kt +++ b/app/src/main/java/com/gorios/lanvoice/net/DialogueClient.kt @@ -46,12 +46,14 @@ class DialogueClient( private var socket: WebSocket? = null private var released = false private var ready = false + private var authReceived = false fun connect() { checkMainThread() check(!released) { "DialogueClient has been released" } generation++ ready = false + authReceived = false socket?.cancel() socket = null onStatus(ConnectionStatus.DISCONNECTED) @@ -107,12 +109,8 @@ class DialogueClient( private fun listener(attempt: Long) = object : WebSocketListener() { override fun onOpen(webSocket: WebSocket, response: Response) = dispatch(attempt, webSocket) { - if (webSocket.send(DialogueProtocol.hello())) { - ready = true - onStatus(ConnectionStatus.CONNECTED) - } else { - finish(webSocket, ConnectionStatus.DISCONNECTED) - } + // Server sends auth-ok first (LAN direct/guest cookie/admin bearer), then expects hello. + // Do not send hello here; wait for the auth event in onMessage. } override fun onMessage(webSocket: WebSocket, text: String) = dispatch(attempt, webSocket) { @@ -122,6 +120,16 @@ class DialogueClient( onProtocolError(error.message ?: "Invalid JSON event") return@dispatch } + if (!authReceived && event.kind == EventKind.AUTH) { + authReceived = true + if (webSocket.send(DialogueProtocol.hello())) { + ready = true + onStatus(ConnectionStatus.CONNECTED) + } else { + finish(webSocket, ConnectionStatus.DISCONNECTED) + } + return@dispatch + } onEvent(event) }