Add more messages for joining the game
This commit is contained in:
parent
25c3f66480
commit
c7f2bdfae2
|
@ -5,19 +5,19 @@ const ERUDA = false;
|
|||
const DIV = false;
|
||||
if (ERUDA) eruda.init();
|
||||
const table = document.getElementById(`table`);
|
||||
let username = ``;
|
||||
const socket = new WebSocket(`ws://${window.location.hostname}:8080`);
|
||||
socket.onopen = () => {
|
||||
log('connected!');
|
||||
document.querySelectorAll(`#joinbutton`)[0].addEventListener(`click`, () => {
|
||||
const usernameInput = document.querySelectorAll(`#username`)[0];
|
||||
if (!usernameInput.value) return;
|
||||
username = document.querySelectorAll(`#username`)[0].value;
|
||||
if (!username) return;
|
||||
|
||||
socket.send(JSON.stringify({
|
||||
type: `join`,
|
||||
username: usernameInput.value,
|
||||
username: username,
|
||||
}))
|
||||
hideJoinBar();
|
||||
printMessage(`Joining as ${usernameInput.value}`);
|
||||
printMessage(`Joining as ${username}`);
|
||||
})
|
||||
|
||||
document.querySelectorAll(`#resignbutton`)[0].addEventListener(`click`, () => {
|
||||
|
@ -46,6 +46,20 @@ const handleIncomingWebSocketRequest = (requestRaw) => {
|
|||
printMessage(`Opponent resigned.`);
|
||||
showJoinBar();
|
||||
hideGameBar();
|
||||
break;
|
||||
case `accept`:
|
||||
printMessage(`Joined as ${username}`);
|
||||
hideJoinBar();
|
||||
break;
|
||||
case `reject`:
|
||||
switch (request.reject) {
|
||||
case `username`:
|
||||
printMessage(`The username "${username}" was already taken!`);
|
||||
break;
|
||||
case `already joined`:
|
||||
printMessage(`You've already joined! How did we even get here? Try refreshing the page?`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue