Establish a WebSocket for an airport
RealTime
Establish a WebSocket for an airport
Performs a WebSocket upgrade to stream real-time airport state. Requires:
- GET with
Upgrade: websocket airport(ICAO, 4 chars) and an API key via either:keyquery parameter, orAuthorization: Bearer <API key>header The API key is forwarded as a Bearer token to the airport’s Durable Object for auth.
GET
Establish a WebSocket for an airport
Establish a session
- Connect to
/connectwithairportand your API key. - Wait for
INITIAL_STATE(this confirms your role and current airport state). - Keep the connection alive by sending
HEARTBEATregularly.
HEARTBEAT every 60 seconds and closes idle sessions after ~70 seconds without inbound client messages.
Packet envelope
Every packet uses this top-level shape:typeis required.airportis optional on most client packets (server uses your connected airport if omitted).timestampis optional on client packets and server-populated on outbound packets.
Packet permissions by role
| Packet type | Who can send | What happens |
|---|---|---|
HEARTBEAT | controller, pilot, observer | Server replies with HEARTBEAT_ACK |
GET_STATE | controller, pilot, observer | Server replies with STATE_SNAPSHOT |
STATE_UPDATE | controller only | Broadcast to same-airport clients (except sender) |
MULTI_STATE_UPDATE | controller only | Broadcast to same-airport clients (except sender) |
SHARED_STATE_UPDATE | controller only | Broadcast to same-airport clients (including sender) |
STOPBAR_CROSSING | pilot only | Broadcast to same-airport controllers |
CLOSE | controller, pilot, observer | Server closes the session gracefully |
Client packets you send
HEARTBEAT
GET_STATE
STATE_UPDATE (controller only)
MULTI_STATE_UPDATE (controller only)
SHARED_STATE_UPDATE (controller only)
STOPBAR_CROSSING (pilot only)
CLOSE
Server packets you should handle
INITIAL_STATEimmediately after connectHEARTBEATevery 60 secondsHEARTBEAT_ACKin response to clientHEARTBEATSTATE_SNAPSHOTin response toGET_STATESTATE_UPDATEwhen a controller changes one object stateMULTI_STATE_UPDATEwhen a controller sends a batch state changeCONTROLLER_CONNECT/CONTROLLER_DISCONNECTfor controller presence changesSHARED_STATE_UPDATEwhen shared state changesSTOPBAR_CROSSING(controllers only) when a pilot crosses a stopbarERRORwhen validation/processing fails
Validation and limits (avoid malformed packets)
objectIdmust match^[a-zA-Z0-9_-]+$.STATE_UPDATEmust includedata.objectIdand one ofdata.stateordata.patch.MULTI_STATE_UPDATEmust includedata.updates(maximum200updates).SHARED_STATE_UPDATEmust includedata.sharedStatePatchobject (maximum10,240serialized characters).- Maximum packet size is
50,000characters. - Unknown packet
typevalues are rejected.
