Whitebox
API
¶
Standarized API of whitebox for plugins to interact with the core system.
Attributes:
| Name | Type | Description |
|---|---|---|
location |
LocationService instance for interacting with the location service |
|
traffic |
TrafficService instance for interacting with the traffic service |
|
status |
StatusService instance for interacting with the status service |
|
host_manager |
HostManagerService instance for Host Manager access |
Event
¶
EventRegistry
¶
Bases: RegistryBase
Registry for managing events and their handlers. Allows registering event handlers and callbacks.
register_callback(event_type, callback)
¶
Register a callback for an existing event.
register_event(event_type, handler, callbacks=None)
¶
Register an event with its handler and optional callbacks.
unregister_callback(event_type, callback)
¶
Unregister a callback for an existing event.
unregister_event(event_type)
¶
Unregister an event by its type.
BaseWebsocketConsumer
¶
Bases: AsyncWebsocketConsumer
This consumer handles WebSocket connections for whitebox.
BaseWebsocketEventConsumer
¶
Bases: BaseWebsocketConsumer
receive(text_data)
async
¶
Called when client sends a message to the WebSocket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_data
|
str
|
The message sent by the client. |
required |
MessageThrottleMixin
¶
SquawkConsumer
¶
Bases: MessageThrottleMixin, BaseWebsocketEventConsumer
Universal WebSocket consumer.
This consumer has no fixed consumer_group_name. Clients connect,
optionally with ?all=1 to subscribe to every currently
registered event type, and then send
command.session.event.subscribe /
command.session.event.unsubscribe frames to add or remove
per-event subscriptions dynamically. Each subscription is reached
by any broadcast_event(event_type, ...) and the payload is
forwarded to the client verbatim.
Inbound messages that are not subscribe / unsubscribe frames fall
through to BaseWebsocketEventConsumer.receive and are emitted
through the regular event system.
Group-name convention: the Channels group for event_type is the
string event_type itself (e.g. group "observation.status.update"
for event "observation.status.update"). This must satisfy channels-redis's
group_name_regex = ^[a-zA-Z\d\-_.]+$. See
broadcast_group_name for the canonical accessor; do not
open-code f"squawk:{event_type}" or similar in callers or
tests.
broadcast_group_name(event_type)
classmethod
¶
Channels group name used to broadcast event_type.
In this codebase the group name is identical to the event name
(no string prefix). squawk is a project codename, not a
prefix — the convention is enforced by callers (_subscribe,
_unsubscribe, events.broadcast_event) all routing
through this classmethod rather than open-coding
f"squawk:{event_type}" or similar.
receive(text_data)
async
¶
Handle subscribe / unsubscribe frames, or fall through to emit.