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:
@@ -1,7 +1,7 @@
|
||||
// Pure logic of the platform pages (plan steps 2.6c, 2.6d, 2.6e).
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { deviceStatus, deviceUsage, hasRoom, linkTargets, normalizeCode } from '../src/pages/platform/devicesLogic.js'
|
||||
import { configInitial, configValue, deviceStatus, deviceUsage, hasRoom, linkTargets, normalizeCode, refOptions } from '../src/pages/platform/devicesLogic.js'
|
||||
import { moduleState, stoppedBy } from '../src/pages/platform/modulesLogic.js'
|
||||
import {
|
||||
approvalState, approvalTarget, canEndSession, canGive, diff, differsFromRole, editorGroups, permLabelKey, resetToRole,
|
||||
@@ -116,3 +116,23 @@ test('approvals and sessions', () => {
|
||||
assert.equal(canEndSession({ ...s, client: 'support' }), false)
|
||||
assert.equal(canEndSession({ ...s, client: 'support' }, { actorIsSuperadmin: true }), true)
|
||||
})
|
||||
|
||||
test('device settings: starting values, typed values, ref options (3.1a)', () => {
|
||||
const fields = [
|
||||
{ key: 'auto_sign_out_minutes', type: 'int', default: 0, choices: [0, 5] },
|
||||
{ key: 'zone', type: 'ref', default: null, choices_from: 'prep_zones' },
|
||||
{ key: 'pos', type: 'ref', default: null, choices_from: 'devices:pos_counter' },
|
||||
{ key: 'sound', type: 'bool', default: true },
|
||||
]
|
||||
assert.deepEqual(configInitial(fields), { auto_sign_out_minutes: 0, zone: null, pos: null, sound: true })
|
||||
assert.deepEqual(configInitial(fields, { auto_sign_out_minutes: 5, sound: false }), { auto_sign_out_minutes: 5, zone: null, pos: null, sound: false })
|
||||
assert.equal(configValue(fields[0], '5'), 5)
|
||||
assert.equal(configValue(fields[1], ''), null)
|
||||
assert.equal(configValue(fields[1], '3'), 3)
|
||||
assert.equal(configValue(fields[3], false), false)
|
||||
assert.deepEqual(refOptions(fields[1], { zones: [{ id: 2, name: 'Grill' }] }), [{ value: '2', label: 'Grill' }])
|
||||
const devices = [{ id: 1, app_key: 'pos_counter', name: 'Till' }, { id: 2, app_key: 'kds', name: 'KDS' },
|
||||
{ id: 3, app_key: 'pos_counter', name: 'Old', revoked_at: 'x' }]
|
||||
assert.deepEqual(refOptions(fields[2], { devices }), [{ value: '1', label: 'Till' }])
|
||||
assert.deepEqual(refOptions(fields[2], { devices, selfId: 1 }), [])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user