@awari/transport-peerjs
v0.0.6
Published
PeerJS-backed implementation of @awari/core's Transport interface, using PeerJS's public broker for signaling.
Downloads
873
Readme
@awari/transport-peerjs
PeerJS-backed implementation of @awari/core's Transport interface, using PeerJS's default public broker for WebRTC signaling. This is the only package that knows PeerJS exists — everything above it (routing, connection planning, ranking) depends only on the Transport interface, so a different transport can be swapped in later without touching them.
See ADR 0008 for the reasoning, including why this can be built and type-checked here but not exercised by automated tests (it needs a real browser WebRTC environment).
Configuring ICE servers / a self-hosted broker
createPeerJsTransport takes an optional peerOptions, passed straight through
to the underlying PeerJS Peer — use it to override the defaults that don't
suit your environment.
The quick way — drop in a built-in preset (IceProvider / ICE_SERVERS):
import { createPeerJsTransport, ICE_SERVERS, IceProvider } from "@awari/transport-peerjs";
const transport = createPeerJsTransport({
peerOptions: { config: { iceServers: ICE_SERVERS[IceProvider.Google] } },
});IceProvider has Google (STUN), Cloudflare (STUN), and OpenRelay (STUN +
TURN). These point at third-party infrastructure this package neither
operates nor endorses — the STUN entries are stable and free; the Open Relay
TURN uses shared public credentials and is best-effort only (rate-limited, may
be down), so verify it before relying on it and use selfHostedTurn(...) for
production. Endpoints can change without notice.
The full control way — hand-write peerOptions:
const transport = createPeerJsTransport({
peerOptions: {
// Replace PeerJS's default cloud ICE config (whose public TURN servers —
// e.g. eu-0.turn.peerjs.com — are flaky and, in some runtimes like
// Electron/restricted DNS, fail to even resolve: a
// `net::ERR_NAME_NOT_RESOLVED` / socket_manager error in the WebRTC log).
config: {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
// For peers on different networks you need a reachable TURN relay:
// { urls: "turn:your-turn.example.com:3478", username: "u", credential: "p" },
],
},
// Or point at your own PeerServer instead of the public broker:
// host: "peer.example.com", port: 443, path: "/", secure: true,
},
});Passing config.iceServers replaces PeerJS's default list (it doesn't
merge), so include STUN yourself if you still want it. STUN-only is enough for
same-machine/LAN peers; cross-network peers behind symmetric NAT need a real
TURN relay.
