Add debugging to web overlay adapter and controller

- Add detailed logging to getFixtureData and getCompletedMatches
- Log fixture data sample when received
- Remove origin check in onIframeMessage for debugging
- Add logging to sendMessageToOverlay
parent 3532e01a
......@@ -158,20 +158,27 @@
// Get fixture data - returns Promise (async like Qt)
getFixtureData: function() {
return new Promise((resolve) => {
if (fixtureData) {
originalConsoleLog('[WebAdapter] getFixtureData called, current data:', fixtureData ? fixtureData.length + ' fixtures' : 'null');
if (fixtureData && fixtureData.length > 0) {
originalConsoleLog('[WebAdapter] Returning cached fixture data');
resolve(JSON.stringify(fixtureData));
} else {
// Request data from parent
originalConsoleLog('[WebAdapter] Requesting fixture data from parent');
requestFixtureData();
// Wait for response with timeout
let attempts = 0;
const maxAttempts = 100; // 10 seconds
const checkData = setInterval(() => {
attempts++;
if (fixtureData) {
if (fixtureData && fixtureData.length > 0) {
clearInterval(checkData);
originalConsoleLog('[WebAdapter] Fixture data received after', attempts * 100, 'ms');
resolve(JSON.stringify(fixtureData));
} else if (attempts > 50) {
} else if (attempts > maxAttempts) {
clearInterval(checkData);
originalConsoleLog('[WebAdapter] Fixture data timeout, returning empty array');
resolve(JSON.stringify([]));
}
}, 100);
......@@ -212,19 +219,26 @@
// Get completed matches - returns Promise
getCompletedMatches: function() {
return new Promise((resolve) => {
originalConsoleLog('[WebAdapter] getCompletedMatches called, current data:', completedMatches ? completedMatches.length + ' matches' : 'null');
if (completedMatches && completedMatches.length > 0) {
originalConsoleLog('[WebAdapter] Returning cached completed matches');
resolve(JSON.stringify(completedMatches));
} else {
// Request data from parent
originalConsoleLog('[WebAdapter] Requesting completed matches from parent');
requestCompletedMatches();
let attempts = 0;
const maxAttempts = 50;
const checkData = setInterval(() => {
attempts++;
if (completedMatches && completedMatches.length > 0) {
clearInterval(checkData);
originalConsoleLog('[WebAdapter] Completed matches received after', attempts * 100, 'ms');
resolve(JSON.stringify(completedMatches));
} else if (attempts > 50) {
} else if (attempts > maxAttempts) {
clearInterval(checkData);
originalConsoleLog('[WebAdapter] Completed matches timeout, returning empty array');
resolve(JSON.stringify([]));
}
}, 100);
......@@ -298,6 +312,7 @@
case 'fixtureData':
fixtureData = message.fixtures || [];
originalConsoleLog('[WebAdapter] Fixture data updated:', fixtureData.length, 'fixtures');
originalConsoleLog('[WebAdapter] Fixture data sample:', fixtureData.slice(0, 2));
break;
case 'timerState':
......
......@@ -706,7 +706,10 @@ class WebOverlayController {
sendMessageToOverlay(type, data) {
if (this.overlayIframe && this.overlayIframe.contentWindow) {
const message = { type, ...data };
console.log('[OverlayController] Sending message to overlay:', type, data);
this.overlayIframe.contentWindow.postMessage(message, '*');
} else {
console.warn('[OverlayController] Cannot send message - iframe not ready');
}
}
......@@ -715,14 +718,14 @@ class WebOverlayController {
* @param {MessageEvent} event - Message event
*/
async onIframeMessage(event) {
// Security: Only accept messages from same origin
if (event.origin !== window.location.origin) {
const message = event.data;
// Skip if not an object or no type
if (!message || typeof message !== 'object' || !message.type) {
return;
}
const message = event.data;
console.log('[OverlayController] Received iframe message:', message.type || message);
console.log('[OverlayController] Received iframe message:', message.type, 'from origin:', event.origin);
// Handle different message types from iframe
switch (message.type) {
......
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