Skip to content

Commit 47b3791

Browse files
authored
fix: game js dynamic ws endpoint call return
1 parent 88b99f3 commit 47b3791

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

data/game.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ canvas.addEventListener("touchstart", (e) => {
517517

518518

519519
function setupWebSocket() {
520-
// ws = new WebSocket("ws://" + location.hostname + "/ws");
521-
ws = new WebSocket("ws://192.168.4.1/ws");
520+
ws = new WebSocket("ws://" + location.hostname + "/ws");
521+
// ws = new WebSocket("ws://192.168.4.1/ws");
522522

523523
ws.onmessage = (event) => {
524524
const data = JSON.parse(event.data);

data/game.js.bak

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,27 @@ async function getMotivationalQuote() {
5959
const local = await fetch("/quote");
6060
if (local.ok) {
6161
const data = await local.json();
62-
quoteText = data.content || fallbackQuotes[0].text;
63-
quoteAuthor = data.author || fallbackQuotes[0].author;
64-
return;
62+
63+
// case 1: single quote object
64+
if (data.content && data.author) {
65+
quoteText = data.content;
66+
quoteAuthor = data.author;
67+
return;
68+
}
69+
70+
// case 2: array of quote objects
71+
if (Array.isArray(data) && data.length > 0) {
72+
const random = data[Math.floor(Math.random() * data.length)];
73+
if (random.content && random.author) {
74+
quoteText = random.content;
75+
quoteAuthor = random.author;
76+
return;
77+
}
78+
}
6579
}
66-
} catch (_) {}
80+
} catch (err) {
81+
console.warn("[Quote] Local ESP fetch failed:", err);
82+
}
6783

6884
// 3. else local code
6985
const fallback = fallbackQuotes[Math.floor(Math.random() * fallbackQuotes.length)];

0 commit comments

Comments
 (0)