Include next mora in greeting event

master
Elnu 2 years ago
parent 53fb1f3c4e
commit f157c847bb

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

@ -26,6 +26,7 @@ impl MessageResponse {
enum MessageResponseData { enum MessageResponseData {
Greeting { Greeting {
id: u64, id: u64,
next_mora: Option<String>,
}, },
Word { Word {
author: u64, author: u64,
@ -165,7 +166,8 @@ impl Server {
fn handle_connection(&mut self, client_id: u64, responder: Responder) -> Result<(), ServerError> { fn handle_connection(&mut self, client_id: u64, responder: Responder) -> Result<(), ServerError> {
println!("A client connected with id #{}", client_id); println!("A client connected with id #{}", client_id);
responder.send(MessageResponseData::Greeting { responder.send(MessageResponseData::Greeting {
id: client_id id: client_id,
next_mora: self.next_mora.clone(),
}.into_message()); }.into_message());
responder.send(MessageResponseData::History { responder.send(MessageResponseData::History {
words: self.database.load_words_before(self.database.last_word_id + 1)? words: self.database.load_words_before(self.database.last_word_id + 1)?

Loading…
Cancel
Save