rtc.io-server
v1.2.0
Published
Signaling server for the rtc.io WebRTC client. Built on socket.io.
Downloads
564
Readme
rtc.io-server
Node signaling server for rtc.io. Thin wrapper on top of socket.io that wires up the rtc.io signaling protocol.
npm install rtc.io-serverUsage
import { Server } from "rtc.io-server";
const server = new Server({ cors: { origin: "*" } });
server.on("connection", (socket) => {
socket.on("join-room", ({ roomId, name }) => {
socket.data.name = name;
socket.join(roomId);
// Tell every existing peer in the room to initiate an offer to the new one.
socket.to(roomId).emit("#rtcio:init-offer", { source: socket.id });
});
// No `disconnecting` handler needed for peer cleanup — the rtc.io-server
// core emits `#rtcio:peer-left` automatically. Add one only if you have
// app-level cleanup (presence rosters, room password registries, etc.).
});
server.listen(3001);What this server does
The rtc.io client multiplexes all WebRTC signaling (offers, answers, ICE candidates, stream metadata) into a single #rtcio:message event. This server registers default handlers that:
- Relay
#rtcio:messageenvelopes to the addressed peer (socket.to(target).emit(...)). - Emit a
#rtcio:peer-leftnotification to a leaving socket's rooms ondisconnecting, so existing peers can short-circuit ICE consent-freshness (~30 s) when a tab closes. The client treats this as a hint that's cross-checked against the local WebRTC state; it never tears down a healthy P2P call on the basis of a signaling-only event. See the signaling protocol for the full contract.
Everything else — room management, app-level events, presence — is your code.
What you implement
- Room/lobby logic.
socket.join(roomId), fan-out on join, presence broadcasts. - The
#rtcio:init-offerkickoff. When a new peer joins a room, emit this to existing peers so they initiate offers to the newcomer. The client listens for it and starts the WebRTC handshake. - App-level events. Chat persistence, auth, etc.
The server has no opinion about any of these — it's just a relay.
API
import { Server, ServerOptions, RtcioEvents } from "rtc.io-server";Server— extends socket.io'sServer. Same options.addDefaultListenersis attached automatically on everyconnection.RtcioEvents— string constants for the rtc.io reserved event names (useRtcioEvents.INIT_OFFERinstead of typing"#rtcio:init-offer"by hand).addDefaultListeners(socket)— registers the message-relay handler. Called automatically; expose for advanced use.
Wire compatibility
This server speaks the rtc.io signaling protocol — pair it with rtc.io@^1.1.0 clients. The envelope format changed in 1.1, so older clients are not wire-compatible.
License
MIT
