WebSocketControllerHandle
class WebSocketControllerHandle<T extends WebSocketDescriptor = {}>The build-time handle host.ws.controller(path, cls) returns. The connection’s lifecycle lives on
the class (open/message/close/error methods), so this handle carries only the one moment the
class cannot: the pre-handshake upgrade hook, which runs in request scope before any instance
exists - the same registration-site placement as a Durable Object mount’s resolve gateway.
Generic over the route’s descriptor T (from the class’s contract), so the hook’s scope is fully
typed. Constructed by the arc only (exported type-only from the package index, like
WebSocketRouteHandle it is dev-held, never dev-constructed).
How you get one
Section titled “How you get one”Handed to you by the framework; see Controller classes.
Methods
Section titled “Methods”upgrade()
Section titled “upgrade()”2 overloads
upgrade(handler: WebSocketUpgradeHandler<{}, T>): thisRegisters the pre-handshake upgrade hook.
The one moment with request context, before the handshake completes (and before the controller
instance exists). The bare form’s scope carries no named deps (a controller route declares no
inject map); the options form declares the hook’s OWN inject plus the state tokens it
provides via scope.state. Either way the hook resolves from the same per-connection container
the instance later uses, so a service it touches is an ordinary connection-scoped service.
handler WebSocketUpgradeHandler<{}, T>
returns this
upgrade<I extends InjectMap>(opts: WebSocketUpgradeOptions<I>, handler: WebSocketUpgradeHandler<I, T>): thisRegisters the pre-handshake upgrade hook.
The one moment with request context, before the handshake completes (and before the controller
instance exists). The bare form’s scope carries no named deps (a controller route declares no
inject map); the options form declares the hook’s OWN inject plus the state tokens it
provides via scope.state. Either way the hook resolves from the same per-connection container
the instance later uses, so a service it touches is an ordinary connection-scoped service.
opts WebSocketUpgradeOptions<I>
handler WebSocketUpgradeHandler<I, T>
returns this
Learn: Controller classes