The BrowserSpace demo announcement describes the player-facing idea: choose a Space, meet a few people, and build. This post is about the networking system underneath it. The goal for the beta is a discoverable shared place without committing to persistent worlds, accounts, or a large browser networking library.
The renderer still draws images with CSS 2D transforms. Networking changes the world data and adds remote character entities; it doesn't send pictures or introduce another rendering pipeline. The earlier renderer posts cover that side of the engine.
One service, several shared worlds
A Node HTTP server serves the game files and the island directory. The same service accepts WebSocket upgrades through the server-side ws package. In the browser, the client uses the native WebSocket API, which provides an ongoing connection in both directions.
Each occupied island has its own voxel array, players, and revision counter. A client joins one island and receives only that island's state. The beta admits four players per island, with a default process-wide limit of 16 islands. Those are explicit limits for this POC, not measured population ceilings.
The first public interface is deliberately ordinary:
| Request |
Purpose |
GET api/rooms |
List islands, their names, occupancy and capacity |
WebSocket room?id=… |
Join one island and exchange updates |
The directory refreshes every ten seconds while the picker is open. New Space opens a choice of Demo or Flat terrain and creates a new room when someone joins; it doesn't reserve an empty world on every refresh. The server settles joining races against the four-player cap. If all room slots are used, an old empty room can be evicted. If every room is occupied, starting another has to wait.
Empty islands expire after 30 minutes. All shared state is in memory, so restarting the process clears it. Solo saves live in the browser and are kept separate. We run one Node process: starting a second independent instance would create a second directory and a different set of worlds.
Join with a snapshot
A joining player needs more than the latest few edits. The server sends a complete snapshot containing the terrain template (Demo or Flat), the block bytes, the current revision, generated-tree validity flags, and the room's players. It also assigns an identifier and a generated label such as Builder 2.
The voxel volume is only 24 × 12 × 24: 6,912 one-byte blocks. The current protocol encodes those bytes as base64 inside JSON, making the block string 9,216 ASCII characters before the rest of the message. That isn't the most compact representation, but it is small enough to start with and easy to inspect. The 4 KiB server message limit applies to incoming client messages, not this outgoing snapshot.
The client replaces its local shared world, rebuilds exposure information, clears pending edits and old remote entities, and chooses a safe spawn from the server's world. A reconnect uses the same full-state path. It does not try to replay actions made while disconnected.
Generated trees need one extra bit of care. A distant tree can be drawn as one pre-rendered image, but an edited tree must fall back to its actual blocks. Including the validity flags keeps a late join from drawing a pristine tree over somebody's changes.
Keep movement immediate, send a smaller story
The local controller continues to handle movement, collision, jumping and camera orbit without waiting for a round trip. It sends position, body heading and an animation pose at up to 10 Hz when they change; stationary presence is reduced to about 1 Hz.
Body heading is separate from camera yaw. Turning the camera around a standing character should change our view of that character, not tell everyone that the character turned to face a new direction.
The server bounds and validates the reported transform, then broadcasts changed player state on a 100 ms interval. Other clients ease their remote sprites toward the newest target:
const amount = Math.min(1, dt * 12);
remote.x += (target.x - remote.x) * amount;
remote.y += (target.y - remote.y) * amount;
remote.z += (target.z - remote.z) * amount;
That is simple smoothing toward the latest state. It is not a buffered timeline, extrapolation, or a server movement simulation. Each remote character uses one of the renderer's existing surface slots; joining three neighbours doesn't add a DOM hierarchy for three articulated bodies.
This is also an important boundary in what the beta guarantees. The server receives player positions, rather than simulating acknowledged movement inputs. There is no server-authoritative movement or anti-cheat system here. The public sandbox scope lets us test shared building before taking on that larger job.
Give block edits one order
Movement can tolerate a newer position superseding an older one. A block edit needs a shared answer.
The client sends a request identifier, a cell, a new material, and the material it expects to find there. It predicts the edit locally for a quick response. The server compares the expected value to its world and checks coordinates, material, reach, line of sight, player-body overlap and the protected foundation. It also limits edit rate.
For an accepted edit, the server changes the block, increments the island revision, and broadcasts the result to everyone, including the builder. A rejected request includes the cell's authoritative value, so that prediction can be rolled back.
Consider two people removing the same stone:
- Both observe stone and ask to replace it with air.
- The first accepted request changes the server's cell and increments the revision.
- The second request expects stone, but finds air. The server rejects it with the current value.
- Both clients converge on air.
The expected value protects a cell-level assumption. It is not a full world transaction or a promise of persistent edit history. The revision gives accepted edits a room-wide order. If the client receives revision 42 while expecting 41, it stops editing and requests a fresh snapshot.
WebSocket delivers an ordered stream on an established connection. The revision check covers our application state across resync and recovery; it is not a mechanism for repairing individual missing TCP packets.
Incoming edits are applied before the frame's mesh build. The world already tracks local exposure and dirty mesh planes, so a burst of changes can be reflected in the next render without rebuilding the entire mesh after every message callback.
Temporary chat, bounded work
Chat uses the same socket, with a separate message type. The server accepts a short string, removes control characters, trims it to 120 UTF-16 code units, and allows one message per player every two seconds. Clients insert text with textContent, so markup remains text.
The display holds at most four messages, each for 45 seconds. A local mute clears and suppresses the feed. The server doesn't keep chat history, and a joining player doesn't receive earlier messages. Opening the real HTML input releases gameplay controls while remote updates continue to render.
Focusing a field on desktop proves only the HTML path. Whether that focus opens a native keyboard in an embedded host still needs testing on that device. We keep a visible Chat button as well as the controller action.
The rest of the transport has budgets too:
| Boundary |
Current beta limit |
| Client receive queue |
256 queued messages |
| Pending local edits |
32 cells |
| Client outgoing backlog |
Stop sending when bufferedAmount exceeds 8 KiB |
| Server outgoing backlog |
Close a slow client above 64 KiB |
| Client message payload |
4 KiB at the server |
| Reconnect |
Six retries, with increasing delay capped at 15 seconds |
The WebSocket standard defines bufferedAmount as queued application data. Watching it helps keep an unresponsive connection from retaining an ever-growing trail of work. These checks complement, rather than replace, the receive-queue and per-message limits.
Small messages also give compression limited scope to offset its own overhead. We keep perMessageDeflate off; the ws documentation describes its extra CPU and memory costs. That is a starting choice to measure, not a rule for every game.
Recovery and the boundary of the demo
The server pings connections every 15 seconds and removes clients that stop answering. Browser disconnect handling removes old remote actors and retries with backoff. Every new connection has a generation marker, so a late event from an old socket cannot overwrite the replacement connection's state.
The browser resolves both endpoints relative to the game directory. That matters when the demo lives at /space/ inside a larger site. Assets, the directory and WebSocket upgrades must all reach the same service through the HTTPS/WSS proxy.
Our local checks cover shared edits, conflicting requests, late joins, capacity, room expiry, chat isolation, reconnect snapshots and four real browser clients within the 72-slot renderer budget. They do not establish four-player performance or native text entry on the target WebKit hardware.
The next step beyond this POC would be deciding what a shared place promises to keep: ownership, durable saves, recovery tools, and a stronger server movement model. For the beta, the useful question is smaller: can people find one another, build in the same world, and recover cleanly when a connection goes away?
Try the demo, or tell us what worked and what got in your way.