webrpc

An elegant P2P SDK keeps networking inside the library

Judge an SDK by how many lines of business-unrelated code it forces you to write.

What "well encapsulated" actually means

A small API surface is not the same as good encapsulation. Real encapsulation means the caller never needs to know how candidates are gathered, when the punch fires, which key exchange runs, or who reconnects after a drop. Leak any of that and it becomes state checks scattered through your code.

There is a direct test: count the branches in your business code that ask whether the peer is connected, whether it reconnected, or whether this error is retryable. A poorly encapsulated SDK makes that number large.

What the RPC style changes

webrpc models the peer as a callable object: you make a call, and the library establishes or reuses the session, encrypts, serializes and propagates errors. Your code sees a method invocation, not a socket to maintain.

The practical consequences: peers can be substituted in unit tests, reconnect logic lives in one place instead of at every call site, and adding an endpoint does not require re-learning the transport.

Encapsulation should not hide cost

Good encapsulation makes cost observable rather than invisible. When a session is established, webrpc reports whether it is direct or degraded to a relay, the current RTT, and the failure reason. You can ignore that, or degrade deliberately when it matters.

This distinction matters: an SDK that leaves you unable to judge connection quality is not elegant, it is opaque.

The comparison

Assembling a WebRTC or libp2p stack yourself reaches the same place, but first you must decide how signaling is deployed, where ICE servers live, how punching falls back, and how state recovers after a drop. Every one of those decisions lands in product code and gets revisited as requirements move.

Replacing that layer with a stable abstraction is, in essence, transferring long-term maintenance cost out of your codebase.

Want to see a complete implementation?

MyWebDisk: a personal cloud built on webrpc

FAQ

Does an RPC style limit flexibility?

No. The underlying connection is readable and writable, so you can drop to the transport interface for streaming work.

Are the language bindings consistent?

Go, Java, Python, C/C++, Rust and PHP share one call semantic with aligned method names and parameter shapes.

Does product code handle reconnects?

No. Keepalive and reconnect live inside the library; callers only observe success or failure.

Can I observe connection quality?

Yes. Session establishment reports direct versus relayed, RTT and failure reason so you can degrade deliberately.

Does encapsulation cost performance?

No. The abstraction adds no relay; data still travels directly between peers.

Related articles

Other topics