papi-dts
    Preparing search index...

    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;
        onDidDisconnectClient: PlatformEvent<RpcClientDisconnectEvent>;
        onDidLoseConnection: PlatformEvent<void>;
        registerEvent: (
            eventName: string,
            documentation?: SingleNotificationDocumentation,
        ) => Promise<boolean>;
        registerMethod: (
            methodName: string,
            method: InternalRequestHandler,
            methodDocs?: SingleMethodDocumentation,
        ) => Promise<boolean>;
        request: (
            requestType: `${string}:${string}`,
            requestParams: RequestParams,
            skipRetry?: boolean,
        ) => Promise<JSONRPCResponse>;
        unregisterEvent: (eventName: string) => Promise<boolean>;
        unregisterMethod: (methodName: string) => Promise<boolean>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    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

    An implementation that opens an endpoint MUST NOT resolve true until that endpoint is actually accepting connections. Callers treat this resolving as permission to start processes that immediately connect, and those clients may get a single attempt with no retry — so reporting ready optimistically surfaces as a client that was refused, whose symptoms appear in a different process entirely. See adr-papi-websocket-hostname-bind.

    Type declaration

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

        true once the connection is established and usable — for a server, once its endpoint is accepting connections. false if the connection could not be established.

        TODO(PT-4495): implementations disagree on what they return when this handler was already connected or connecting, so a caller can neither rely on that case nor tell a benign double-connect from a real failure. PT-4495 replaces the boolean with a result type that distinguishes the three outcomes; until then, only the two states above are contractual.

    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

    onDidDisconnectClient: PlatformEvent<RpcClientDisconnectEvent>

    Event that fires when a process disconnects from the network, carrying the method names its departure removed from the central registry.

    This is platform-internal core plumbing between the process that owns the websocket server and the services that know how their own registered names are formed, not part of the @papi/* surface.

    This is a local, in-process event: only the process that owns the connections can observe one being lost, so it fires exclusively in the process holding the websocket server. Everywhere else it is a real event that simply never fires.

    onDidLoseConnection: PlatformEvent<void>

    Event that fires when this process's own connection to the network is lost unexpectedly — the websocket closed without the app having asked it to.

    This is platform-internal core plumbing between the process that holds a client connection and the services that react to losing one, not part of the @papi/* surface — the same status as onDidDisconnectClient above, which is this seam in the opposite direction.

    This is a local, in-process event. Only a process that holds a client connection can lose one, so it fires exclusively on clients; in the process that owns the websocket server it is a real event that simply never fires. A deliberate disconnect does not fire it: intent travels in the close code, and a close the app asked for is not a loss.

    Nor does a connection that was never established. A socket that dies during the opening handshake is a failed connection ATTEMPT, which connect reports through its own return value; surfacing a startup that never reached the network is separate work (PT-4494 / PT-4495). This event is only for losing a connection that was up.

    Carries no payload. The close detail is logged where it is observed, and a subscriber's job is to react to the loss rather than to classify it.

    registerEvent: (
        eventName: string,
        documentation?: SingleNotificationDocumentation,
    ) => Promise<boolean>

    Register a centrally-tracked network event with the main process. Multi-source vs single-source semantics is determined by looking up the event name in MULTI_SOURCE_EVENT_NAMES. See MultiSourceNetworkEvents for multi-source vs single-source semantics.

    Returns true if the registration was accepted, false otherwise. Used by createNetworkEventEmitterAsync; not for direct caller use.

    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,
        skipRetry?: boolean,
    ) => Promise<JSONRPCResponse>

    Send a request and resolve after receiving a response

    Type declaration

      • (
            requestType: `${string}:${string}`,
            requestParams: RequestParams,
            skipRetry?: boolean,
        ): Promise<JSONRPCResponse>
      • Parameters

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

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

        • requestParams: RequestParams

          Parameters associated with this request

        • OptionalskipRetry: boolean

          Whether to skip the retry process that will retry up to 10 times

        Returns Promise<JSONRPCResponse>

        Promise that resolves to a JSONRPCSuccessResponse or JSONRPCErrorResponse message

    unregisterEvent: (eventName: string) => Promise<boolean>

    Unregister a network event emitter so it is no longer tracked centrally

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

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