UNPKG

node-simple-ipc

Version:

A Node.Js module for local Inter Process Communication

82 lines (81 loc) 2.74 kB
import { IpcProcess, IpcActOptions, IpcHandler, EventHandler, NodeSimpleIpcOptions, RemoveHandler } from './types'; export declare class NodeSimpleIpc { private ipcProcess; private options; private rpcEm; private eventsEm; private registeredRpcNames; private messageHandler; /** * Constructor. * * @param ipcProcess IPC process (NodeJS.process or ChildProcess). By default "process" will be used. * @param options NodeSimpleIpc options. */ constructor(ipcProcess?: IpcProcess, options?: NodeSimpleIpcOptions); private onIpcMessage; /** * Start a RPC request. * * @param name RPC name. * @param data Request data (optional). * @param options Request options. * @returns The response. */ act<D = unknown>(name: string, data?: unknown, options?: IpcActOptions): Promise<D>; /** * Add a RPC endpoint. * * @param name RPC name. * @param handlerFn Handler function. * @returns Function you can call to remove the RPC endpoint. */ add<I = unknown, O = unknown>(name: string, handlerFn: IpcHandler<I, O>): RemoveHandler; /** * Adds the listener function to the end of the listeners. * * @param event Event name. * @param handler Listener function. * @returns Function you can call to remove the event handler. */ on<T = unknown>(event: string, handler: EventHandler<T>): RemoveHandler; /** * Adds a one-time listener function for the event. The next time event is triggered, this listener is removed and then invoked. * * @param event Event name. * @param handler Listener function. * @returns Function you can call to remove the event handler. */ once<T = unknown>(event: string, handler: EventHandler<T>): RemoveHandler; /** * Removes the specified listener from the listener array. * * @param event Event name. * @param handler Listener function. * @returns Returns a reference to the NodeSimpleIpc. */ off<T = unknown>(event: string, handler: EventHandler<T>): void; /** * Send an event over IPC. * * @param event Event name. * @param data Event data (optional). * @returns The sending result. */ emit(event: string, data?: unknown): boolean; /** * Send RPC output properties over IPC. * * @param input Input properties. * @param partialOutput Output properties (only data and error). * @returns The sending result. */ private sendOutput; /** * Send RPC input properties over IPC. * * @param partialInput Input properties. * @returns The sending result. */ private sendInput; }