A class representing the client-side of the proxy system.

Constructors

  • Creates an instance of the Client class.

    Parameters

    • proxyHost: string

      The host address of the proxy server.

    • proxyPort: number

      The port number of the proxy server.

    • localPort: number

      The local port number.

    • localHost: string

      The local host address.

    • incomingServerPort: number

      The incoming server port number.

    • reconnectInterval: number

      The reconnect interval in milliseconds.

    Returns Client

Properties

incomingServerPort: number

The incoming server port number.

isReconnecting: boolean = false

Indicates if the client is in the process of reconnecting.

localHost: string

The local host address.

localPort: number

The local port number.

proxyHost: string

The host address of the proxy server.

proxyPort: number

The port number of the proxy server.

proxySocket: null | Socket = null

The proxy server socket connection.

proxySocketHandler: null | ProxySocketHandler = null

An instance of the proxy socket handler, responsible for managing socket communications. Null if no handler is assigned.

reconnectInterval: number

The reconnect interval in milliseconds.

Methods

  • Attempts to reconnect to the proxy server after a delay.

    Returns void

  • Clears the app2 socket map for a specific name and closes the associated sockets.

    Parameters

    • name: string

      The name of the socket to clear.

    Returns void

  • Establishes a connection to App2 and sets up event listeners for the socket.

    Parameters

    • name: string

      The unique name associated with the App2 connection.

    Returns Promise<Socket>

    A promise that resolves with the established App2 socket.

    • data: Forwards received data to the proxy socket handler.
    • drain: Resumes the socket after backpressure is alleviated.
    • end: Cleans up resources when the connection ends.
    • close: Cleans up resources when the connection is closed.
    • error: Logs errors and cleans up resources.
  • Connects to the proxy server.

    Returns Promise<void>

  • Writes buffered data for the specified socket name to the proxy server in chunks. If the proxy socket's writable buffer reaches its highWaterMark, the method waits for the drain event before continuing.

    Parameters

    • name: string

      The unique name of the connection for which data is being written.

    Returns Promise<void>

    A promise that resolves when all buffered data has been sent.

    • Splits the buffered data into chunks of a fixed size.
    • Writes each chunk to the proxy socket.
    • Waits for the drain event if the writable buffer becomes full.
    • This method handles backpressure using the drain event.
    • Data is sent as JSON, including metadata such as the command, name, subdomain, and chunk.

    Buffers are mapped by socket names:

    {
    "socketName1": <Buffer ...>,
    "socketName2": <Buffer ...>
    }