KC's Workspace
    Preparing search index...
    interface WebSocketServer {
        "[isWebSocketServer]": true;
        api?: any;
        clients: Set<WebSocketClient>;
        off: {
            (
                event: "connection",
                cb: (
                    this: Server<WebSocket>,
                    socket: WebSocket,
                    request: IncomingMessage,
                ) => void,
            ): this;
            (
                event: "error",
                cb: (this: Server<WebSocket>, error: Error) => void,
            ): this;
            (
                event: "headers",
                cb: (
                    this: Server<WebSocket>,
                    headers: string[],
                    request: IncomingMessage,
                ) => void,
            ): this;
            (
                event: "close" | "listening",
                cb: (this: Server<WebSocket>) => void,
            ): this;
            (
                event: string | symbol,
                listener: (this: Server<WebSocket>, ...args: any[]) => void,
            ): this;
        } & (event: string, listener: Function) => void;
        on: {
            (
                event: "connection",
                cb: (
                    this: Server<WebSocket>,
                    socket: WebSocket,
                    request: IncomingMessage,
                ) => void,
            ): this;
            (
                event: "error",
                cb: (this: Server<WebSocket>, error: Error) => void,
            ): this;
            (
                event: "headers",
                cb: (
                    this: Server<WebSocket>,
                    headers: string[],
                    request: IncomingMessage,
                ) => void,
            ): this;
            (
                event: "close" | "listening",
                cb: (this: Server<WebSocket>) => void,
            ): this;
            (
                event: string | symbol,
                listener: (this: Server<WebSocket>, ...args: any[]) => void,
            ): this;
        } & <T extends string>(
            event: T,
            listener: WebSocketCustomListener<InferCustomEventPayload<T>>,
        ) => void;
        close(): Promise<void>;
        handleInvoke(
            payload: HotPayload,
        ): Promise<{ result: any } | { error: any }>;
        listen(): void;
        send(payload: HotPayload): void;
        send<T extends string>(
            event: T,
            payload?: InferCustomEventPayload<T>,
        ): void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    "[isWebSocketServer]": true
    api?: any

    Get all connected clients.

    off: {
        (
            event: "connection",
            cb: (
                this: Server<WebSocket>,
                socket: WebSocket,
                request: IncomingMessage,
            ) => void,
        ): this;
        (event: "error", cb: (this: Server<WebSocket>, error: Error) => void): this;
        (
            event: "headers",
            cb: (
                this: Server<WebSocket>,
                headers: string[],
                request: IncomingMessage,
            ) => void,
        ): this;
        (event: "close" | "listening", cb: (this: Server<WebSocket>) => void): this;
        (
            event: string | symbol,
            listener: (this: Server<WebSocket>, ...args: any[]) => void,
        ): this;
    } & (event: string, listener: Function) => void

    Unregister event listener.

    Type Declaration

      • (event: string, listener: Function): void
      • Parameters

        Returns void

    on: {
        (
            event: "connection",
            cb: (
                this: Server<WebSocket>,
                socket: WebSocket,
                request: IncomingMessage,
            ) => void,
        ): this;
        (event: "error", cb: (this: Server<WebSocket>, error: Error) => void): this;
        (
            event: "headers",
            cb: (
                this: Server<WebSocket>,
                headers: string[],
                request: IncomingMessage,
            ) => void,
        ): this;
        (event: "close" | "listening", cb: (this: Server<WebSocket>) => void): this;
        (
            event: string | symbol,
            listener: (this: Server<WebSocket>, ...args: any[]) => void,
        ): this;
    } & <T extends string>(
        event: T,
        listener: WebSocketCustomListener<InferCustomEventPayload<T>>,
    ) => void

    Handle custom event emitted by import.meta.hot.send

    Type Declaration

      • (
            event: "connection",
            cb: (
                this: Server<WebSocket>,
                socket: WebSocket,
                request: IncomingMessage,
            ) => void,
        ): this
      • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

        server.on('connection', (stream) => {
        console.log('someone connected!');
        });

        Returns a reference to the EventEmitter, so that calls can be chained.

        By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

        import { EventEmitter } from 'node:events';
        const myEE = new EventEmitter();
        myEE.on('foo', () => console.log('a'));
        myEE.prependListener('foo', () => console.log('b'));
        myEE.emit('foo');
        // Prints:
        // b
        // a

        Parameters

        Returns this

        v0.1.101

      • (event: "error", cb: (this: Server<WebSocket>, error: Error) => void): this
      • Parameters

        Returns this

      • (
            event: "headers",
            cb: (
                this: Server<WebSocket>,
                headers: string[],
                request: IncomingMessage,
            ) => void,
        ): this
      • Parameters

        Returns this

      • (event: "close" | "listening", cb: (this: Server<WebSocket>) => void): this
      • Parameters

        Returns this

      • (
            event: string | symbol,
            listener: (this: Server<WebSocket>, ...args: any[]) => void,
        ): this
      • Parameters

        • event: string | symbol
        • listener: (this: Server<WebSocket>, ...args: any[]) => void

        Returns this

    Methods

    • Disconnect all clients and terminate the server.

      Returns Promise<void>

    • Parameters

      Returns Promise<{ result: any } | { error: any }>

    • Listen on port and host

      Returns void

    • Broadcast events to all clients

      Parameters

      Returns void

    • Send custom event

      Type Parameters

      • T extends string

      Parameters

      Returns void