// how to we communicate... // * in flight // * arrived! (probably) <- this is the tricky one. we know enough time has passed for the message // * received to have been received, but we are only halfway to the earliest possible // * read acknowledgement. // // we know the length of the roundtrip: it is 2x the light lag. progress bars show a passage of time, // it could scroll: // * along the bottom of the message // * across the message // * as it is being sent, a transluscent red bar grows from right to left (towards their messages) // * while we are waiting for acknowledgement, a similar blue bar brows from left to right // * next to the message conversation = [ { c: 1, text: "hows space"}, { c: 0, text: "trying to work out if the coffees shit but"}, { c: 0, text: "my sense of taste is just not happening :/"}, { c: 1, text: "maybe you're being spared"}, { c: 0, text: "ur right"}, { c: 0, text: "ship swill is a delicacy to exactly no one"}, { c: 0, text: "at least the caffeine still works"}, { c: 1, text: "lol"}, { c: 1, text: "you probably got your own stash for later though, right?"}, { c: 1, text: "knowing you"}, { c: 0, text: "oh yea i got some on nimbus"}, { c: 0, text: "donchuu worry"}, { c: 0, text: "how about you?"}, { c: 0, text: "new job soon, right?"}, { c: 1, text: "induction tomorrow wish me luckk"}, { c: 0, text: "break a leg!"}, { c: 1, text: ":)"} ]; sentMessages = [] let messageIdx = -1; let title = "Hester Gomez"; let pings = 0; const startTime = Date.now(); function getMessageList() { return document.getElementById("messages"); } function getMessageElement(messageIdx) { let list = getMessageList(); let messageElements = list.getElementsByTagName("li"); return messageElements[messageIdx]; } class SentMessage { constructor(oneWayLag, idx, onDelivered) { this.oneWayLag = oneWayLag; this.idx = idx; this.createdTime = Date.now(); this.onDelivered = onDelivered; this.updateBarIntervalId = setInterval(() => { let elapsed = Math.abs(Date.now() - this.createdTime) / 1000; let progress = elapsed / this.oneWayLag; // divide in half to measure the round trip progress /= 2; this.setProgress(progress); }, 10); } setProgress(amount) { let thisMessage = getMessageElement(this.idx); let progressBar = thisMessage.getElementsByClassName("progress")[0]; if (amount < 0.5) { const color = "var(--light-red)"; this.updateStatus("in flight", color); progressBar.style.backgroundColor = color; amount *= 2; } else if (amount < 1) { const color = "var(--robin-egg-blue)"; this.updateStatus("completing round trip", color); progressBar.style.backgroundColor = color; amount -= 0.5; amount *= 2; } else { const color = "var(--eggshell)"; this.updateStatus("delivered", color); progressBar.style.backgroundColor = color; clearInterval(this.updateBarIntervalId); amount = 0; this.onDelivered(); } amount = Math.min(amount, 1); let percentage = `${amount * 100}%`; progressBar.style.width = percentage; } updateStatus(newStatus, color) { let thisMessage = getMessageElement(this.idx); let statusElement = thisMessage.getElementsByClassName("message-status")[0]; statusElement.innerHTML = newStatus; statusElement.style.color = color; } } function updateTextBox(message) { document.getElementById("textbox-input").value = message; } function setTypingIndicator(isTyping) { document.getElementById("typing-indicator").innerHTML = isTyping ? "Hester is typing..." : ""; } // add the message at the index to the displayed messages function addMessage(idx) { let message = conversation[idx]; let messageHtml = getMessageHtml(message.text, isMessageOurs(message)); getMessageList().innerHTML += messageHtml; // scroll as far as we can so that messages aren't hidden window.scrollTo(0, document.body.scrollHeight); } function getMessageHtml(text, isOurs) { let owner = isOurs ? "ours" : "theirs"; // we don't want loading bars on their messages, since we have no idea if one has been sent // until it arrives let progressBar = isOurs ? `
` : ""; let statusText = isOurs ? ` ` : ""; let message = `