Skip to content

Live Viewer

LiveViewer starts the server immediately and streams push_state calls to connected browser tabs over WebSocket as a simulation runs. See Live Streaming for a worked example.

simview.live.LiveViewer

LiveViewer(
    scene: SimulationScene,
    host: str = "127.0.0.1",
    preferred_port: int = 5420,
    open_browser: bool = False,
)

Streams a running simulation to an already-open browser tab over WebSocket, instead of the usual save-then-view flow.

scene should already have its complete model (terrain, bodies, ...) -- states are pushed incrementally afterwards via push_state, using the same validation/encoding as SimulationScene.add_state. Because push_state appends to scene.states exactly like add_state would, the scene can still be save()d normally once streaming is done.

push_state

push_state(time, body_states, scalar_values=None) -> None

Append one frame and broadcast it to every connected viewer.

Runs on the caller's thread. Delegates to scene.add_state for the same validation/encoding SimulationScene normally does (the frame also lands in self.scene.states, so scene.save() still works after streaming), then hands the just-appended frame to the server thread's event loop for broadcast. Safe to call before any client has connected -- the frame is simply buffered for the next connection's catch-up message.

stop

stop() -> None

Signal the server to exit and wait for its thread to finish.

Idempotent -- safe to call multiple times (e.g. once explicitly and once more via exit).