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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user