fix(web client): websocket url detection on invite screen

This commit is contained in:
Henri Bourcereau 2026-05-24 16:01:42 +02:00
parent a23147556b
commit 2f40a0a507
5 changed files with 32 additions and 59 deletions

View file

@ -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"

View file

@ -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,

View file

@ -195,12 +195,9 @@ fn IdleCard(
pending_action: RwSignal<Option<PendingLobbyAction>>,
) -> 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)}
</button>
</div>
// Hidden "join by code" fallback
<div style="margin-top:1.25rem;text-align:center">
<button
class="portal-page-btn"
style="font-size:0.75rem;opacity:0.7"
on:click=move |_| join_open.update(|v| *v = !*v)
>
{move || if join_open.get() { "" } else { "" }}
{t!(i18n, join_code_label)}
</button>
{move || {
let cmd = cmd_join.clone();
join_open.get().then(|| view! {
<div style="margin-top:0.75rem;display:flex;gap:0.5rem">
<input
class="login-input"
style="margin:0"
type="text"
placeholder=move || t_string!(i18n, join_code_placeholder)
prop:value=move || join_code.get()
on:input=move |ev| join_code.set(event_target_value(&ev))
/>
<button
class="login-btn login-btn-secondary"
style="margin:0;padding:0 1rem"
disabled=move || join_code.get().is_empty()
on:click=move |_| {
let code = join_code.get();
if auth_username.get_untracked().is_some() {
cmd.unbounded_send(NetCommand::JoinRoom { room: code }).ok();
} else {
pending_action.set(Some(PendingLobbyAction::Join { code }));
}
}
>
{t!(i18n, join_room)}
</button>
</div>
})
}}
</div>
}
}
@ -338,8 +293,6 @@ fn NicknameModal(
{t!(i18n, nickname_modal_or)}
" "
<A href="/account">{t!(i18n, nickname_modal_sign_in)}</A>
" · "
<A href="/account">{t!(i18n, nickname_modal_register)}</A>
</p>
</div>
</div>