WebSockets
Start here
Section titled “Start here”WebSocketArcThe WebSocket arc: the WebSocketBase authoring surface plus compilation and per-upgrade execution.FlareWebSocketContextThe connection a WebSocket handler holds: a lean, runtime-agnostic noun over the live socket.socketContractDefines a typed WebSocket contract - the"ws"kind of the genericcontractcore, the WS sibling ofhttpContract.WebSocketControllerBaseBase class for a class-form WebSocket endpoint.WebSocketChannelsFramework service for publishing to WebSocket channels from OUTSIDE a connection: an HTTP handler, a timer, any code in the same broadcast domain.WebSocketRouteHandleThe build-time handlehost.ws.route(path, opts)returns: attach the connection’s lifecycle behaviors with individual registrar calls, the same wayhost.http.get/postregister behaviors (never an object literal).WebSocketRefusalAnupgradehook’s accept-then-close verdict: the handshake completes, then the connection closes immediately with this code and reason, skipping the route’s channels and controller entirely.
Classes
Section titled “Classes”FlareWebSocketContextThe connection a WebSocket handler holds: a lean, runtime-agnostic noun over the live socket.FlareWebSocketMessageRuntime-agnostic representation of a single WebSocket message.WebSocketArcThe WebSocket arc: the WebSocketBase authoring surface plus compilation and per-upgrade execution.WebSocketChannelsFramework service for publishing to WebSocket channels from OUTSIDE a connection: an HTTP handler, a timer, any code in the same broadcast domain.WebSocketControllerBaseBase class for a class-form WebSocket endpoint.WebSocketControllerHandleThe build-time handlehost.ws.controller(path, cls)returns.WebSocketRefusalAnupgradehook’s accept-then-close verdict: the handshake completes, then the connection closes immediately with this code and reason, skipping the route’s channels and controller entirely.WebSocketRouteHandleThe build-time handlehost.ws.route(path, opts)returns: attach the connection’s lifecycle behaviors with individual registrar calls, the same wayhost.http.get/postregister behaviors (never an object literal).
Functions
Section titled “Functions”socketContractDefines a typed WebSocket contract - the"ws"kind of the genericcontractcore, the WS sibling ofhttpContract.
WebSocketCloseHandlerclosehandler: runs at the terminal close.WebSocketControllerClassA concrete WebSocket controller class: constructed once per connection with its container, socket, and input.WebSocketDescriptorStatic shape of one WebSocket route: inbound/outbound schemas and typed upgrade inputs.WebSocketErrorHandlererrorhandler: runs on a transport/protocol error; a terminal close still follows.WebSocketHandlerScopeThe per-connection DI + config + input surface handed to a function-form WS handler as its second argument.WebSocketIncomingThe inbound message type a descriptor produces: the validated value whenincomingis declared, otherwise a FlareWebSocketMessage (the rich wrapper - inspect.text()/.json()/.isBinary).WebSocketInputThe CONNECT-time typed input every WS handler’sscope.inputcarries (stable for the connection’s life): the upgrade path params and query.WebSocketMessageHandlermessagehandler: runs per inbound message; the payload is onscope.input.message.WebSocketMessageHandlerScopeThemessagehandler’s scope: WebSocketHandlerScope whoseinputadditionally carries the validated inboundmessage(typed from the descriptor’sincoming), mirroring HTTP’sscope.input.body.WebSocketMessageInputThemessagehandler’sscope.input: the connect-time input plus the validated inboundmessage.WebSocketOpenHandleropenhandler: runs once when the connection reaches OPEN.WebSocketOutgoingThe outbound value type a descriptor accepts (raw wire type when nooutgoingschema).WebSocketRawThe raw WebSocket message wire types: text (string) or binary (Uint8Array).WebSocketRouteOptionsPer-route options forhost.ws.route/host.ws.controller: loose inline fields OR a brandedcontract.WebSocketsConfigResolved shape of thewebsocketsconfig section: the per-connection size caps and liveness timers.WebSocketStateDurable per-connection state: the storews.stateexposes.WebSocketTokenBranded WS contract entry for one route (e.g.WebSocketUpgradeRead-only view of the HTTP request behind one WebSocket upgrade, handed to theupgradehook.WebSocketUpgradeHandlerTheupgradehook: runs BEFORE the handshake completes, in request scope (no socket exists yet).WebSocketUpgradeHandlerScopeTheupgradehook’s scope: the WebSocketHandlerScope shape plus the pre-connectionstatewriter.WebSocketUpgradeOptionsThe options accepted by the two-argupgraderegistrar: the hook’s own DI map and state provisions.WebSocketUpgradeResultWhat oneupgradehook run decides.
Constants
Section titled “Constants”WEBSOCKETS_CONFIGPre-defined token for Flare-internal WebSocket config (size caps and liveness timers).