Compare commits

..

4 Commits

Author SHA1 Message Date
lamp 840490b362 ip as default nick 2022-01-17 22:30:17 -06:00
lamp 7c8741eb62 🤦‍♂️ 2022-01-17 22:28:52 -06:00
lamp e99fa4cbab fix 2022-01-13 22:27:50 -06:00
lamp d2e24df6f4 Update 'readme.md' 2021-12-03 15:52:11 -06:00
2 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -2,4 +2,4 @@ The frontend was stolen from [DayDun](https://daydun.com/piano/) and the backend
The notable thing about this and DayDun's piano is that note events are simply, individually, immediately broadcasted in a minimal binary format, and clients _instantly_ play notes they receive; unlike Brandon Lockaby's Multiplayer Piano which buffers note events with timing data into JSON that's sent every 200ms and then played exactly _one second_ after they actually happened. (PianoRhythm does something similar.) Doing this preserves the exact note timing regardless of networking quality (unless it takes longer than a second for the data to get through), which is fine for listening to other players, but a problem when playing together. With this piano, notes go directly through as fast as possible, which is perfect for local networks, and reveals the true networking quality and latency over the internet.
It's also super simple to run if you do want to use it on your local network; just download, `npm install`, `node index.js` and connect to it (default port is 924).
It's also super simple to run if you do want to use it on your local network; just download, `npm install`, `node server.js` and connect to it (default port is 924).
+4 -4
View File
@@ -23,17 +23,17 @@ wss.on("connection", (ws, req) => {
function broadcastChat(message) {
broadcast({type: "chat", message});
chatlog.push(message);
if (chatlog.length >= 100) chatlog.unshift();
if (chatlog.length >= 100) chatlog.shift();
}
ws.user = {
uid: req.ip,
nick: req.query.nick || "potato-chan",
color: [Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255)]
nick: req.query.nick || req.ip,
color: [Math.floor(Math.random()*256),Math.floor(Math.random()*256),Math.floor(Math.random()*256)]
}
let t = Array.from(wss.clients).map(ws => ws.user.id);
for (let i = 0; i < 256; i++) if (!t.includes(i)) { ws.user.id = i; break; }
if (!ws.user.id) return ws.close();
if (ws.user.id == null) return ws.close();
console.log("join", ws.user);