From 2f40a0a507f9912ff6ebc3d70a01129d039388dc Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Sun, 24 May 2026 16:01:42 +0200 Subject: [PATCH] fix(web client): websocket url detection on invite screen --- clients/web/locales/fr.json | 4 +-- clients/web/src/app.rs | 25 ++++++++++++++---- clients/web/src/portal/lobby.rs | 47 --------------------------------- devenv.lock | 11 +++++--- justfile | 4 +++ 5 files changed, 32 insertions(+), 59 deletions(-) diff --git a/clients/web/locales/fr.json b/clients/web/locales/fr.json index 569d66b..d429838 100644 --- a/clients/web/locales/fr.json +++ b/clients/web/locales/fr.json @@ -130,14 +130,12 @@ "copy_link": "Copier le lien", "link_copied": "Copié !", "scan_qr": "ou scannez le QR code", - "join_code_label": "Rejoindre avec un code", - "join_code_placeholder": "Code de la salle", "share_btn": "Partager", "nickname_modal_title": "Choisissez votre pseudo", "nickname_modal_hint": "Vous jouerez sous le nom de :", "nickname_modal_play": "Jouer", "nickname_modal_or": "ou", - "nickname_modal_sign_in": "Se connecter", + "nickname_modal_sign_in": "connectez-vous", "nickname_modal_register": "Créer un compte", "new_game": "Nouvelle partie", "language": "Langue" diff --git a/clients/web/src/app.rs b/clients/web/src/app.rs index 5c38d33..6cfaa54 100644 --- a/clients/web/src/app.rs +++ b/clients/web/src/app.rs @@ -29,7 +29,22 @@ use trictrac_store::CheckerMove; use std::collections::VecDeque; -const RELAY_URL: &str = "ws://localhost:8080/ws"; +fn relay_url() -> String { + #[cfg(debug_assertions)] + { + "ws://localhost:8080/ws".to_string() + } + #[cfg(not(debug_assertions))] + { + let location = web_sys::window() + .and_then(|w| Some(w.location())) + .unwrap(); + let protocol = location.protocol().unwrap_or_default(); + let host = location.host().unwrap_or_default(); + let ws_protocol = if protocol == "https:" { "wss" } else { "ws" }; + format!("{ws_protocol}://{host}/ws") + } +} const GAME_ID: &str = "trictrac"; const STORAGE_KEY: &str = "trictrac_session"; const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -205,7 +220,7 @@ pub fn App() -> impl IntoView { Some(NetCommand::CreateRoom { room }) => { break Some(( RoomConfig { - relay_url: RELAY_URL.to_string(), + relay_url: relay_url(), game_id: GAME_ID.to_string(), room_id: room, rule_variation: 0, @@ -219,7 +234,7 @@ pub fn App() -> impl IntoView { Some(NetCommand::JoinRoom { room }) => { break Some(( RoomConfig { - relay_url: RELAY_URL.to_string(), + relay_url: relay_url(), game_id: GAME_ID.to_string(), room_id: room, rule_variation: 0, @@ -304,7 +319,7 @@ pub fn App() -> impl IntoView { if !session.is_host { save_session(&StoredSession { - relay_url: RELAY_URL.to_string(), + relay_url: relay_url(), game_id: GAME_ID.to_string(), room_id: room_id_for_storage.clone(), token: session.reconnect_token, @@ -358,7 +373,7 @@ pub fn App() -> impl IntoView { if is_host { save_session(&StoredSession { - relay_url: RELAY_URL.to_string(), + relay_url: relay_url(), game_id: GAME_ID.to_string(), room_id: room_id_for_storage.clone(), token: reconnect_token, diff --git a/clients/web/src/portal/lobby.rs b/clients/web/src/portal/lobby.rs index c3dbf24..686dac7 100644 --- a/clients/web/src/portal/lobby.rs +++ b/clients/web/src/portal/lobby.rs @@ -195,12 +195,9 @@ fn IdleCard( pending_action: RwSignal>, ) -> impl IntoView { let i18n = use_i18n(); - let join_open = RwSignal::new(false); - let join_code = RwSignal::new(String::new()); let cmd_bot = cmd_tx.clone(); let cmd_create = cmd_tx.clone(); - let cmd_join = cmd_tx; let on_create = move |_: leptos::ev::MouseEvent| { let code = generate_room_code(); @@ -232,48 +229,6 @@ fn IdleCard( {t!(i18n, create_room)} - - // Hidden "join by code" fallback -
- - {move || { - let cmd = cmd_join.clone(); - join_open.get().then(|| view! { -
- - -
- }) - }} -
} } @@ -338,8 +293,6 @@ fn NicknameModal( {t!(i18n, nickname_modal_or)} " " {t!(i18n, nickname_modal_sign_in)} - " · " - {t!(i18n, nickname_modal_register)}

diff --git a/devenv.lock b/devenv.lock index 991fcf7..e6e8ef6 100644 --- a/devenv.lock +++ b/devenv.lock @@ -3,10 +3,11 @@ "devenv": { "locked": { "dir": "src/modules", - "lastModified": 1776863933, + "lastModified": 1779486363, + "narHash": "sha256-6rNmvwTngbmz/j3DGsEYkyakrHHY8N5wgRD9k35HyuM=", "owner": "cachix", "repo": "devenv", - "rev": "863b4204725efaeeb73811e376f928232b720646", + "rev": "90692720b2ad7a7811204155900bf6bea3a3b420", "type": "github" }, "original": { @@ -18,10 +19,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1776734388, + "lastModified": 1779102034, + "narHash": "sha256-vZJZjLo513IeI8hjzHFc6TDezUd4uCE2Eq4SNO3DNNg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "10e7ad5bbcb421fe07e3a4ad53a634b0cd57ffac", + "rev": "687f05a9184cad4eaf905c48b63649e3a86f5433", "type": "github" }, "original": { @@ -34,6 +36,7 @@ "nixpkgs-cmake3": { "locked": { "lastModified": 1758213207, + "narHash": "sha256-rqoqF0LEi+6ZT59tr+hTQlxVwrzQsET01U4uUdmqRtM=", "owner": "NixOS", "repo": "nixpkgs", "rev": "f4b140d5b253f5e2a1ff4e5506edbf8267724bde", diff --git a/justfile b/justfile index 1ac30e4..bc78103 100644 --- a/justfile +++ b/justfile @@ -55,6 +55,10 @@ build-relay: cp target/release/relay-server deploy cp -u server/relay-server/GameConfig.json deploy/ +# generate web stats report from the current nginx logs +stats: + ssh -t raspberry sudo goaccess /var/log/nginx/trictrac_access.log --log-format=COMBINED -o html > var/stats/report.html + # start a trictrac container with nixos-container # `boot.enableContainers = true` must be set on local nixos system local: