diff --git a/app.js b/app.js index 96c2a92..9e3ccca 100644 --- a/app.js +++ b/app.js @@ -20,9 +20,94 @@ const connections = {}; window.openTerminals = {}; let activePeer = null; window.activePeer = null; // Expose to other modules +hideStatusIndicator(); + + +function waitForPeerResponse(expectedMessageFragment, timeout = 900000) { + console.log(`[DEBUG] Waiting for peer response with fragment: "${expectedMessageFragment}"`); + + return new Promise((resolve, reject) => { + const startTime = Date.now(); + + window.handlePeerResponse = (response) => { + console.log(`[DEBUG] Received response: ${JSON.stringify(response)}`); + if (response && response.success && response.message.includes(expectedMessageFragment)) { + console.log(`[DEBUG] Expected response received: ${response.message}`); + resolve(response); + } else if (Date.now() - startTime > timeout) { + console.warn('[WARN] Timeout while waiting for peer response'); + reject(new Error('Timeout waiting for peer response')); + } + }; + + // Timeout fallback + setTimeout(() => { + console.warn('[WARN] Timed out waiting for response'); + reject(new Error('Timed out waiting for peer response')); + }, timeout); + }); +} + + // Initialize the app console.log('[INFO] Client app initialized'); +document.addEventListener('DOMContentLoaded', () => { + const statusIndicator = document.getElementById('status-indicator'); + if (statusIndicator) { + statusIndicator.remove(); + console.log('[INFO] Status indicator removed from DOM on load'); + } +}); +// Show Status Indicator +// Modify showStatusIndicator to recreate it dynamically +function showStatusIndicator(message = 'Processing...') { + const statusIndicator = document.createElement('div'); + statusIndicator.id = 'status-indicator'; + statusIndicator.className = 'position-fixed top-0 start-0 w-100 h-100 d-flex justify-content-center align-items-center bg-dark bg-opacity-75'; + statusIndicator.innerHTML = ` +
${message}
+