Fix overlay web adapter: Add standalone mode API fallback

- Added isStandaloneMode detection (window.parent === window)
- getFixtureData() now fetches directly from /api/overlay/fixtures in standalone mode
- getCompletedMatches() now fetches directly from /api/overlay/completed-matches in standalone mode
- getWinningOutcomes() now fetches directly from /api/overlay/winning-outcomes in standalone mode
- Prevents timeout waiting for parent window response when no parent exists
parent 975881f2
...@@ -109,6 +109,12 @@ ...@@ -109,6 +109,12 @@
// Web environment - set up postMessage bridge // Web environment - set up postMessage bridge
originalConsoleLog('[WebAdapter] Setting up postMessage bridge for web environment'); originalConsoleLog('[WebAdapter] Setting up postMessage bridge for web environment');
// Check if we're in standalone mode (no parent window to respond)
const isStandaloneMode = window.parent === window;
if (isStandaloneMode) {
originalConsoleLog('[WebAdapter] Standalone mode detected - no parent window, will use direct API calls');
}
// Data storage // Data storage
let fixtureData = null; let fixtureData = null;
let timerState = { running: false, remaining_seconds: 0 }; let timerState = { running: false, remaining_seconds: 0 };
...@@ -157,12 +163,39 @@ ...@@ -157,12 +163,39 @@
// Get fixture data - returns Promise (async like Qt) // Get fixture data - returns Promise (async like Qt)
getFixtureData: function() { getFixtureData: function() {
return new Promise((resolve) => { return new Promise(async (resolve) => {
originalConsoleLog('[WebAdapter] getFixtureData called, current data:', fixtureData ? fixtureData.length + ' fixtures' : 'null'); originalConsoleLog('[WebAdapter] getFixtureData called, current data:', fixtureData ? fixtureData.length + ' fixtures' : 'null');
if (fixtureData && fixtureData.length > 0) { if (fixtureData && fixtureData.length > 0) {
originalConsoleLog('[WebAdapter] Returning cached fixture data'); originalConsoleLog('[WebAdapter] Returning cached fixture data');
resolve(JSON.stringify(fixtureData)); resolve(JSON.stringify(fixtureData));
} else if (isStandaloneMode) {
// Standalone mode - fetch directly from API
originalConsoleLog('[WebAdapter] Standalone mode - fetching fixture data directly from API');
try {
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) {
const data = await response.json();
originalConsoleLog('[WebAdapter] API returned fixture data:', data ? data.length : 0, 'fixtures');
fixtureData = data || [];
resolve(JSON.stringify(fixtureData));
} else {
originalConsoleLog('[WebAdapter] API request failed:', response.status, response.statusText);
resolve(JSON.stringify([]));
}
} catch (error) {
originalConsoleLog('[WebAdapter] API fetch error:', error.message);
resolve(JSON.stringify([]));
}
} else { } else {
// Request data from parent // Request data from parent
originalConsoleLog('[WebAdapter] Requesting fixture data from parent'); originalConsoleLog('[WebAdapter] Requesting fixture data from parent');
...@@ -218,12 +251,39 @@ ...@@ -218,12 +251,39 @@
// Get completed matches - returns Promise // Get completed matches - returns Promise
getCompletedMatches: function() { getCompletedMatches: function() {
return new Promise((resolve) => { return new Promise(async (resolve) => {
originalConsoleLog('[WebAdapter] getCompletedMatches called, current data:', completedMatches ? completedMatches.length + ' matches' : 'null'); originalConsoleLog('[WebAdapter] getCompletedMatches called, current data:', completedMatches ? completedMatches.length + ' matches' : 'null');
if (completedMatches && completedMatches.length > 0) { if (completedMatches && completedMatches.length > 0) {
originalConsoleLog('[WebAdapter] Returning cached completed matches'); originalConsoleLog('[WebAdapter] Returning cached completed matches');
resolve(JSON.stringify(completedMatches)); resolve(JSON.stringify(completedMatches));
} else if (isStandaloneMode) {
// Standalone mode - fetch directly from API
originalConsoleLog('[WebAdapter] Standalone mode - fetching completed matches directly from API');
try {
const apiBaseUrl = window.location.origin;
const response = await fetch(`${apiBaseUrl}/api/overlay/completed-matches`, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
originalConsoleLog('[WebAdapter] API returned completed matches:', data ? data.length : 0, 'matches');
completedMatches = data || [];
resolve(JSON.stringify(completedMatches));
} else {
originalConsoleLog('[WebAdapter] API request failed:', response.status, response.statusText);
resolve(JSON.stringify([]));
}
} catch (error) {
originalConsoleLog('[WebAdapter] API fetch error:', error.message);
resolve(JSON.stringify([]));
}
} else { } else {
// Request data from parent // Request data from parent
originalConsoleLog('[WebAdapter] Requesting completed matches from parent'); originalConsoleLog('[WebAdapter] Requesting completed matches from parent');
...@@ -248,7 +308,34 @@ ...@@ -248,7 +308,34 @@
// Get winning outcomes - returns Promise // Get winning outcomes - returns Promise
getWinningOutcomes: function(matchId) { getWinningOutcomes: function(matchId) {
return new Promise((resolve) => { return new Promise(async (resolve) => {
if (isStandaloneMode) {
// Standalone mode - fetch directly from API
originalConsoleLog('[WebAdapter] Standalone mode - fetching winning outcomes from API for match:', matchId);
try {
const apiBaseUrl = window.location.origin;
const response = await fetch(`${apiBaseUrl}/api/overlay/winning-outcomes/${matchId}`, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
originalConsoleLog('[WebAdapter] API returned winning outcomes:', data ? data.length : 0, 'outcomes');
resolve(JSON.stringify(data || []));
} else {
originalConsoleLog('[WebAdapter] API request failed:', response.status, response.statusText);
resolve(JSON.stringify([]));
}
} catch (error) {
originalConsoleLog('[WebAdapter] API fetch error:', error.message);
resolve(JSON.stringify([]));
}
} else {
// Request data from parent // Request data from parent
requestWinningOutcomes(matchId); requestWinningOutcomes(matchId);
let attempts = 0; let attempts = 0;
...@@ -262,6 +349,7 @@ ...@@ -262,6 +349,7 @@
resolve(JSON.stringify([])); resolve(JSON.stringify([]));
} }
}, 100); }, 100);
}
}); });
} }
}; };
......
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