This reference documents the public developer-facing API for @rupertsworld/electron-ipc.
IPCService<TEvents>exposeIPC(serviceOrCtor, serviceName?, deps?)getPreloadPath()enableIPC(deps?)resolveIPC<T>(serviceName)from@rupertsworld/electron-ipc/renderer
Base class for main-process services that emit typed events.
on<K extends keyof TEvents>(event: K, listener: (payload: TEvents[K]) => void): thisonce<K extends keyof TEvents>(event: K, listener: (payload: TEvents[K]) => void): thisoff<K extends keyof TEvents>(event: K, listener: (payload: TEvents[K]) => void): thisemit<K extends keyof TEvents>(event: K, payload: TEvents[K]): this
offis a silent no-op if listener is not registered.- Events emitted before listener registration are not replayed.
- If one listener throws, other listeners still run.
Registers a service in the main process.
serviceOrCtor: object | new () => objectserviceName?: string(defaults to constructor name)deps(optional runtime injection for tests/custom wiring):ipcMaineventBus
When deps is omitted, Electron defaults are resolved at runtime from the host app.
- Duplicate resolved service name registration throws.
- Service can be provided as class constructor or instance.
- Service methods are invoked by renderer RPC calls.
- Missing/non-callable methods reject with contextual errors.
- Reserved framework method names (
on,off,once,emit,setEmitHook,constructor) are not callable as RPC methods.
Returns an absolute path to the package-shipped preload script (preload.cjs).
- Returns an absolute path.
- Returned path points at an existing file.
- Path is stable across process cwd changes.
- Throws deterministic error text if path resolution fails.
Sets up preload bridge APIs and exposes them on window.ipcServiceBridge.
depsoptional preload injection:contextBridgeipcRenderer
When omitted, Electron defaults are resolved at runtime from the host app.
- Must be called before renderer uses
resolveIPC(...). - Exposes bridge methods:
invoke(serviceName, methodName, args)hasService(serviceName)on(serviceName, eventName, callback)returning unsubscribe function
Resolves a typed renderer-facing proxy for a registered main service.
Import path:
import { resolveIPC } from '@rupertsworld/electron-ipc/renderer'
- Throws immediately if service is not registered.
- Non-event methods are async (
Promise) at call sites over IPC. on/once/offare preserved for event subscription semantics.- Method failures reject with service/method contextual error messages.
- Use shared interfaces like:
interface IMyService extends IPCService<MyServiceEvents> { ... }
- Resolve with:
const service = resolveIPC<IMyService>('MyService')
This keeps event payloads and method signatures typed in renderer usage.
npm run testruns unit + boundary integration tests.npm run test:electronruns real Electron process integration tests.npm run test:allruns both.- Electron integration can require a host environment that supports launching Electron windows.