summaryrefslogtreecommitdiffstats
path: root/web/play/src/crash.ts
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-08 03:32:24 +0100
committersalmonik <salmonik@tuta.io>2026-11-08 03:32:24 +0100
commitfda24c47a8262388ada92722850a362da65aaa6e (patch)
tree13363fa1461ae4e10087acba562a527b8bde4228 /web/play/src/crash.ts
parentv5.0.0: protocol v5 and the browser frontend (diff)
downloadzagan-bet-fda24c47a8262388ada92722850a362da65aaa6e.tar.gz
zagan-bet-fda24c47a8262388ada92722850a362da65aaa6e.zip
web: accept the serialized reels array and stop game loops on navigation
The Rust SlotsView serializes reels as an array of chars, so the browser joins it instead of String(array). The crash chart, reel animation and roulette observer now stop when another screen takes over, and a returning crash screen rebuilds its detached canvas. Action buttons ignore a double click before the server view arrives. Also tightens the gateway session registry with a generation token, caps WebSocket messages at 64 KiB, uses the __Host- cookie prefix on HTTPS, and ships the systemd unit.
Diffstat (limited to '')
-rw-r--r--web/play/src/crash.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/web/play/src/crash.ts b/web/play/src/crash.ts
index 6f3c8dd..a683dcd 100644
--- a/web/play/src/crash.ts
+++ b/web/play/src/crash.ts
@@ -31,6 +31,7 @@ let sendCommand: ((command: unknown) => void) | null = null;
31let frameHandle: number | undefined; 31let frameHandle: number | undefined;
32let verifyToken = 0; 32let verifyToken = 0;
33let lastStatus = ""; 33let lastStatus = "";
34let lastAction = 0;
34 35
35function build( 36function build(
36 board: HTMLElement, 37 board: HTMLElement,
@@ -88,6 +89,8 @@ function build(
88 const primary = node("button", "btn primary wide big", "START") as HTMLButtonElement; 89 const primary = node("button", "btn primary wide big", "START") as HTMLButtonElement;
89 const leave = node("button", "btn ghost wide", "Leave table") as HTMLButtonElement; 90 const leave = node("button", "btn ghost wide", "Leave table") as HTMLButtonElement;
90 primary.addEventListener("click", () => { 91 primary.addEventListener("click", () => {
92 if (Date.now() - lastAction < 500) return;
93 lastAction = Date.now();
91 if (current?.status === "running") sendCommand?.("CashOut"); 94 if (current?.status === "running") sendCommand?.("CashOut");
92 else sendCommand?.("Start"); 95 else sendCommand?.("Start");
93 }); 96 });
@@ -118,6 +121,15 @@ function build(
118 }; 121 };
119} 122}
120 123
124/// Stop the chart loop when another screen takes over.
125export function stopCrashAnimation(): void {
126 if (frameHandle !== undefined) {
127 cancelAnimationFrame(frameHandle);
128 frameHandle = undefined;
129 }
130 current = null;
131}
132
121export function renderCrash( 133export function renderCrash(
122 board: HTMLElement, 134 board: HTMLElement,
123 side: HTMLElement, 135 side: HTMLElement,
@@ -125,7 +137,7 @@ export function renderCrash(
125 send: (command: unknown) => void, 137 send: (command: unknown) => void,
126 now: Clock, 138 now: Clock,
127): void { 139): void {
128 if (!parts || parts.board !== board) { 140 if (!parts || parts.board !== board || !parts.canvas.isConnected) {
129 parts = build(board, side, send, now); 141 parts = build(board, side, send, now);
130 lastStatus = ""; 142 lastStatus = "";
131 } 143 }