|
|
|
@ -19,18 +19,25 @@ function displayWord(_word, end, delay) {
|
|
|
|
|
div.scrollTop = div.offsetHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateInput(data) {
|
|
|
|
|
if (data.next_mora !== null) {
|
|
|
|
|
let waiting = data.author === id;
|
|
|
|
|
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}…`;
|
|
|
|
|
input.disabled = waiting;
|
|
|
|
|
if (!waiting) input.focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ws.onmessage = e => {
|
|
|
|
|
const { event, data } = JSON.parse(e.data);
|
|
|
|
|
switch (event) {
|
|
|
|
|
case "greeting":
|
|
|
|
|
id = data.id;
|
|
|
|
|
updateInput(data);
|
|
|
|
|
break;
|
|
|
|
|
case "word":
|
|
|
|
|
let waiting = data.author === id;
|
|
|
|
|
displayWord(data.word, true, 0);
|
|
|
|
|
input.placeholder = waiting ? "Waiting for other players..." : `${data.next_mora}…`;
|
|
|
|
|
input.disabled = waiting;
|
|
|
|
|
if (!waiting) input.focus();
|
|
|
|
|
updateInput(data);
|
|
|
|
|
break;
|
|
|
|
|
case "history":
|
|
|
|
|
console.log(data);
|
|
|
|
|