The Redis media:status key was only rewritten after a command received via Redis. When the last track ended naturally (AudioPlayer Idle -> advanceQueue with an empty queue), currentTrackItem was cleared but the status key was not persisted — so the backend's cached status and the frontend's 10s polling stayed stuck showing the finished track as 'playing' forever. Wire a media-status sink (commandHandler provides the real redisPub to MediaHandler) and re-publish status after auto-advance, so natural track end updates the UI.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import type Redis from "ioredis";
|
|
import { createChildLogger } from "@/shared/logger/index";
|
|
import { MEDIA_STATUS_KEY } from "../../shared/redis-channels.js";
|
|
|
|
/**
|
|
* Shared sink for writing the media status Redis key.
|
|
*
|
|
* CommandHandler owns the publisher + status writes for command-triggered
|
|
* changes (`publishMediaStatus`). MediaHandler needs to also persist status
|
|
* when the queue advances *outside* a command (natural track end / screen-share
|
|
* done), so we expose the real publisher here and let CommandHandler wire it
|
|
* once at startup.
|
|
*/
|
|
const logger = createChildLogger("media-status-sink");
|
|
|
|
let _setMediaStatusKey: ((payload: unknown) => void) | null = null;
|
|
|
|
export function setMediaStatusWriter(writer: (payload: unknown) => void): void {
|
|
_setMediaStatusKey = writer;
|
|
}
|
|
|
|
export function setMediaStatusKey(payload: unknown): void {
|
|
if (!_setMediaStatusKey) {
|
|
logger.warn("Media status writer not wired — skipping status publish");
|
|
return;
|
|
}
|
|
_setMediaStatusKey(payload);
|
|
}
|
|
|
|
export { MEDIA_STATUS_KEY };
|
|
|
|
export function wireMediaStatusWriter(redisPub: Redis): void {
|
|
setMediaStatusWriter((payload) => {
|
|
redisPub
|
|
.set(MEDIA_STATUS_KEY, JSON.stringify(payload))
|
|
.catch((err: unknown) => {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
logger.warn({ error: msg }, "Failed to update media status key");
|
|
});
|
|
});
|
|
}
|