File size: 1,833 Bytes
a31f556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
import sqlite3

from backend.services.usb_monitor import get_db_path
from backend.gaming.capture_engine import capture_engine
from backend.gaming.audio_capture import GameAudioCapture

logger = logging.getLogger(__name__)

class GamingSession:
    def __init__(self):
        # We reuse the global capture engine since it has failsafes built in
        self.screen = capture_engine
        self.audio = GameAudioCapture()
        self.active = False
        self.id = None
        self.game_id = None

    async def start_session(self, game_id: str):
        import uuid
        self.id = uuid.uuid4().hex
        self.game_id = game_id
        
        self.screen.start()
        self.audio.start()
        self.active = True
        
        # Log to SQLite
        try:
            with sqlite3.connect(get_db_path()) as conn:
                conn.execute('PRAGMA journal_mode=WAL')
                conn.execute("INSERT INTO gaming_sessions (id, game_id) VALUES (?, ?)", (self.id, self.game_id))
            logger.info(f"JARVIS 10X: Session {self.id} started for {self.game_id}")
        except Exception as e:
            logger.error(f"Failed to log session start: {e}")

    async def end_session(self):
        if not self.active: return
        self.screen.stop()
        self.audio.stop()
        self.active = False
        
        # Log session end
        try:
            with sqlite3.connect(get_db_path()) as conn:
                conn.execute('PRAGMA journal_mode=WAL')
                conn.execute("UPDATE gaming_sessions SET ended_at = CURRENT_TIMESTAMP WHERE id = ?", (self.id,))
            logger.info(f"JARVIS 10X: Session {self.id} ended")
        except Exception as e:
            logger.error(f"Failed to log session end: {e}")

# Global registry for active sessions
session_registry = {}