fix: reconnect on ws failure

This commit is contained in:
Evan Carroll 2026-01-18 23:12:24 -06:00
parent 84cb4e5e78
commit 27b3658e1d
5 changed files with 430 additions and 3 deletions

View file

@ -14,8 +14,8 @@ use uuid::Uuid;
use crate::components::{
ActiveBubble, AvatarEditorPopup, Card, ChatInput, ConversationModal, EmotionKeybindings,
FadingMember, InventoryPopup, KeybindingsPopup, MessageLog, NotificationHistoryModal,
NotificationMessage, NotificationToast, RealmHeader, RealmSceneViewer, SettingsPopup,
ViewerSettings,
NotificationMessage, NotificationToast, RealmHeader, RealmSceneViewer, ReconnectionOverlay,
SettingsPopup, ViewerSettings,
};
#[cfg(feature = "hydrate")]
use crate::components::{
@ -118,6 +118,9 @@ pub fn RealmPage() -> impl IntoView {
// Error notification state (for whisper failures, etc.)
let (error_message, set_error_message) = signal(Option::<String>::None);
// Reconnection trigger - increment to force WebSocket reconnection
let (reconnect_trigger, set_reconnect_trigger) = signal(0u32);
let realm_data = LocalResource::new(move || {
let slug = slug.get();
async move {
@ -330,9 +333,10 @@ pub fn RealmPage() -> impl IntoView {
});
#[cfg(feature = "hydrate")]
let (_ws_state, ws_sender) = use_channel_websocket(
let (ws_state, ws_sender) = use_channel_websocket(
slug,
Signal::derive(move || channel_id.get()),
Signal::derive(move || reconnect_trigger.get()),
on_members_update,
on_chat_message,
on_loose_props_sync,
@ -954,6 +958,22 @@ pub fn RealmPage() -> impl IntoView {
/>
}
}
// Reconnection overlay - shown when WebSocket disconnects
{
#[cfg(feature = "hydrate")]
let ws_state_for_overlay = ws_state;
#[cfg(not(feature = "hydrate"))]
let ws_state_for_overlay = Signal::derive(|| crate::components::ws_client::WsState::Disconnected);
view! {
<ReconnectionOverlay
ws_state=ws_state_for_overlay
on_reconnect=Callback::new(move |_: ()| {
set_reconnect_trigger.update(|t| *t += 1);
})
/>
}
}
}
.into_any()
}