Class Duplex<In, Out>

A Duplex<In, Out> is the core type used for StreamEndpoint, and represents two streams - one going "in" to a server, and one going "out" to a client

Type Parameters

  • In

    The type of messages transmitted to the server

  • Out

    The type of messages transmitted to the client

Hierarchy

  • Duplex

Constructors

  • Assigns the underlying streams to the duplex and creates the server and client StreamHandler views

    Type Parameters

    • In

    • Out

    Parameters

    • toServer: Stream<In> = ...

      Stream for sending data to the server, will create a new stream if not specified

    • toClient: Stream<Out> = ...

      Stream for sending data to the client, will create a new stream if not specified

    Returns Duplex<In, Out>

Properties

client: StreamHandler<Out, In>

StreamHanlder view of the underlying streams from the perspective of the client - from this perspective, you will be able to listen for messages being sent to the client and be able to write messages "out" to the server

server: StreamHandler<In, Out>

StreamHanlder view of the underlying streams from the perspective of the server - from this perspective, you will be able to listen for messages being sent to the server and be able to write messages "out" to the client

toClient: Stream<Out>

Underlying stream to the clietn - likely unnecessary to access

toServer: Stream<In>

Underlying stream to the server - likely unnecessary to access

Methods

  • "Closes" the clientside of this duplex by making it so the server view throws errors if you try to read messages sent to the client or write messages to the server

    Returns void

  • "Closes" the serverside of this duplex by making it so the server view throws errors if you try to read messages sent to the server or write messages to the client

    Returns void

  • Returns

    New duplex

    Example

    const isTrueEndpoint = async ({server}}: Duplex<boolean, string>) => {
    server.on("message", (b) => server.write(b ? "true" : "false"));
    }
    // Forward requests from otherEndpoint to endpoint, and forward responses back
    const isEvenEndpoint = async (dup: Duplex<number, string>) =>
    isTrueEndpoint(dup.map((n: number) => n % 2 === 0, (s) => s));

    Type Parameters

    • NewIn

    • NewOut

    Parameters

    • inFn: ((input: NewIn) => In)

      transformation for input message types

        • (input: NewIn): In
        • Parameters

          • input: NewIn

          Returns In

    • outFn: ((output: Out) => NewOut)

      transformation for output message types

        • (output: Out): NewOut
        • Parameters

          • output: Out

          Returns NewOut

    Returns Duplex<NewIn, NewOut>

Generated using TypeDoc