Preparing search index...

    Interface PluginWebSocketServer

    A WebSocket endpoint under the plugin's route, returned by ServerAPI.registerWebSocket. A subset of ws's WebSocketServer.

    interface PluginWebSocketServer {
        clients: ReadonlySet<WebSocket>;
        close(cb?: (err?: Error) => void): void;
        on(
            event: "connection",
            listener: (ws: WebSocket, request: IncomingMessage) => void,
        ): this;
        on(
            event: "upgrade",
            listener: (request: IncomingMessage, socket: Duplex, head: Buffer) => void,
        ): this;
        on(event: "error", listener: (error: Error) => void): this;
    }
    Index
    clients: ReadonlySet<WebSocket>

    Connections completed by the server (empty when using upgrade).

    • Stops accepting new connections and removes the endpoint. Called automatically when the plugin stops, which also terminates any connected clients.

      Parameters

      • Optionalcb: (err?: Error) => void

      Returns void

    • Emitted with each WebSocket connection after the server has completed the handshake. Not emitted when an upgrade listener is attached.

      Parameters

      • event: "connection"
      • listener: (ws: WebSocket, request: IncomingMessage) => void

      Returns this

    • Escape hatch for plugins that need the raw HTTP upgrade — typically to hand it to a reverse proxy. When at least one upgrade listener is attached the plugin handles the upgrade entirely itself: the server does not complete the handshake and connection is never emitted. The arguments match Node.js's http.Server upgrade event.

      Parameters

      • event: "upgrade"
      • listener: (request: IncomingMessage, socket: Duplex, head: Buffer) => void

      Returns this

    • Parameters

      • event: "error"
      • listener: (error: Error) => void

      Returns this