From 8c1b926eb3de7c3b42ede0ddc55bc6d4a7e9f807 Mon Sep 17 00:00:00 2001 From: konsumlamm Date: Fri, 24 May 2024 16:05:44 +0200 Subject: [PATCH] Fix websocket handling --- liberica/src/lib/bindings.ts | 2 +- robusta/src/main.rs | 12 ++++++------ robusta/src/ws_message.rs | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/liberica/src/lib/bindings.ts b/liberica/src/lib/bindings.ts index 6f122c1..2d0e7c2 100644 --- a/liberica/src/lib/bindings.ts +++ b/liberica/src/lib/bindings.ts @@ -5,7 +5,7 @@ */ export type Stop = { name: string; id: string; lat: number; lon: number } -export type ClientResponse = { GameState: GameState } | { MrXGadget: MrXGadget } | { DetectiveGadget: DetectiveGadget } | { MrXPosition: MrXPosition } | "GameStart" | "DetectiveStart" | "GameEnd" +export type ClientResponse = { GameState: GameState } | { MrXGadget: MrXGadget } | { DetectiveGadget: DetectiveGadget } | { MrXPosition: MrXPosition } | { GameStart: null } | { DetectiveStart: null } | { GameEnd: null } export type MrXGadget = { AlternativeFacts: { stop_id: string } } | { Midjourney: { image: number[] } } | "NotFound" | "Teleport" | "Shifter" diff --git a/robusta/src/main.rs b/robusta/src/main.rs index cf6ac8a..a392a22 100644 --- a/robusta/src/main.rs +++ b/robusta/src/main.rs @@ -595,9 +595,9 @@ async fn broadcast(connections: &[ClientConnection], message: ClientResponse) { ClientResponse::MrXPosition(_) => "Mr. X position", ClientResponse::MrXGadget(_) => "Mr. X gadget", ClientResponse::DetectiveGadget(_) => "Detective gadget", - ClientResponse::GameStart => "game start", - ClientResponse::DetectiveStart => "detective start", - ClientResponse::GameEnd => "game end", + ClientResponse::GameStart() => "game start", + ClientResponse::DetectiveStart() => "detective start", + ClientResponse::GameEnd() => "game end", }; error!("failed to send {} to client {}: {}", message_type, connection.id, err); } @@ -625,12 +625,12 @@ impl RunningState { } async fn start_game(connections: &[ClientConnection], running_state: &mut RunningState) { - broadcast(connections, ClientResponse::GameStart).await; + broadcast(connections, ClientResponse::GameStart()).await; running_state.position_cooldown = Some(COOLDOWN); } async fn end_game(connections: &[ClientConnection], running_state: &mut RunningState) { - broadcast(connections, ClientResponse::GameEnd).await; + broadcast(connections, ClientResponse::GameEnd()).await; *running_state = RunningState::new(); } @@ -653,7 +653,7 @@ async fn run_timer_loop(state: SharedState, running_state: Arc