Host-authoritative by design
One browser owns the truth. The CEO’s browser already runs the full simulation for a solo night, so in a live room it simply keeps doing that and becomes the host:- Host (CEO) runs
GameState, applies every action, and broadcasts the result. - Guests and the DJ send intents only: “I want to buy 2 TSLA”, “here is my mix”. They never edit state.
- Relay routes frames between them. It has no game logic, no database, and does not parse payloads.
The wire: a 3-byte header
Every game message is a binary WebSocket frame with a fixed 3-byte header followed by an opaque payload.
Entering and leaving a room uses a handful of small JSON text messages:
create, join, resume, kick, close
from clients, and created, joined, peer, host, kicked, closed, error from the relay.
Signed-in players only. Live clubs need a signed-in account: before opening a socket, a client gets a pass from
the api that vouches for the player, and the relay refuses create, join or resume without one (the player sees a
sign-in error). That pass also lets the relay apply its limits and kicks to a player’s account.
A snapshot is the public club state serialized to JSON and gzipped with the browser’s built-in CompressionStream
(no library). A busy night is about 100 KB of JSON and 10–15 KB on the wire. The host sends one at most every
250 ms, coalescing every action in between.
Room lifecycle
- Room codes are 6 characters from a 31-symbol alphabet that leaves out look-alikes (0, O, 1, I, L), drawn with a cryptographic RNG: possible codes.
- The host token is a secret that makes a browser the host.
- Guests are admitted at night. A
helloduring the day waits until the club opens. - One DJ at a time. A second DJ is turned away until the decks are free.
DJ sync: state, not audio
Streaming a DJ set to every guest would cost each listener an audio stream. NYXERON sends the mix instead: every browser already has the same track crate, so the DJ only needs to say what the decks are doing. Four times a second the DJ’s browser sends aMixSync: for each deck the track id, play state, playhead, tempo,
reverse flag, loop, and the channel’s EQ, filter and fader settings, plus the crossfader. One-shot moves (pads,
brake, backspin) travel as separate events the moment they happen. The host relays both to the whole room as reliable
events, and every browser plays the set on its own Web Audio engine.
Bandwidth
where
So . A modest
128 kbit/s audio stream would be about 13 times more, per listener, and would add encoding delay on top. For a room
with listeners the relay sends roughly , so even a room of 50 listeners stays near
60 kB/s of mix traffic.
Staying on the beat
The mix arrives a little late, so each follower aims slightly ahead of where the DJ was when the message was sent, and only jumps when it is clearly off: a small drift is inaudible, a seek is not. where
Play, pause, track loads, tempo, loops and EQ are applied immediately; only the playhead uses the tolerance. A track
that is still loading is never loaded twice, and a track a listener does not have simply stays silent on that deck.
Worked example
Worked example
The DJ’s deck A is playing forward at tempo and reports s.A listener whose deck is at s is off by s, below
s: it keeps playing untouched. A listener at s is off by s and seeks to
62.6248 s.
Reconnects
Phones lose signal and laptops sleep; a live club has to survive that. Backoff. After a drop, a client waits with exponential backoff and equal jitter, so a relay restart is not hit by every player at the same instant: so the first wait falls in s and the waits settle in s. The counter resets only after a connection has held for more than 10 s, so a server that accepts and immediately drops can’t make clients spin. A client stops for good when it is kicked, its room is closed or gone, or another tab takes the room over (replaced).
Guests and DJs get a new peer id on every reconnect, so the seat is tied to something else: a secret key chosen
for that night. The host holds a disconnected guest’s seat for 60 seconds; when the guest’s hello comes back with
the same key, the host binds the old seat, with everything in it, to the new id.
The host reconnects with resume and its secret token. A room only comes back to the account that opened it. Peers are told host off and then host on; the relay
re-announces every peer still in the room and they send hello again. If the host stays away longer than the
60-second grace period the room closes, but the same code can be resumed for up to an hour, so invite links and
scheduled events keep working.