Skip to content

Commit

Permalink
Fix websocket handling
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm committed May 24, 2024
1 parent 9de649d commit 8c1b926
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion liberica/src/lib/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 6 additions & 6 deletions robusta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -653,7 +653,7 @@ async fn run_timer_loop(state: SharedState, running_state: Arc<tokio::sync::Mute
let state = state.lock().await;
running_state.position_cooldown = Some(COOLDOWN);
if warmup {
broadcast(&state.connections, ClientResponse::DetectiveStart).await;
broadcast(&state.connections, ClientResponse::DetectiveStart()).await;
warmup = false;
running_state.mr_x_gadgets.allow_use();
running_state.detective_gadgets.allow_use();
Expand Down
6 changes: 3 additions & 3 deletions robusta/src/ws_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub enum ClientResponse {
MrXGadget(MrXGadget),
DetectiveGadget(DetectiveGadget),
MrXPosition(MrXPosition),
GameStart,
DetectiveStart,
GameEnd,
GameStart(),
DetectiveStart(),
GameEnd(),
}

#[derive(specta::Type, Clone, Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 8c1b926

Please sign in to comment.