Represents anything that handles the RPC protocol and allows callers to register methods that can be called remotely over the network.

NOTE: In JSONRPC jargon, a "request" is made to a "method". In our code we talk about "request types", but JSONRPC doesn't have the notion of a "request type". However, a "request type" is really just the name of a method in JSONRPC. So "method names" and "request types" are treated as the same thing. Similarly, what we call a "request handler" is the same thing as a "method" that has been registered with a JSONRPC server.

interface IRpcMethodRegistrar {
    connect: ((localEventHandler: EventHandler) => Promise<boolean>);
    connectionStatus: ConnectionStatus;
    disconnect: (() => Promise<void>);
    emitEventOnNetwork: EventHandler;
    registerMethod: ((methodName: string, method: InternalRequestHandler, methodDocs?: SingleMethodDocumentation) => Promise<boolean>);
    request: ((requestType: `${string}:${string}`, requestParams: RequestParams) => Promise<JSONRPCResponse>);
    unregisterMethod: ((methodName: string) => Promise<boolean>);
}

Hierarchy (view full)

Implemented by

Properties

connect: ((localEventHandler: EventHandler) => Promise<boolean>)

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

Type declaration

    • (localEventHandler): Promise<boolean>
    • 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

connectionStatus: ConnectionStatus

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

disconnect: (() => Promise<void>)

Disconnects from the connection:

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

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

Unique network event type for coordinating between processes

Event data to emit on the network

registerMethod: ((methodName: string, method: InternalRequestHandler, methodDocs?: SingleMethodDocumentation) => Promise<boolean>)

Register a method that will be called if an RPC request is made

request: ((requestType: `${string}:${string}`, requestParams: RequestParams) => Promise<JSONRPCResponse>)

Send a request and resolve after receiving a response

Type declaration

    • (requestType, requestParams): Promise<JSONRPCResponse>
    • 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

unregisterMethod: ((methodName: string) => Promise<boolean>)

Unregister a method so it is no longer available to RPC requests