Fix fixtures overlay: Add direct API fallback for standalone web mode

- Added isStandaloneWebMode() function to detect when running without Qt or parent iframe
- Added fetchFixturesFromAPI() function to fetch data directly from /api/overlay/fixtures
- Modified fetchFixturesData() to use direct API call in standalone mode
- Falls back to API when WebChannel is unavailable or times out
- Fixes issue where fixtures overlay showed 'null' data when loaded directly in browser
parent f3fe1492
......@@ -490,11 +490,66 @@
console.log(`🔍 DEBUG [${getTimestamp()}] ${label}${elapsed}`);
}
// Detect if running in standalone web mode (not embedded in iframe with parent)
function isStandaloneWebMode() {
// Check if we're in a browser without Qt and without a parent window that can respond
const isQtEnvironment = typeof qt !== 'undefined' && qt.webChannelTransport;
const hasParent = window.parent !== window;
return !isQtEnvironment && !hasParent;
}
// Fetch fixtures data directly from API (for standalone web mode)
async function fetchFixturesFromAPI() {
debugTime('Fetching fixtures data directly from API (standalone web mode)');
try {
// Determine API base URL
const apiBaseUrl = window.location.origin;
const response = await fetch(`${apiBaseUrl}/api/overlay/fixtures`, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log('DEBUG: API response received:', data);
if (data && Array.isArray(data) && data.length > 0) {
console.log('DEBUG: API returned fixtures data');
fixturesData = data;
renderFixtures();
} else {
console.log('DEBUG: API response did not contain fixtures data');
debugTime('No fixtures data in API response');
showNoMatches('No fixtures available');
}
} catch (error) {
console.log('DEBUG: Failed to fetch from API:', error.message);
debugTime(`API fetch failed: ${error.message}`);
// Show fallback data
showFallbackFixtures();
}
}
// WebChannel fixture data functions
async function fetchFixturesData(retryCount = 0) {
const maxRetries = 10;
const baseDelay = 1000; // 1 second
// Check if running in standalone web mode - use direct API call
if (isStandaloneWebMode()) {
console.log('DEBUG: Standalone web mode detected, fetching directly from API');
await fetchFixturesFromAPI();
return;
}
try {
debugTime('Fetching fixtures data via WebChannel');
......@@ -508,9 +563,10 @@
fetchFixturesData(retryCount + 1);
}, delay);
} else {
console.log('DEBUG: Max retries reached, using fallback data');
console.log('DEBUG: Max retries reached, trying direct API fetch');
debugTime('Max retries reached for WebChannel connection');
showFallbackFixtures();
// Try direct API fetch as fallback
await fetchFixturesFromAPI();
}
return;
}
......@@ -559,10 +615,10 @@
fetchFixturesData(retryCount + 1);
}, delay);
} else {
console.log('DEBUG: Max retries reached, using fallback data');
console.log('DEBUG: Max retries reached, trying direct API fetch');
debugTime('Max retries reached for fixtures data fetch');
// Show fallback data instead of error message
showFallbackFixtures();
// Try direct API fetch as fallback
await fetchFixturesFromAPI();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment