Skip to content

Server

SimViewServer is the FastAPI app that serves a scene's model/states (or per-blob columnar endpoints) to the browser, and handles WebSocket live-push. Most users won't instantiate this directly — see SimulationScene.show(), LiveViewer, or the simview CLI instead.

simview.server.SimViewServer

SimViewServer(
    sim_path: str
    | Path
    | Sequence[str | Path]
    | None = None,
    data: dict | None = None,
    live: bool = False,
    frame_buffer_size: int = _LIVE_FRAME_BUFFER_MAXLEN,
)

broadcast_episodes async

broadcast_episodes(episodes: list[dict]) -> None

Push updated episode boundaries to every connected /ws/states client.

A separate message kind from the frame broadcasts -- episodes describe the model, not a frame, and arrive far more rarely. See the onmessage handler in SimView.js.

broadcast_frame async

broadcast_frame(frame: dict) -> None

Send one newly-pushed frame to every connected /ws/states client.

Must run on self.loop (the server thread's event loop) -- LiveViewer schedules this via asyncio.run_coroutine_threadsafe from its sender thread rather than calling it directly.

set_episodes

set_episodes(episodes: list[dict]) -> None

Replace the served model's episode boundaries (live mode).

Re-serializes /model so a viewer connecting later sees them; already connected viewers are told separately via broadcast_episodes.