Product selection message handler
This commit is contained in:
@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user