Bash.tv → GitHub → itch.io

Let people watch multiplayer matches. Spectators joining by room code without taking a seat, a delay buffer so watchers can't feed live positions to players, a spectator view that hides secret information, a camera that follows a player, cycles between players, pans freely or fits everyone, spectator UI (names, scores, who is followed), and streaming-friendly views. Tested module, built into th...

Download skill (.zip) Files on GitHub

Spectator mode

Server side (assets/spectate.js)

import { createDelayBuffer, spectatorView } from "./spectate.js";
const delayed = createDelayBuffer(3000);       // 3 s behind: enough to stop "he's behind the wall!" calls
each send tick:
  delayed.push(Date.now(), spectatorView(snapshot, { hiddenFields: ["hand", "role"] }));
  const late = delayed.take(Date.now()); if (late) for (const s of spectators) s.send(late);

Camera (client)

import { createSpectatorCamera } from "./spectate.js";
const cam = createSpectatorCamera({ width: 960, height: 540 });
each frame: cam.update(dt, ents); ctx.save(); cam.apply(ctx); drawWorld(); ctx.restore();
Tab / tap a name: cam.next();   Shift+Tab: cam.prev();   drag: cam.pan(dx, dy);   O: cam.mode = "overview"

Modes: follow (a player; picks the first when none is chosen), free (drag to pan), overview (fits all players with a zoom limit).

UI

Tested

Node tests: delay buffer returns the newest item at least the delay old and drops older ones; hidden fields removed; follow, cycle and overview camera. With real sockets: the spectator receives snapshots about 500 ms late (test setting).

Pitfalls

Sending spectators the players’ private data, spectators counted as players, no delay in competitive games, and a camera that jumps (it eases here).