@@ -119,7 +119,6 @@ def gen():
119119
120120 return Response (stream_with_context (gen ()), mimetype = 'text/event-stream' )
121121
122-
123122# Endpoint that merges rooms and control status and records a heartbeat
124123@app .route ('/status' , methods = ['GET' ])
125124def status ():
@@ -138,6 +137,9 @@ def status():
138137@app .before_request
139138def log_incoming_request ():
140139 try :
140+ sid = session .get ('session_id' )
141+ if sid :
142+ LAST_SEEN [sid ] = time .time ()
141143 if not request .path in ['/rooms' , '/status' , '/control/status' ]:
142144 logger .info ('Incoming request: %s %s args=%s' , request .method , request .path , dict (request .args ))
143145 except Exception :
@@ -157,7 +159,7 @@ def index():
157159 # maybe this person just reloaded but still has a microphone running
158160 if 'session_id' in session and is_youngest_session ():
159161 mic_idx = session .get ('microphone_index' )
160- logger .info ("Session %s is still active, automatically reconnecting microphone %s." , session .get ('session_id' ), mic_idx )
162+ logger .debug ("Session %s is still active, automatically reconnecting microphone %s." , session .get ('session_id' ), mic_idx )
161163 # only reconnect automatically if we actually have a microphone index in the session
162164 if mic_idx is not None :
163165 automatically_reconnect = True
@@ -183,8 +185,9 @@ def api():
183185 action = request .form .get ('action' )
184186 logger .info (f'Received action: { action } ' )
185187
188+
186189 if action == 'start_webrtc' :
187- # Start per-player webrtc-cli using the provided SDP offer
190+ # Start per-player pulse-receive using the provided SDP offer
188191 offer = request .form .get ('offer' )
189192 if not offer :
190193 return jsonify ({'success' : False , 'error' : 'Missing offer' })
@@ -213,9 +216,6 @@ def api():
213216 'microphone_start_timestamp' : session ['microphone_start_timestamp' ]
214217 }
215218
216- return jsonify ({'success' : True , 'answer' : start_res .get ('answer' ), 'player_id' : player_id })
217-
218-
219219 if action == 'get_assignments' :
220220 return jsonify ({'success' : True , 'assignments' : get_mic_assignments ()})
221221
@@ -301,7 +301,7 @@ def run_xdotool_command(args):
301301 ids = [l .strip () for l in ws .stdout .splitlines () if l .strip ()]
302302 if ids :
303303 ULTRASTAR_WINDOW_ID = ids [0 ]
304- logger .info ('Cached UltraStar window id: %s' , ULTRASTAR_WINDOW_ID )
304+ logger .debug ('Cached UltraStar window id: %s' , ULTRASTAR_WINDOW_ID )
305305 else :
306306 logger .warning ('No UltraStar window found via `xdotool search UltraStar`' )
307307 return False , 'window not found'
@@ -385,7 +385,7 @@ def control_release():
385385 CONTROL_OWNER = None
386386 CONTROL_OWNER_NAME = None
387387 CONTROL_TIMESTAMP = 0
388- logger .info ('Control released by session %s' , sid )
388+ logger .debug ('Control released by session %s' , sid )
389389 return jsonify ({'success' : True })
390390
391391
@@ -1227,6 +1227,20 @@ def stale_cleanup_loop():
12271227 stale = []
12281228 for sid , last in list (LAST_SEEN .items ()):
12291229 if now - last > 10.0 :
1230+ # If this session has an associated microphone process that is still alive,
1231+ # treat the session as active and skip stale removal.
1232+ try :
1233+ mic = mgr .microphones .get (sid )
1234+ if mic :
1235+ try :
1236+ if mic .is_process_alive ():
1237+ logger .debug ('Session %s has active microphone; skipping stale removal' , sid )
1238+ continue
1239+ except Exception :
1240+ # If mic liveness check fails, fall back to treating as stale
1241+ logger .exception ('Error checking mic liveness for session %s' , sid )
1242+ except Exception :
1243+ logger .exception ('Error inspecting microphones for session %s' , sid )
12301244 stale .append (sid )
12311245 for sid in stale :
12321246 try :
0 commit comments