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