kkrpc
    Preparing search index...

    Function createRelay

    • Creates a transparent bidirectional relay between two IoInterfaces. Messages flow in both directions without parsing.

      Parameters

      Returns Relay

      // Relay between IPC and stdio (Electron main process)
      import { createRelay, NodeIo } from "kkrpc"
      import { ElectronIpcMainIO } from "kkrpc/electron-ipc"
      import { spawn } from "child_process"

      // Spawn external process
      const worker = spawn("node", ["./worker.js"])

      // Create relay: IPC <-> stdio
      const relay = createRelay(
      new ElectronIpcMainIO(ipcMain, webContents, "my-channel"),
      new NodeIo(worker.stdout, worker.stdin)
      )

      // Cleanup
      relay.destroy()
      // Renderer side (separate channel)
      import { ElectronIpcRendererIO, RPCChannel } from "kkrpc/electron-ipc"

      const io = new ElectronIpcRendererIO("my-channel")
      const rpc = new RPCChannel(io)
      const api = rpc.getAPI<WorkerAPI>()

      // Calls go directly to worker through main's relay
      const result = await api.calculate(42)