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:
@@ -157,3 +157,26 @@ test('wsUrlFor', () => {
|
||||
assert.equal(wsUrlFor('/api/ws/connect?token=a', 'https://10.0.2.2:18443'), 'wss://10.0.2.2:18443/api/ws/connect?token=a')
|
||||
assert.equal(wsUrlFor('/api/ws/connect', 'http://192.168.1.5'), 'ws://192.168.1.5/api/ws/connect')
|
||||
})
|
||||
|
||||
test('credentials go in the first frame (empty ones left out); refusals reach onRefused', async () => {
|
||||
FakeWS.all = []
|
||||
const refused = []
|
||||
const events = []
|
||||
const live = createLiveClient({
|
||||
url: 'ws://venue/api/ws/connect',
|
||||
credentials: () => ({ device: 'dev-token', token: null }),
|
||||
onEvent: (type, data) => events.push([type, data]),
|
||||
onRefused: code => refused.push(code),
|
||||
WebSocketImpl: FakeWS, windowTarget: new FakeWindow(), timers: fakeTimers(),
|
||||
})
|
||||
await live.start()
|
||||
const ws = FakeWS.all.at(-1)
|
||||
assert.equal(ws.url, 'ws://venue/api/ws/connect')
|
||||
ws.open()
|
||||
assert.deepEqual(ws.sent, [{ cursor: 0, device: 'dev-token' }])
|
||||
ws.msg({ type: 'refused', data: { code: 'device.revoked' } })
|
||||
ws.msg({ type: 'device.updated', data: { device_id: 3 } })
|
||||
assert.deepEqual(refused, ['device.revoked'])
|
||||
assert.deepEqual(events, [['device.updated', { device_id: 3 }]])
|
||||
live.stop()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user