A multiplayer game starter built with React Three Fiber (R3F), Node.js, WebSockets, and Vite.
Mobile controls using nippleJS and WASD movement controls on desktop.
- Use Node.js 20.19 or newer.
- Install dependencies:
npm installRun the full development app, including the Express/WebSocket server and Vite middleware:
npm run devOpen http://localhost:8080.
Build production assets:
npm run buildRun the production server after a build:
npm startBuild and run production locally:
npm run previewPeer-to-peer WebRTC. The server relays signalling and serves the ICE server list from
/ice-servers.
A deployment needs a TURN relay. Without one, voice works between some pairs of players and
not others, with no error on either side. Create a TURN Server app at dash.cloudflare.com ->
Realtime -> TURN and set TURN_TOKEN_ID and TURN_API_TOKEN.
/ice-servers is public, so it never serves the key itself - it exchanges it for a credential
that expires after two hours. If Cloudflare cannot be reached, voice degrades to STUN rather than
taking the game down.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Suggestions for improving the server and WebSocket flow would be much appreciated.
The server supplies world time on join and on each 25-second heartbeat. Clients compensate for half the round-trip delay and advance using a monotonic browser clock, so local clock settings do not change the time of day. Reconnecting resynchronizes automatically.
shared/dayNightCycle.js defines a repeating 10-minute cycle: five minutes from sunrise to
sunset and five from sunset to sunrise. Dawn, dusk and blue twilight blend across each
horizon crossing (roughly 45 seconds), within those ten minutes. A fixed UTC epoch keeps
the cycle running through empty rooms and server restarts. The sun and moon peak at 25°
and travel across the negative-Z side of the sky; their directions also drive the key
light, moving shadows and grass highlights. Night retains the cool forest palette.
Run node --test shared/dayNightCycle.test.js to check timing, paths and server messages.
