edgeport - v1.0.3
    Preparing search index...

    Interface WsConnection

    A live WebSocket connection.

    Async-iterate it to receive messages in arrival order; the iteration ends when the peer closes the socket. It is an AsyncDisposable, so await using closes it on scope exit.

    1.0.0

    import { connect } from 'edgeport/ws';

    await using ws = await connect('wss://echo.example.com');
    ws.send('hello');
    for await (const msg of ws) {
    if (msg.type === 'text') console.log('text:', msg.data);
    else console.log('binary bytes:', msg.data.length);
    break;
    }
    interface WsConnection {
        closed: Promise<{ code: number; reason: string }>;
        "[asyncDispose]"(): PromiseLike<void>;
        "[asyncIterator]"(): AsyncIterator<WsMessage, any, any>;
        close(code?: number, reason?: string): void;
        send(data: string | Uint8Array<ArrayBufferLike>): void;
        sendJson(value: unknown): void;
    }

    Hierarchy

    • AsyncDisposable
    • AsyncIterable<WsMessage>
      • WsConnection
    Index
    closed: Promise<{ code: number; reason: string }>

    Resolves with the close code and reason once the peer's close frame arrives.

    • Returns PromiseLike<void>

    • Returns AsyncIterator<WsMessage, any, any>

    • Closes the connection.

      Parameters

      • Optionalcode: number

        Optional RFC 6455 close code (e.g. 1000).

      • Optionalreason: string

        Optional human-readable close reason.

      Returns void

    • Sends a message to the peer.

      Parameters

      • data: string | Uint8Array<ArrayBufferLike>

        A string for a text frame, or bytes for a binary frame.

      Returns void

    • Serializes a value to JSON and sends it as a text frame.

      The value is JSON.stringify-ed and sent with send.

      Parameters

      • value: unknown

        The value to serialize and send.

      Returns void

      1.0.2