Integrations
Peer-to-Peer
Bidirectional RPC between two Katman instances — Electron, Web Workers, browser extensions.
Two peers that can call each other's procedures simultaneously. Uses MessagePort or any bidirectional channel.
Setup
import { } from "katman/peer"
// Peer A (e.g., Electron main process)
const = (mainRouter, channel.port1)
// Peer B (e.g., Electron renderer)
const = (rendererRouter, channel.port2)
// A calls B's procedures
const = await ..()
// B calls A's procedures
const = await ..({ : "/tmp" })Use cases
- Electron: main ↔ renderer communication with typed RPC
- Web Workers: main thread ↔ worker thread
- Browser extensions: background ↔ popup/content scripts
- Node.js Worker Threads: parent ↔ child
How it works
createPeer() does two things on the same port:
- Serves your local router (handles incoming requests)
- Creates a typed client for the remote peer's router
Messages are tagged with __type: "request" or __type: "response" so they don't conflict.
Cleanup
peerA.dispose() // stop listening
peerB.dispose()What's next?
- Message Port — one-way RPC (server + client on separate ports)
- Integrations — other available integrations