Foggy Scales — Realtime

Keep the weighing board honest while rain and signal come and go: heartbeats, reconnects, catch-up. 15 levels, right in the browser.

What you learn in this game

A WebSocket connection can die without a word: a phone goes behind a hill, the signal goes, and no packet tells anyone. Both ends still hold a connection that looks open. This is called a half-open connection. In Fog Scale all the code really runs: the board is a Node server with ws, each phone is a Chromium or WebKit page, and each phone's signal goes through a Toxiproxy proxy that can be made silent, cut, or slowed down. What you see after Run is the recording of your combination of choices running.

When a phone connects again, it does not know what happened while it was away. The board knows, if every piece of news has a sequence number: the phone names the last number it got, the board sends what came after. The same number lets the phone refuse news that arrives twice.

With fetch, a token usually goes in the Authorization header. new WebSocket(url, protocols) only takes an address and a list of subprotocols, so the token has to ride somewhere else: a cookie, the address, or the first message after the connection opens. Each place has its own consequence, and this afternoon Mr. Jaya brings one of them.

Eyes cannot read 50 numbers a second, and an old phone cannot draw that fast. A busy realtime page collects the messages and draws once: every 250 milliseconds as in the dashboard lesson, or every frame with requestAnimationFrame. No message is thrown away, they are only drawn together.

Two people edit the same list with no signal, then connect again. There are three ways to merge: keep the whole list and let the newest win (last write wins), send steps with row numbers, or use a CRDT that gives every row a fixed name so the order of arrival does not matter. This afternoon Ms. Anggi uses Yjs 13.6.33 on the tablet, the phone and the board.