This folder contains files for a single Cloudflare Worker that:
- serves the built Vite frontend (Workers Assets)
- provides a WebSocket backend using a Durable Object (one room per
instance_id)
- Node.js 20.19+ or 22.12+ (required by Vite)
- npm
- Install deps
npm install- Run the backend (Worker) locally:
npm run devThis starts wrangler dev on http://localhost:8787.
- Run the frontend (Vite) in a second terminal:
npm run dev:webOpen the Vite URL (usually http://localhost:5173).
The frontend will auto-connect to the local Worker at ws://localhost:8787/ws?instance_id=....
Run timing + scenario tests for the web client:
npm run test:web- Authenticate:
npx wrangler login- Deploy:
npm run deployThis builds the Vite app into web/dist and deploys the Worker + assets.
Discord Activities loads your URL in an iframe and provide an instance_id query param.
This project uses:
?instance_id=...as the multiplayer room id- WebSockets on the same origin:
/ws?instance_id=...
To setup the discord activity:
- Go to https://discord.com/developers/applications
- Choose your Application
- Go to "Activities - Settings":
- Check "Enable Activities"
- Check "Supported Platforms" for Web, iOS, Android
- Go to "Activities URL Mappings":
- prefix
/; target:wos-rally-sync.yourdomain.workers.dev
- prefix
- (Optional) Set custom Background/Coverart at "Activities - Art Assets"
- Ensure your Activity is allowed to use WebSockets.
Client sends:
STATE_REQUESTPLAYER_ADDPLAYER_REMOVERALLY_START({ starterId, rallyDurationMs, preDelayMs }or{ starterId, launchAt })RALLY_ENDTIME_SYNC_REQUEST({ t0 })
Server broadcasts:
{ type: "STATE", payload: { players, rally } }TIME_SYNC_RESPONSE({ t0, t1, t2 })