fix(audio,sessions): unify audio playback state and improve session discovery
Some checks failed
CI / test (push) Failing after 18s

- move voice/audio players to single global audio engine with shared volume

- stop/reset previous track when switching to another media

- keep playback alive across chat switches via global audio element

- list refresh sessions by redis scan fallback when user session set is missing
This commit is contained in:
2026-03-08 11:48:13 +03:00
parent 27d3340a37
commit 897defc39d
3 changed files with 122 additions and 99 deletions

View File

@@ -105,6 +105,26 @@ async def list_refresh_sessions_for_user(*, user_id: int) -> list[RefreshSession
try:
redis = get_redis_client()
session_ids = await redis.smembers(f"auth:user_refresh:{user_id}")
if not session_ids:
cursor = 0
discovered: list[str] = []
while True:
cursor, keys = await redis.scan(cursor=cursor, match="auth:refresh:*", count=200)
for raw_key in keys:
key = raw_key.decode("utf-8") if isinstance(raw_key, bytes) else str(raw_key)
if not key.startswith("auth:refresh:"):
continue
jti = key.removeprefix("auth:refresh:")
if not jti:
continue
owner = await redis.get(key)
if owner and str(owner).isdigit() and int(owner) == user_id:
discovered.append(jti)
if cursor == 0:
break
if discovered:
await redis.sadd(f"auth:user_refresh:{user_id}", *discovered)
session_ids = {item.encode("utf-8") for item in discovered}
sessions: list[RefreshSession] = []
stale: list[str] = []
for raw_jti in session_ids: