feat: add android multicast lock, network config, and connection ack handling

This commit is contained in:
brontomark committed 2026-11-13 09:25:16 +01:00
1 parent 6a8729a147
commit 2d94be87ae
10 files changed
+344 -29

No files matched your search

+32 -8
View File
@@ -230,7 +230,7 @@ class BarcodeServerCore:
async def handle_type_post(request: web.Request) -> web.Response:
if not self.is_listening:
return web.json_response({"status": "paused", "message": "Server in pausa"}, status=503)
return web.json_response({"status": "paused", "message": "Server in pausa", "success": False}, status=503)
try:
data = await request.json()
@@ -240,10 +240,10 @@ class BarcodeServerCore:
required_pin = str(self.config.get("pin", "")).strip()
if required_pin and pin != required_pin:
return web.json_response({"status": "error", "message": "PIN errato"}, status=401)
return web.json_response({"status": "error", "message": "PIN errato", "success": False}, status=401)
if not code:
return web.json_response({"status": "error", "message": "Nessun codice fornito"}, status=400)
return web.json_response({"status": "error", "message": "Nessun codice fornito", "success": False}, status=400)
suffix = data.get("suffix") or self.config.get("suffix", "enter")
success = await self.kb.type_text(code, suffix=suffix)
@@ -259,7 +259,7 @@ class BarcodeServerCore:
return web.json_response({"status": "ok", "typed": code, "success": success})
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
return web.json_response({"status": "error", "message": str(e), "success": False}, status=500)
async def handle_websocket(request: web.Request) -> web.WebSocketResponse:
ws = web.WebSocketResponse(heartbeat=25.0)
@@ -301,12 +301,23 @@ class BarcodeServerCore:
})
elif msg_type == "scan":
req_id = payload.get("req_id")
if not authenticated:
await ws.send_json({"type": "auth_error", "message": "Autenticazione richiesta"})
await ws.send_json({
"type": "auth_error",
"message": "Autenticazione richiesta",
"req_id": req_id,
})
continue
if not self.is_listening:
await ws.send_json({"type": "paused", "message": "Server in pausa"})
await ws.send_json({
"type": "ack",
"code": payload.get("code", ""),
"success": False,
"message": "Server in pausa",
"req_id": req_id,
})
continue
code = str(payload.get("code", "")).strip()
@@ -323,12 +334,25 @@ class BarcodeServerCore:
if self.on_scan:
self.on_scan(code, client_name, success)
await ws.send_json({
ack_data = {
"type": "ack",
"code": code,
"success": success,
"time": timestamp,
})
}
if req_id is not None:
ack_data["req_id"] = req_id
await ws.send_json(ack_data)
else:
ack_data = {
"type": "ack",
"code": "",
"success": False,
"message": "Codice vuoto",
}
if req_id is not None:
ack_data["req_id"] = req_id
await ws.send_json(ack_data)
elif msg_type == "ping":
await ws.send_json({"type": "pong"})