Add websocket

parent 897b39c1
......@@ -13,10 +13,9 @@ import os
from pathlib import Path
from typing import Optional, Dict, Any, List
# Suppress Chromium sandbox warnings when running as root - MUST be set before Qt imports
if os.geteuid() == 0: # Running as root
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = '1'
print("Qt WebEngine sandbox disabled for root user")
# Disable Qt WebEngine sandbox to allow localhost fetches - MUST be set before Qt imports
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = '1'
print("Qt WebEngine sandbox disabled for localhost access")
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
......@@ -1890,6 +1889,53 @@ class PlayerWindow(QMainWindow):
except Exception as e:
logger.error(f"Failed to send fixtures data to overlay: {e}")
def _fetch_fixture_data(self):
"""Fetch fixture data using priority order: WebSocket -> API -> QWebChannel"""
try:
logger.info("Fetching fixture data using priority order: WebSocket -> API -> QWebChannel")
# Priority 1: Try WebSocket (if available)
if hasattr(self, 'window_overlay') and self.window_overlay:
overlay_view = self.window_overlay
if hasattr(overlay_view, 'socket') and overlay_view.socket and overlay_view.socket.connected:
logger.info("WebSocket available, requesting fixture data...")
# WebSocket request would be handled asynchronously
# For now, fall through to API
pass
# Priority 2: Try API fetch
try:
import requests
base_url = self._get_web_server_base_url()
api_url = f"{base_url}/api/cashier/pending-matches"
logger.info(f"Fetching fixtures data from API: {api_url}")
response = requests.get(api_url, timeout=10)
if response.status_code == 200:
data = response.json()
if data.get('success') and data.get('matches'):
matches = data['matches']
logger.info(f"Successfully fetched {len(matches)} matches from API")
return {'matches': matches}
else:
logger.warning(f"API returned success=false or no matches: {data}")
else:
logger.error(f"API request failed with status {response.status_code}: {response.text}")
except Exception as api_error:
logger.warning(f"API fetch failed: {api_error}")
# Priority 3: Try QWebChannel (last resort)
logger.info("Falling back to QWebChannel for fixture data")
# QWebChannel communication would happen through the overlay
# For now, return None to indicate no data available
logger.warning("QWebChannel fallback not implemented yet")
return None
except Exception as e:
logger.error(f"Failed to fetch fixture data: {e}")
return None
def _fetch_fixtures_data(self):
"""Fetch fixtures data from the web API"""
try:
......@@ -2513,7 +2559,7 @@ class QtVideoPlayer(QObject):
}
# Fetch and include fixture data if available
fixture_data = self._fetch_fixture_data()
fixture_data = self._fetch_fixtures_data()
if fixture_data:
default_data['fixtures'] = fixture_data.get('matches', [])
logger.info(f"Included {len(default_data['fixtures'])} fixtures in default overlay")
......@@ -3071,7 +3117,7 @@ class QtVideoPlayer(QObject):
# If loading fixtures template, fetch and send fixture data
if load_specific_template == "fixtures.html":
logger.info("Loading fixtures template, fetching fixture data...")
fixture_data = self._fetch_fixture_data()
fixture_data = self._fetch_fixtures_data()
if fixture_data:
# Send fixture data to the overlay
fixture_payload = {'fixtures': fixture_data.get('matches', [])}
......
This diff is collapsed.
......@@ -7,6 +7,7 @@ import time
from datetime import datetime, date
from flask import Blueprint, render_template, request, jsonify, redirect, url_for, flash, session, g
from flask_login import login_required, current_user, login_user, logout_user
from flask_socketio import emit, join_room, leave_room
from werkzeug.security import check_password_hash
from werkzeug.utils import secure_filename
......@@ -5181,3 +5182,4 @@ def upload_intro_video():
except Exception as e:
logger.error(f"API upload intro video error: {e}")
return jsonify({"error": str(e)}), 500
......@@ -20,6 +20,7 @@ bcrypt>=4.0.0
Werkzeug>=2.3.0
Jinja2>=3.1.0
WTForms>=3.0.0
Flask-SocketIO>=5.3.0
# Configuration and environment
python-dotenv>=0.19.0
......
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