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 socket: WebSocket? = null
|
||||||
private var released = false
|
private var released = false
|
||||||
private var ready = false
|
private var ready = false
|
||||||
|
private var authReceived = false
|
||||||
|
|
||||||
fun connect() {
|
fun connect() {
|
||||||
checkMainThread()
|
checkMainThread()
|
||||||
check(!released) { "DialogueClient has been released" }
|
check(!released) { "DialogueClient has been released" }
|
||||||
generation++
|
generation++
|
||||||
ready = false
|
ready = false
|
||||||
|
authReceived = false
|
||||||
socket?.cancel()
|
socket?.cancel()
|
||||||
socket = null
|
socket = null
|
||||||
onStatus(ConnectionStatus.DISCONNECTED)
|
onStatus(ConnectionStatus.DISCONNECTED)
|
||||||
@@ -107,12 +109,8 @@ class DialogueClient(
|
|||||||
|
|
||||||
private fun listener(attempt: Long) = object : WebSocketListener() {
|
private fun listener(attempt: Long) = object : WebSocketListener() {
|
||||||
override fun onOpen(webSocket: WebSocket, response: Response) = dispatch(attempt, webSocket) {
|
override fun onOpen(webSocket: WebSocket, response: Response) = dispatch(attempt, webSocket) {
|
||||||
if (webSocket.send(DialogueProtocol.hello())) {
|
// Server sends auth-ok first (LAN direct/guest cookie/admin bearer), then expects hello.
|
||||||
ready = true
|
// Do not send hello here; wait for the auth event in onMessage.
|
||||||
onStatus(ConnectionStatus.CONNECTED)
|
|
||||||
} else {
|
|
||||||
finish(webSocket, ConnectionStatus.DISCONNECTED)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessage(webSocket: WebSocket, text: String) = dispatch(attempt, webSocket) {
|
override fun onMessage(webSocket: WebSocket, text: String) = dispatch(attempt, webSocket) {
|
||||||
@@ -122,6 +120,16 @@ class DialogueClient(
|
|||||||
onProtocolError(error.message ?: "Invalid JSON event")
|
onProtocolError(error.message ?: "Invalid JSON event")
|
||||||
return@dispatch
|
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)
|
onEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user