openrtc-netcode
v0.1.0
Published
A small lobby, mesh, message, and replicated-state netcode layer built on OpenRTC.
Maintainers
Readme
openrtc-netcode
openrtc-netcode is a small multiplayer layer on top of OpenRTC. It treats
OpenRTC rooms as lobbies, forms a deterministic P2P mesh between lobby members,
and exposes reliable typed messages, lightweight replicated state, networked
objects, and browser voice-chat signaling.
Gameplay payloads are sent over OpenRTC peer data paths only: Iroh
relay/direct, WebRTC DataChannel upgrades, and MoQ routes when enabled. Firebase
and Firestore remain part of OpenRTC's control plane for identity, discovery,
rooms, tickets, and browser signaling metadata; openrtc-netcode does not use
Firestore as a state or message relay.
import { createNetcode } from 'openrtc-netcode';
const netcode = createNetcode({ apiKey: 'pk_live_...' });
await netcode.createLobby({ id: 'duel-room' });
netcode.onMessage('chat', (message) => {
console.log(message.from, message.payload);
});
await netcode.broadcast('chat', { text: 'hello' });Networked game objects are synchronized through netcode.objects:
await netcode.objects.spawn({
id: 'crate-1',
kind: 'crate',
transform: { position: { x: 0, y: 1, z: 0 } },
physics: { linearVelocity: { x: 0, y: 0, z: 0 } },
});Voice chat uses OpenRTC netcode connections for SDP/ICE signaling and lets the browser WebRTC stack carry microphone media:
await netcode.voice.start();
netcode.voice.on('peer:stream', ({ stream }) => {
audioElement.srcObject = stream;
});