bundle.website.builtin.components.websocket.base.backend

Attributes

Functions

create_router(endpoint[, handler]) → fastapi.APIRouter

Build a websocket router bound to endpoint.

run_websocket(websocket, *task_factories) → None

Run one websocket session with composable async tasks.

every(seconds, tick) → TaskFactory

Return a task factory that runs tick periodically every seconds.

drain_text(websocket) → None

Consume and discard incoming text frames until disconnect.

receive_json(handle) → TaskFactory

Return a task factory that reads JSON objects and forwards them to handle.

now_ns() → int

keepalive_loop(websocket) → None

Default keepalive protocol: keepalive -> keepalive_ack.

Module Contents

bundle.website.builtin.components.websocket.base.backend.WebSocketHandler
bundle.website.builtin.components.websocket.base.backend.TaskFactory
bundle.website.builtin.components.websocket.base.backend.create_router(endpoint: str, handler: WebSocketHandler | None = None) → fastapi.APIRouter

Build a websocket router bound to endpoint.

Parameters:
  • endpoint – FastAPI websocket path (for example /ws/ecc).

  • handler – Websocket coroutine handler. Defaults to keepalive_loop.

Returns:

APIRouter with one websocket entrypoint.

async bundle.website.builtin.components.websocket.base.backend.run_websocket(websocket: fastapi.WebSocket, *task_factories: TaskFactory) → None

Run one websocket session with composable async tasks.

The function accepts the connection, starts all tasks, waits for completion, and performs robust cancellation cleanup when the socket closes.

bundle.website.builtin.components.websocket.base.backend.every(seconds: float, tick: TaskFactory) → TaskFactory

Return a task factory that runs tick periodically every seconds.

async bundle.website.builtin.components.websocket.base.backend.drain_text(websocket: fastapi.WebSocket) → None

Consume and discard incoming text frames until disconnect.

bundle.website.builtin.components.websocket.base.backend.receive_json(handle: collections.abc.Callable[[fastapi.WebSocket, dict], collections.abc.Awaitable[None]]) → TaskFactory

Return a task factory that reads JSON objects and forwards them to handle.

bundle.website.builtin.components.websocket.base.backend.now_ns() → int
async bundle.website.builtin.components.websocket.base.backend.keepalive_loop(websocket: fastapi.WebSocket) → None

Default keepalive protocol: keepalive -> keepalive_ack.