This repo contains two Workers
- Website for https://silentspacemarine.com/ in Cloudflare Pages
- Wasm Doom message router, using WebSockets and Durable Objects
Assets are in ./assets
Worker code is in site/index.js
You need the following files in ./assets
(not included in this repo):
- doom1.wad (md5sum: f0cefca49926d00903cf57551d901abe)
- websockets-doom.js - get it from doom-wasm src directory after compilation
- websockets-doom.wasm - get it from doom-wasm src directory after compilation
- websockets-doom.wasm.map - get it from doom-wasm src directory after compilation
npm install -g @cloudflare/wrangler@beta
wrangler login
wrangler publish --config wrangler-site.toml
Adjust wrangler-site.toml to your account_id
and zone_id
.
Our message router has the following requirements:
- Accept Wasm Doom WebSocket connections and build a routing table
- Receive and parse the incoming messages
- Broadcast the messages to the corresponding clients
- Handle some REST APIs to create and validate Doom rooms (sessions)
Just supports the network multiplayer in our Silent Space Marine showcase project.
Read more about it in our blog post here.
The router source code is at router/index.mjs
First make sure you have Durable Objects enabled in your account.
Make sure you have the Durable Objects wrangler (beta) installed:
npm install -g @cloudflare/wrangler@beta
Adjust wrangler-router.toml to your account_id
and zone_id
or use the CF_ACCOUNT_ID
and CF_ZONE_ID
environment variables.
Run this command just once
wrangler login
wrangler publish --config wrangler-router.toml --new-class Router
Later updates use:
wrangler login
wrangler publish --config wrangler-router.toml
You can use make
to deploy the workers.
Create an .env
file with your account and zone ids:
ROUTER_CF_ZONE_ID = 72...........91
ROUTER_CF_ACCOUNT_ID = 0a...............2f
SITE_CF_ZONE_ID = 13....................a0
SITE_CF_ACCOUNT_ID = 07.................4f
Run make
:
make publish
You can run the Website, Wasm Doom and Multiplayer locally, in your computer, using a NodeJS WebSocket router implementation.
First install NodeJS and npm. Then:
cd scripts
npm install
./router.js
Point your browser to http://0.0.0.0:8000
Read more about Multiplayer Doom on Cloudflare Workers in our blog post here.