Files
xenia-pos-local/local_backend/models/sync_event.py
T
bonaminandClaude Opus 5.5 bda5cde92b 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>
2026-11-14 16:31:59 +02:00

25 lines
1.1 KiB
Python

"""WebSocket replay buffer (F-014): every broadcast event gets a seq id the clients resume from.
Written and read with raw SQL in services/ws_bus.py (hot path, no ORM). The model
exists so the table is part of the Alembic-managed schema.
- sqlite_autoincrement: ids must never be reused after old rows are pruned, or a
client's cursor could skip events.
- created_at is a UTCDateTime; ws_bus writes it with core.timeutil.to_db_str() so the
raw-SQL text matches what the type stores (prune compares the text).
"""
from sqlalchemy import Column, Integer, String, Text
from core.timeutil import UTCDateTime
from database import Base
class SyncEvent(Base):
__tablename__ = "sync_events"
__table_args__ = {"sqlite_autoincrement": True}
id = Column(Integer, primary_key=True)
event_type = Column(String, nullable=False)
payload = Column(Text, nullable=False)
target_user_ids = Column(Text, nullable=True) # JSON list; NULL = not addressed to users
target_device_ids = Column(Text, nullable=True) # JSON list of devices (plan 3.1a); NULL = none
created_at = Column(UTCDateTime, nullable=False, index=True)