Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1229,6 +1229,13 @@ def stream_engine_thread_target(chat_id: int):
|
|
| 1229 |
session['streaming_state'] = "streaming"
|
| 1230 |
if old_st != "streaming":
|
| 1231 |
threading.Thread(target=notify_state_change, args=(chat_id, "streaming"), daemon=True).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1232 |
|
| 1233 |
# --- Packet loop ---
|
| 1234 |
last_read_time = time.time()
|
|
@@ -1276,8 +1283,9 @@ def stream_engine_thread_target(chat_id: int):
|
|
| 1276 |
session['frames_encoded'] += 1
|
| 1277 |
session['bytes_sent'] += out_pkt.size
|
| 1278 |
session['last_frame_time'] = datetime.datetime.now()
|
| 1279 |
-
# Push live stats to SSE subscribers every
|
| 1280 |
-
|
|
|
|
| 1281 |
threading.Thread(target=_push_state_sse, args=(chat_id,), daemon=True).start()
|
| 1282 |
|
| 1283 |
elif active_audio_out_stream and packet.stream.type == 'audio' and in_a_streams and packet.stream.index == in_a_streams[0].index:
|
|
|
|
| 1229 |
session['streaming_state'] = "streaming"
|
| 1230 |
if old_st != "streaming":
|
| 1231 |
threading.Thread(target=notify_state_change, args=(chat_id, "streaming"), daemon=True).start()
|
| 1232 |
+
# Schedule a delayed live-view refresh so the status bubble
|
| 1233 |
+
# reflects real stats (frames/bytes/uptime) instead of zeros.
|
| 1234 |
+
def _delayed_stats_refresh(cid=chat_id):
|
| 1235 |
+
time.sleep(4)
|
| 1236 |
+
_push_state_sse(cid)
|
| 1237 |
+
_do_live_view_edit(cid, force=True)
|
| 1238 |
+
threading.Thread(target=_delayed_stats_refresh, daemon=True).start()
|
| 1239 |
|
| 1240 |
# --- Packet loop ---
|
| 1241 |
last_read_time = time.time()
|
|
|
|
| 1283 |
session['frames_encoded'] += 1
|
| 1284 |
session['bytes_sent'] += out_pkt.size
|
| 1285 |
session['last_frame_time'] = datetime.datetime.now()
|
| 1286 |
+
# Push live stats to SSE subscribers: every frame for first 300, then every 100
|
| 1287 |
+
_fc = session['frames_encoded']
|
| 1288 |
+
if _fc < 300 or _fc % 100 == 0:
|
| 1289 |
threading.Thread(target=_push_state_sse, args=(chat_id,), daemon=True).start()
|
| 1290 |
|
| 1291 |
elif active_audio_out_stream and packet.stream.type == 'audio' and in_a_streams and packet.stream.index == in_a_streams[0].index:
|