Commit 6fe34089 authored by Lisa (AI Assistant)'s avatar Lisa (AI Assistant)

Fix: Always send connect first, then pairing request after rejection

parent ed8270c3
...@@ -227,15 +227,12 @@ class NodeClient() { ...@@ -227,15 +227,12 @@ class NodeClient() {
hasReceivedChallenge = true hasReceivedChallenge = true
Log.d(TAG, "Received challenge: nonce=$challengeNonce, ts=$challengeTimestamp") Log.d(TAG, "Received challenge: nonce=$challengeNonce, ts=$challengeTimestamp")
// Check if we need to send pairing request instead of connect // BUG FIX: Always send connect first - the gateway requires "connect" as the first request
if (pendingPairingAfterConnect) { // If connect is rejected with "device-required", we handle that in the response handler
pendingPairingAfterConnect = false // This was causing "invalid handshake: first request must be connect" error
Log.d(TAG, "Sending pairing request after reconnect") pendingPairingAfterConnect = false
sendPairingRequest(nodeId, token, capabilities) Log.d(TAG, "Always sending connect request first (protocol requirement)")
} else { sendConnectRequestWithChallenge(nodeId, token, capabilities)
// Now send connect request with proper v3 signature
sendConnectRequestWithChallenge(nodeId, token, capabilities)
}
} else if (event == "node.pair.resolved") { } else if (event == "node.pair.resolved") {
// Pairing was approved, now reconnect with token // Pairing was approved, now reconnect with token
val approved = json.optJSONObject("payload")?.optBoolean("approved", false) val approved = json.optJSONObject("payload")?.optBoolean("approved", false)
...@@ -263,9 +260,10 @@ class NodeClient() { ...@@ -263,9 +260,10 @@ class NodeClient() {
if ((error?.contains("device-required") == true || if ((error?.contains("device-required") == true ||
error?.contains("device signature") == true || error?.contains("device signature") == true ||
error?.contains("invalid") == true) && isPairingMode) { error?.contains("invalid") == true) && isPairingMode) {
// Set flag to send pairing request after reconnect // Device not paired - send pairing request on THIS connection
pendingPairingAfterConnect = true Log.d(TAG, "Device not paired, sending pairing request")
Log.d(TAG, "Will send pairing request on reconnect after connection rejection") sendPairingRequest(nodeId, token, capabilities)
// Don't close - wait for pairing response
} else { } else {
_connectionStatus.trySend(ConnectionStatus(false, nodeId)) _connectionStatus.trySend(ConnectionStatus(false, nodeId))
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment