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:
@@ -53,3 +53,31 @@ export function hasRoom(usage, appKey, { moving = false } = {}) {
|
||||
export function linkTargets(devices, selfId = null) {
|
||||
return devices.filter(d => !d.revoked_at && d.id !== selfId)
|
||||
}
|
||||
|
||||
// ── per-device settings (plan step 3.1a) ────────────────────────────────────
|
||||
// `fields` = the app's device_app.config from GET /api/platform/modules:
|
||||
// [{ key, type: 'bool'|'int'|'str'|'enum'|'ref', default, choices, min, max, choices_from }]
|
||||
|
||||
/** The form's starting values: the device's config (already effective) or the defaults. */
|
||||
export function configInitial(fields = [], current = null) {
|
||||
return Object.fromEntries(fields.map(f => [f.key, current && f.key in current ? current[f.key] : f.default]))
|
||||
}
|
||||
|
||||
/** A form control's raw value → the value sent to the API (selects and inputs give strings). */
|
||||
export function configValue(field, raw) {
|
||||
if (field.type === 'bool') return !!raw
|
||||
if (field.type === 'int') return raw === '' || raw == null ? null : Number(raw)
|
||||
if (field.type === 'ref') return raw === '' || raw == null ? null : Number(raw)
|
||||
if (field.type === 'enum') return raw
|
||||
return raw == null ? '' : String(raw)
|
||||
}
|
||||
|
||||
/** Options of a `ref` field: prep zones, or live devices of one app ("devices:<app>"). */
|
||||
export function refOptions(field, { zones = [], devices = [], selfId = null } = {}) {
|
||||
if (field.choices_from === 'prep_zones') return zones.map(z => ({ value: String(z.id), label: z.name }))
|
||||
if (field.choices_from?.startsWith('devices:')) {
|
||||
const app = field.choices_from.slice('devices:'.length)
|
||||
return devices.filter(d => !d.revoked_at && d.app_key === app && d.id !== selfId).map(d => ({ value: String(d.id), label: d.name }))
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user