Documentation
    Preparing search index...

    Class WebSocketAdaptor

    Serves the @WebSocketRoute() methods of a NestJS application over WebSocket.

    Call upgrade after the application has been created. It finds the routes, checks them, and takes over the HTTP server's upgrade events. A handshake whose path matches no route is rejected with close code 1002.

    contracts/common.md#principled-implementation Routes are matched by paths built from the global prefix, the version, the module prefix, the controller path, and the method path, joined and normalized the same way for every combination; the adapter answers upgrade events itself through a ws server in no-server mode and removes its listeners when the HTTP server closes.

    contracts/common.md#clear-and-simple-design A class with one static factory, one close property, and the private handler; discovery, method checks, termination, and close reasons are module-private functions.

    contracts/common.md#prohibited-implementation-shortcuts The global prefix, versioning options, and module graph are read from app.config and app.container, which NestJS keeps internal because INestApplication has no public accessor for them; this is the limitation of the adapter, not a fixture-specific branch.

    contracts/common.md#meaningful-documentation The comment states when to call it and what happens to an unmatched handshake.

    contracts/portability.md#os-neutral-implementation Diagnostic source URLs are converted by fileURLToPath before path.relative uses native paths; route matching uses HTTP path segments separately from filesystem paths. No filesystem case policy is inferred from the OS.

    Index
    • Stops the adapter: removes its listeners from the HTTP server and closes the WebSocket server.

      Returns Promise<void>

      contracts/common.md#principled-implementation The listeners are removed before the ws server closes, so no upgrade event reaches a closing server, and the returned promise resolves when the server has closed.

      contracts/common.md#clear-and-simple-design An arrow property so the same function value can be registered and unregistered as the HTTP server's close listener.

      contracts/common.md#prohibited-implementation-shortcuts It releases exactly what the adapter registered.

      contracts/common.md#meaningful-documentation The comment states what is released.

      contracts/portability.md#os-neutral-implementation Diagnostic source URLs are converted by fileURLToPath before path.relative uses native paths; route matching uses HTTP path segments separately from filesystem paths. No filesystem case policy is inferred from the OS.

    • Creates the adapter for the application: it visits every controller, validates the WebSocket routes, and starts listening for upgrade events.

      All route errors of the application are collected and thrown together, with the controller, method, source location, and reasons of each.

      Parameters

      • app: INestApplication

      Returns Promise<WebSocketAdaptor>

      contracts/common.md#principled-implementation Controller data-method descriptors are checked before any handshake is served, with child properties shadowing inherited methods and accessors never executed, and all defects are reported in one error, so a misconfigured route fails at start and not at the first client; source locations come from get-function-location, converted with fileURLToPath so a file: URL becomes the path on every platform.

      contracts/common.md#clear-and-simple-design One asynchronous factory that awaits the visitor and hands the operator list to the private constructor.

      contracts/common.md#prohibited-implementation-shortcuts The visitor reports through the same error path for every controller; no controller or route name is special-cased.

      contracts/common.md#meaningful-documentation The comment states the collected error report and the effect on the server.

      contracts/portability.md#os-neutral-implementation Diagnostic source URLs are converted by fileURLToPath before path.relative uses native paths; route matching uses HTTP path segments separately from filesystem paths. No filesystem case policy is inferred from the OS.