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:
2026-11-14 16:31:59 +02:00
co-authored by Claude Opus 5.5
parent 034426f870
commit bda5cde92b
31 changed files with 974 additions and 145 deletions
@@ -0,0 +1,61 @@
// Per-device settings of an app, rendered from its manifest (plan step 3.1a): the
// fields come from GET /api/platform/modules → device_app.config, the texts from
// modules:<app>.config.<key>.{label,hint,choices.<value>}. The backend validates them
// (validation.device_config). Used by the pair and edit dialogs of DevicesPage.
import { useEffect, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { Field, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { configValue, refOptions } from './devicesLogic'
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
const { t } = useTranslation('manager')
const needsZones = fields.some(f => f.choices_from === 'prep_zones')
const [zones, setZones] = useState([])
useEffect(() => {
if (!needsZones) return undefined
let alive = true
client.get('/api/prep-zones').then(r => { if (alive) setZones(r.data) }).catch(() => {})
return () => { alive = false }
}, [needsZones])
if (!fields.length) return null
const base = key => `modules:${appKey}.config.${key}`
const set = (f, raw) => onChange({ ...value, [f.key]: configValue(f, raw) })
return (
<div className="grid gap-4" data-testid="device-config">
{fields.map(f => {
const label = t(`${base(f.key)}.label`, { defaultValue: f.key })
const hint = t(`${base(f.key)}.hint`, { defaultValue: '' }) || undefined
const v = value?.[f.key]
if (f.type === 'bool') {
return <Switch key={f.key} checked={!!v} onChange={on => set(f, on)} label={label} description={hint} data-config={f.key} />
}
if (f.choices?.length) {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={f.choices.map(c => ({ value: String(c), label: t(`${base(f.key)}.choices.${c}`, { defaultValue: String(c) }) }))} />
</Field>
)
}
if (f.type === 'ref') {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={[{ value: '', label: t('devices.form.none') }, ...refOptions(f, { zones, devices, selfId })]} />
</Field>
)
}
return (
<Field key={f.key} label={label} hint={hint}>
<Input type={f.type === 'int' ? 'number' : 'text'} value={v ?? ''} min={f.min ?? undefined} max={f.max ?? undefined}
onChange={e => set(f, e.target.value)} data-config={f.key} />
</Field>
)
})}
</div>
)
}