WebGL NativeUnity 3D C#Godot 4Node.jsZero Server Cost
Looking for class properties and methods?
Mereb is an ultra-lightweight (13 kB gzipped), zero-cost multiplayer netcode and matchmaking engine designed specifically for modern web games, web game portals (Poki, CrazyGames), mobile web browsers, indie game engines (Godot 4, Unity WebGL, Three.js, Phaser 3), and React applications.
The Economic Problem Mereb Solves
Dedicated server platforms (Hathora, AWS GameLift, Agones) cost $150 to $1,000+/month in continuous container uptime and bandwidth fees. For indie and web games monetizing via ad impressions ($1.50-$3.00 CPM), dedicated server bills bankrupt games. Mereb streams 60Hz gameplay directly P2P over WebRTC UDP, reducing server bills to $0/month.
High-Level Network Topology
Mereb utilizes a Host-Authoritative WebRTC Mesh Topology coordinated by Cloudflare Workers and Durable Objects:
Unlike standard WebSockets that suffer from severe head-of-line blocking when a single packet drops on mobile Wi-Fi, Mereb initializes two independent WebRTC channels between peers:
Match start, player deaths, kills, round timers, game over, chat, and scoring.
Smart Bot Fallback (Eradicating Empty Lobbies)
If matchmaking exceeds botTimeoutMs (default: 8,000ms), Mereb automatically activates a local offline AI bot. The queue never feels empty, and players never bounce from your game.
5-Minute Quickstart
Setup GuideESM / npm
Follow these steps to integrate real-time P2P multiplayer into your game in under 5 minutes:
Step 1: Install Package
npm install mereb-netcode
Step 2: Core Game Loop Blueprint
JavaScript / TypeScript
import { MerebClient, MerebLobby, SnapshotInterpolator } from 'mereb-netcode';
// 1. Initialize Multiplayer Client
const net = new MerebClient({
host: 'mereb-signaling.dawitbaslyos.workers.dev',
botTimeoutMs: 8000,
autoJoinFromUrl: true
});
// 2. Attach Drop-in Arcade Lobby UI
const lobby = new MerebLobby(net, { title: '⚔️ ARENA WARRIORS' });
// 3. Set up Interpolation Buffer for Smooth Opponent Movement
const interpolator = new SnapshotInterpolator({ bufferTime: 80 });
// 4. Handle Match Lifecycle
net.on('match-start', ({ role, isHost, localId, peerId, isBot }) => {
console.log(`Match Active! Role: ${role}, Opponent: ${peerId}`);
if (isHost) {
// Host: Run Authoritative Simulation Loop (20-60Hz)
setInterval(() => {
net.sendState({
t: Date.now(),
x: player.x,
y: player.y,
health: player.health
});
}, 50);
} else {
// Client: Stream Inputs to Host
window.addEventListener('keydown', (e) => {
net.sendInput({ key: e.key, down: true });
});
}
});
// 5. Client receives World State & feeds Interpolator
net.on('state', (serverState) => {
interpolator.pushSnapshot(serverState.t, { opponent: serverState });
});
// 6. Render Loop (60/120 FPS)
function render() {
requestAnimationFrame(render);
if (!net.isHost) {
const smooth = interpolator.getInterpolated();
if (smooth.opponent) {
opponentSprite.x = smooth.opponent.x;
opponentSprite.y = smooth.opponent.y;
}
}
}
requestAnimationFrame(render);
Why Mereb is Better: Industry Benchmarks
Economic AnalysisPhoton vs Hathora vs Mereb
Game developers building web, mobile, and indie multiplayer games face a recurring economic crisis: Dedicated multiplayer server costs often exceed the total ad and in-app purchase revenue generated by the game.
Monthly Hosting Cost at 1,000 CCU
⚔️ Mereb SDK
$0.00 / mo (100% Free)
Hathora
$340 / mo
Photon Fusion
$380 / mo
AWS GameLift
$450 / mo
Agones / GKE
$520 / mo
Detailed Feature Matrix
Feature
⚔️ Mereb SDK
Photon Engine
Hathora
Agones / K8s
1,000 CCU Cost
$0 / month
$190 – $380 / mo
$180 – $350 / mo
$320 – $750 / mo
Egress Bandwidth
$0 (Direct P2P)
$0.08 / GB overage
$0.05 – $0.09 / GB
$0.09 / GB (Cloud)
Cold-Start Time
0 ms (Instant)
~250 ms
15 – 45 seconds
30 – 90 seconds
Same-Region Ping
5 – 18 ms (UDP)
45 – 85 ms
35 – 70 ms
40 – 80 ms
Poki/CrazyGames Ad Hooks
Built-in
❌ Disconnects
❌ Disconnects
❌ Disconnects
8s Bot Fallback
Built-in
❌ Manual code
❌ Manual code
❌ Manual code
Binary Compression
Built-in (85%)
Proprietary
Manual Protobuf
Manual Protobuf
Cloudflare Workers Deployment
Durable ObjectsSQLite Engine
Deploy your own globally distributed signaling and matchmaking cluster to Cloudflare's edge in 60 seconds.
Step 1: Review `wrangler.toml`
wrangler.toml
name = "mereb-signaling"
main = "worker.js"
compatibility_date = "2024-09-23"
[durable_objects]
bindings = [
{ name = "GAME_ROOM", class_name = "GameRoom" }
]
[[migrations]]
tag = "v1"
new_sqlite_classes = ["GameRoom"]
Step 2: Deploy to Production
cd cloudflare
npx wrangler deploy
STUN / TURN Relays & Polar Billing
NAT TraversalMonetization
Mereb pools redundant STUN servers and automatically falls back to TLS TURN over port 443 for players behind strict institutional firewalls.
RFC 5766 Dynamic HMAC TURN Relays
When connecting from university dorms or cellular data, fetch dynamic time-limited TURN credentials:
const res = await fetch('https://mereb-signaling.workers.dev/api/turn-credentials');
const { iceServers } = await res.json();
const net = new MerebClient({
host: 'mereb-signaling.workers.dev',
turnServers: iceServers
});
Unity 3D WebGL Integration
Unity 2022 / 2023 / Unity 6C# WebGL Bridge
Integrate Mereb into Unity WebGL builds via a native JavaScript bridge plugin (MerebBridge.jslib) and a C# manager (MerebNetworkManager.cs).