envision.server module

class envision.server.AllowCORSMixin[source]

A mix-in that adds CORS headers to the page.

options()[source]

Apply a base response status.

set_default_headers()[source]

Setup the default headers. In this case they are the minimum required CORS related headers.

class envision.server.BroadcastWebSocket(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This websocket receives the SMARTS state (the other end of the open websocket is held by the Envision Client (SMARTS)) and broadcasts it to all web clients that have open web-sockets via the StateWebSocket handler.

initialize(max_capacity_mb)[source]

Setup this websocket.

on_close()[source]

Close the broadcast websocket.

async on_message(message)[source]

Asynchronously receive messages from the Envision client.

async open(simulation_id)[source]

Asynchronously open the websocket to broadcast to all web clients.

class envision.server.FileHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This handler serves files to the given requester.

async get(id_)[source]

Serve a resource requested by id.

initialize(path_map: Dict[str, str | Path] = {})[source]

FileHandler that serves file for a given ID.

async serve_chunked(path: Path, chunk_size: int = 1048576)[source]

Serve a file to the endpoint given a path.

class envision.server.Frame(data: str, timestamp: float, next_=None)[source]

A frame that describes a single envision simulation step.

property data

The raw envision data.

property size

The byte size of the frame’s raw data.

property timestamp

The timestamp for this frame.

class envision.server.Frames(max_capacity_mb=500)[source]

A managed collection of simulation frames. This collection uses a random discard of simulation frames to stay under capacity. Random discard favors preserving newer frames over time.

append(frame: Frame)[source]

Add a frame to the end of the existing frames.

property elapsed_time: float

The total elapsed time between the first and last frame.

property start_frame: Frame | None

The first frame in all available frames.

property start_time: float | None

The first timestamp in all available frames.

class envision.server.MainHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This handler serves the index file.

get()[source]

Serve the index file.

class envision.server.MapFileHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This handler serves map geometry to the given endpoint.

initialize()[source]

Setup this handler.

class envision.server.ModelFileHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This model file handler serves vehicle and other models to the client.

async get(id_)[source]

Serve the requested model geometry.

initialize()[source]

FileHandler that serves file for a given ID.

class envision.server.SimulationListHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This handler serves a list of the active simulations.

async get()[source]

Serve the active simulations.

class envision.server.StateWebSocket(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

This websocket sits on the other side of the web client. It handles playback and playback control messages from the web-client.

check_origin(origin)[source]

Check the validity of the message origin.

get_compression_options()[source]

Get the message compression configuration.

initialize()[source]

Setup this websocket.

on_close()[source]

Stop listening and close the socket.

async on_message(message)[source]

Asynchronously handle playback requests.

async open(simulation_id)[source]

Open this socket to listen for web-client playback requests.

class envision.server.WebClientRunLoop(frames: Frames, web_client_handler: WebSocketHandler, message_frequency: float, message_frame_volume: int, seek: int | None = None)[source]

The run loop is like a “video player” for the simulation. It supports seeking and playback. The run loop wraps the web client handler and pushes the frame messages to it as needed.

run_forever()[source]

Starts the connection loop to push frames to the connected web client.

seek(offset_seconds)[source]

Indicate to the web-client that it should progress to the nearest frame to the given time.

stop()[source]

End the simulation playback.

envision.server.main()[source]

Main function for when using this file as an entry-point.

envision.server.make_app(max_capacity_mb: float, debug: bool)[source]

Create the envision web server application through composition of services.

envision.server.on_shutdown()[source]

Callback on shutdown of the envision server.

envision.server.run(max_capacity_mb: int = 500, port: int = 8081, debug: bool = False)[source]

Create and run an envision web server.