feat(backend): live connection and per-device settings for paired screens (platform-v2 3.1a)
- WebSocket: credentials may come in the first frame ({cursor, token?, device?}).
A device token alone connects a paired screen (login-none apps get every event, a
sign-in app only events addressed to it); a terminal session's JWT needs its own
device, as over HTTP. Refusals send {type: refused, data: {code}} + close 4001/4003.
- ws_bus: registry of open sockets by user, session and device. Ending a session
closes its sockets (session.ended); revoke/reassign close the device's sockets
(device.revoked / device.updated); edits and module on/off send device.updated.
Events can target devices (device_ids=..., sync_events.target_device_ids, rev 0014).
Pushes go through each socket's own loop (call_soon_threadsafe).
- Device config: DeviceApp.config = typed ConfigFields, validated on pair/edit/
reassign (validation.device_config), effective values (defaults filled) in both
device views and the module catalogue. First field: auto_sign_out_minutes (KDS, POS).
- Manager: DeviceConfigFields renders an app's fields in the pair and edit dialogs.
- @xenia/api createLiveClient: `credentials` and `onRefused` options.
- Tests: tests/test_live.py (11), module texts for config fields, live client,
devices logic, manager.mjs device setting + live socket checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,7 +63,7 @@ def test_pairing_flow(client, owner_h):
|
||||
# the manager types the code (case and dashes don't matter)
|
||||
typed = f"{code[:3].lower()}-{code[3:]}"
|
||||
r = client.post("/api/devices", headers=owner_h,
|
||||
json={"code": typed, "app_key": "kds", "name": "Bar KDS", "config": {"prep_zone_id": 2}})
|
||||
json={"code": typed, "app_key": "kds", "name": "Bar KDS", "config": {"auto_sign_out_minutes": 5}})
|
||||
assert r.status_code == 201, r.text
|
||||
d = r.json()
|
||||
assert d["claimed"] is False and d["user_agent"] == "KDS-Box" and d["effective_login_mode"] == "pin"
|
||||
@@ -74,7 +74,7 @@ def test_pairing_flow(client, owner_h):
|
||||
poll = client.get(f"/api/devices/pair-request/{code}", headers={"X-Xenia-Pair-Secret": secret})
|
||||
assert poll.status_code == 200
|
||||
token = poll.json()["device_token"]
|
||||
assert poll.json()["device"]["config"] == {"prep_zone_id": 2} and poll.json()["device"]["app_status"] == "ok"
|
||||
assert poll.json()["device"]["config"] == {"auto_sign_out_minutes": 5} and poll.json()["device"]["app_status"] == "ok"
|
||||
# the token is handed out exactly once
|
||||
assert err(client.get(f"/api/devices/pair-request/{code}", headers={"X-Xenia-Pair-Secret": secret})) \
|
||||
== "device.pair_code_invalid"
|
||||
|
||||
Reference in New Issue
Block a user