Manages the JSON-RPC protocol on the client end of a websocket that connects to main

Created by any process that connects to the websocket server owned by main

Implements

Constructors

Properties

connectionStatus: ConnectionStatus

Whether this connector is setting up or has finished setting up its connection and is ready to communicate on the network

Methods

  • Sets up the RPC handler by populating connector info, setting up event handlers, and doing one of the following:

    • On clients: connecting to the server
    • On servers: opening an endpoint for clients to connect

    Parameters

    • localEventHandler: EventHandler

      Function that handles events from the server by accepting an eventType and an event and emitting the event locally. Used when receiving an event over the network.

    Returns Promise<boolean>

    Promise that resolves when finished connecting

  • Disconnects from the connection:

    • On clients: disconnects from the server
    • On servers: disconnects from all clients and closes its connection endpoint

    Returns Promise<void>

  • Sends an event to other processes. Does NOT run the local event subscriptions as they should be run by NetworkEventEmitter after sending on network.

    Type Parameters

    • T

    Parameters

    • eventType: string

      Unique network event type for coordinating between processes

    • event: T

      Event data to emit on the network

    Returns void

  • Send a request and resolve after receiving a response

    Parameters

    • requestType: `${string}:${string}`

      Type of request (or "method" in JSONRPC jargon) to call

    • requestParams: RequestParams

      Parameters associated with this request

    Returns Promise<JSONRPCResponse>

    Promise that resolves to a JSONRPCSuccessResponse or JSONRPCErrorResponse message