Please wait. If this message stays more than a few seconds, check if your browser support Javascript and Websockets.
Connection status:
Your connection status is: Connected!
You are waiting for your game master to unlock a puzzle for you. As you play your game, your game master should instruct you when to open this app and start the next puzzle.
You don't have to do anything on your end here yet!
If you see a connection error or are told a puzzle is unlocked, please try refreshing this page.
`; let ws; let synced_data_value = {}; async function websocket(url) { ws = new WebSocket(url); if (!ws) { document.getElementById("connection-status").innerHTML = "Disconnected! Does your browser support Javascript and Websockets?"; } ws.addEventListener("open", () => { console.log('Opened websocket') document.getElementById("connection-status").innerHTML = "Connected!"; pollForPuzzle(); }) ws.addEventListener("message", ({ data }) => { console.log(data); const messageJson = JSON.parse(data); console.log(messageJson); if (messageJson["message"] == "synced_data_value") { console.log("sync attempt"); synced_data_value = messageJson["data"]; } if (messageJson["message"] == "new_status") { console.log("new game is:"); console.log(messageJson["data"]); // The puzzle didn't change, don't change the HTML let nextPuzzle = messageJson["data"]; if (currentPuzzle["puzzle"] == nextPuzzle["puzzle"] && currentPuzzle["reward"] == nextPuzzle["reward"]) { return; } currentPuzzle = messageJson["data"]; if (! currentPuzzle || currentPuzzle["puzzle"] === "waiting" ) { gameApp.innerHTML = waitingHtml; } else { if ([true, "true"].includes(currentPuzzle["reward"])) { gameApp.innerHTML = puzzles[currentPuzzle["puzzle"]]["solution"]; } else { gameApp.innerHTML = puzzles[currentPuzzle["puzzle"]]["puzzle"]; } } } }) ws.addEventListener("close", () => { console.log('Closed websocket') }) } const url = new URL("https://jennatest.gamenightrunner.com") url.protocol = "wss" url.pathname = "/ws" websocket(url) const closeConnection = () => ws.close() const UUID = crypto.randomUUID(); const game = "KRMQS"; let currentPuzzle = ""; const pollForPuzzle = () => { ws.send(JSON.stringify({ "message": "Do we have a puzzle?", "game": game })); console.log("Checking for puzzle"); setTimeout(pollForPuzzle, 10000); }