Product selection message handler

This commit is contained in:
Eden Kirin
2023-05-11 15:08:24 +02:00
parent 69e087c0c9
commit 9151aa3e1e
8 changed files with 113 additions and 89 deletions

View File

@ -2,6 +2,8 @@ if (typeof FAIRHOPPER_WS_SERVER === "undefined") {
var FAIRHOPPER_WS_SERVER = "ws://127.0.0.1:8011";
}
let ws = null;
const BOARD_ICONS = {
PLAYER: "😀",
PLAYER_ON_DESTINATION: "😎",
@ -146,7 +148,7 @@ function productPurchaseDone(product) {
function wsConnect() {
console.log("Attempting to connect to", FAIRHOPPER_WS_SERVER);
let ws = new WebSocket(FAIRHOPPER_WS_SERVER);
ws = new WebSocket(FAIRHOPPER_WS_SERVER);
ws.onopen = () => {
console.log("WS connected");
@ -178,6 +180,7 @@ function wsConnect() {
};
ws.onclose = (e) => {
ws = null;
setTimeout(() => {
wsConnect();
}, 1000);
@ -189,6 +192,21 @@ function wsConnect() {
};
}
function finishProductSelection() {
if (!ws) {
return;
}
const wsMessage = {
message: "product_selection_done",
data: null,
};
ws.send(JSON.stringify(wsMessage));
}
window.onload = () => {
document.getElementById("finish-product-selection").onclick = () => {
finishProductSelection();
};
wsConnect();
};