Minimal air hockey game.
Prerequisites: Node.js
- Install dependencies:
npm install - Run the app:
npm run dev
This repo now includes an online lobby/room system for WebRTC P2P (Mode A):
- Lobby: room list, create room, join by roomId (search)
- Signaling relay: offer/answer/ice (gameplay wiring comes next)
- Sign up at Cloudflare.
- Make sure you can access the Workers & Pages dashboard.
From the project root:
npm install -g wrangler
wrangler loginIf you prefer not to install globally, you can use the local one under cf/worker.
The worker lives in cf/worker.
cd cf/worker
npm install
wrangler deployNotes:
- The first deploy applies the Durable Object migration in
cf/worker/wrangler.toml. - Wrangler will print your Worker URL, for example:
https://hockey-lobby.<your-subdomain>.workers.dev
- The lobby WebSocket endpoint is
.../ws.
Create or edit d:/GameDev/WebGame/hockey/.env.local:
VITE_LOBBY_WS_URL=wss://hockey-lobby.<your-subdomain>.workers.dev/wsThen run:
npm run devOpen the page, you should see:
- Lobby shows CONNECTED
- Create Room -> enters Room screen
- Room list updates and search by Room ID works
Nothing special for this phase (Worker + Durable Objects are configured by wrangler.toml).
If you want a custom domain later:
- Add your domain to Cloudflare
- Workers -> Triggers -> Custom Domains
- Set
VITE_LOBBY_WS_URLto your custom domainwss://.../ws
You can build this with PeerJS, but this repo uses a Cloudflare Worker + Durable Object for these reasons:
- We need a lobby/rooms anyway: room list + search + join are first-class features here.
- Stable WebSocket signaling: Vercel Serverless/Edge is not a great fit for long-lived WebSocket stateful routing; Durable Objects are.
- Lower moving parts: no extra PeerJS server to run; signaling and lobby are one deploy.
- More control: protocol is explicit (offer/answer/ice), so we can add reconnect rules and debugging without a black box.
If you already have a good PeerJS server + region strategy, it can work, but you still end up needing a lobby/state store somewhere.
