Guides WebRTC without a signaling server

WebRTC without your own signaling server

Opening a direct WebRTC connection between two browsers still requires signaling—a side channel to exchange session descriptions and network candidates before the peer-to-peer link exists. Instead of requiring a custom WebSocket backend, Trystero performs signaling over existing public relays so multiplayer apps can deploy as static files.

How public-relay signaling works

During WebRTC setup, peers exchange an SDP offer, an SDP answer, and ICE candidates describing reachable IP/port paths. Those payloads are a few kilobytes of connection metadata; once the WebRTC channel opens, peers communicate directly and the signaling path goes idle.

Trystero routes those handshakes through interchangeable signaling strategies: public Nostr relays by default, or MQTT brokers, BitTorrent trackers, Supabase, Firebase, or a self-hosted WebSocket relay via a single import swap. Relays only receive a SHA-256 hash of appId and roomId as the topic, and SDP/ICE payloads are encrypted with AES-256-GCM before leaving the browser. Application state, messages, files, and media streams never pass through the signaling relay.

Minimal setup

Pick a globally unique appId for your application, such as a domain you control or 'username/app-name'. Peers joining the same room name discover each other across the relay pool and open direct data channels:

import {joinRoom} from 'trystero'

const room = joinRoom({appId: 'whiteboard.example.com'}, documentId)

const stroke = room.makeAction('stroke')

stroke.onMessage((points, {userId}) => renderRemoteStroke(userId, points))

canvas.addEventListener('pointermove', e => {
  if (e.buttons) stroke.send([e.offsetX, e.offsetY, e.pressure])
})

Every incoming message arrives with a verified userId derived from the sender's ECDSA public key; see Self-certifying identities for how key ownership is verified during the WebRTC handshake.

What a signaling relay can observe

A public relay can observe connection timing, client IP addresses, how many endpoints subscribed to a given SHA-256 topic hash, and the ephemeral peerIds in announcements. Without knowing your appId and roomId, it cannot recover the room name or decrypt SDP payloads. Adding a room password derives the AES-256-GCM key via PBKDF2-SHA256 so even someone who knows appId and roomId cannot decrypt offers or join; see End-to-end encryption in P2P apps.

Running your own signaling relay

Public relays suit prototypes, demos, and lightweight apps. When you need dedicated availability guarantees, LAN-only operation without internet access, or control over relay endpoints, deploy @trystero-p2p/ws-relay on any Node host and keep the same room code:

import {joinRoom} from '@trystero-p2p/ws-relay'

const room = joinRoom(
  {
    appId: 'whiteboard.example.com',
    relayConfig: {urls: ['wss://relay.example.com']}
  },
  documentId
)

If your stack already includes Supabase or Firebase, their strategy packages use your project for signaling. For other pub/sub systems such as Cloudflare Durable Objects or PartyKit, createTopicStrategy adapts any topic transport in roughly 30 lines of code.

Where TURN fits

Signaling handles peer discovery, whereas NAT traversal determines whether packets can flow directly once peers know each other's addresses. On roughly 10–15% of networks—strict corporate firewalls, symmetric NATs, and some cellular carriers—direct UDP hole-punching fails and WebRTC requires a TURN server to relay DTLS-encrypted packets. Public signaling relays do not provide TURN; see TURN & troubleshooting to configure turnConfig with short-lived credentials.