Fix autologin when connection restored
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
let connection = null;
|
||||
let triggerSystem: TriggerSystem;
|
||||
let accessibilityManager: AccessibilityManager;
|
||||
let awaitingSessionResumed = false;
|
||||
|
||||
// Speech control
|
||||
function handleKeyDown(event: KeyboardEvent): void {
|
||||
@@ -281,6 +282,33 @@
|
||||
addToOutputHistory(`Connected to ${profile?.host}:${profile?.port}`);
|
||||
}
|
||||
|
||||
// Check if we're reconnecting to an existing session
|
||||
const hasStoredSession = connection && connection.getSessionId();
|
||||
if (hasStoredSession) {
|
||||
console.log(`Connection has existing session ID, waiting for session_resumed event before autologin`);
|
||||
awaitingSessionResumed = true;
|
||||
|
||||
// Set a timeout in case session_resumed event doesn't come
|
||||
setTimeout(() => {
|
||||
if (awaitingSessionResumed) {
|
||||
console.log('Timeout waiting for session_resumed, proceeding with autologin');
|
||||
awaitingSessionResumed = false;
|
||||
performAutoLogin(profile);
|
||||
}
|
||||
}, 5000); // 5 second timeout
|
||||
} else {
|
||||
// Fresh connection, proceed with autologin immediately
|
||||
console.log('Fresh connection, proceeding with autologin');
|
||||
performAutoLogin(profile);
|
||||
}
|
||||
|
||||
dispatch('connected');
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform auto-login if enabled
|
||||
*/
|
||||
function performAutoLogin(profile) {
|
||||
// Handle auto-login if enabled
|
||||
if (profile?.autoLogin?.enabled) {
|
||||
setTimeout(() => {
|
||||
@@ -308,8 +336,6 @@
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
dispatch('connected');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,6 +484,12 @@
|
||||
function handleSessionResumed(data) {
|
||||
console.log(`Session resumed for ${profileId}:`, data);
|
||||
|
||||
// We successfully resumed a session, so don't perform autologin
|
||||
if (awaitingSessionResumed) {
|
||||
console.log('Session resumed successfully, skipping autologin');
|
||||
awaitingSessionResumed = false;
|
||||
}
|
||||
|
||||
if (data.messagesReplayed > 0) {
|
||||
// Add a system message to the output to notify the user
|
||||
addToOutputHistory(`[SYSTEM] Reconnected to MUD. ${data.messagesReplayed} messages have been replayed.`, false);
|
||||
|
||||
Reference in New Issue
Block a user