Splitting more, added chat, and fancier draw-animations

This commit is contained in:
Kasper Rynning-Tønnesen
2020-03-14 14:04:07 +01:00
parent 35e736a9d9
commit f398db4e42
11 changed files with 688 additions and 196 deletions

25
api/chat.js Normal file
View File

@@ -0,0 +1,25 @@
module.exports = io => {
io.on("connection", socket => {
let username = null;
socket.on("username", msg => {
if (msg.username == null) {
username = null;
socket.emit("accept_username", false);
return;
}
if (msg.username.length > 3 && msg.username.length < 30) {
username = msg.username;
socket.emit("accept_username", true);
return;
}
socket.emit("accept_username", false);
});
socket.on("chat", msg => {
msg.username = username;
msg.timestamp = new Date().getTime();
io.emit("chat", msg);
});
});
};