/** * Navidrome MCP Server - Guest additions to the play queue * Copyright (C) 2025 * SPDX-License-Identifier: AGPL-3.0-or-later */ import { playbackEngine, type QueueTrackMetadata } from '../../services/playback/playback-engine.js'; import { TokenBuckets } from '../auth/token-bucket.js'; import { GuestLedger } from './guest-ledger.js'; type GuestQueueEngine = Pick; /** A guest session, or the admin session that queues from the guest page as the host. */ interface QueueingGuest { sessionId: string; isHost: boolean; /** Read when the song is recorded, since a rename can land while the add awaits its turn. */ currentLabel: () => string; /** Read again after the queue reads, since a ban or sign-out can land while an add or removal awaits them. */ isLive: () => boolean; } type AddResult = { kind: 'added'; entryId: number; remaining: number; } | { kind: 'radio'; } | { kind: 'limit'; limit: number; } | { kind: 'duplicate'; } | { kind: 'wait'; waitMs: number; } | { kind: 'untracked'; } | { kind: 'signed-out'; }; type RemoveResult = { kind: 'removed'; remaining: number; } | { kind: 'not-found'; } | { kind: 'started'; } | { kind: 'signed-out'; }; /** `guestLabel` names the guest who added the removed song, or is null for a song no guest added. */ type HostRemoveResult = { kind: 'removed'; guestLabel: string | null; } | { kind: 'not-found'; } | { kind: 'started'; }; /** `stayed` counts the queued songs left in place because no mpv was attached. */ interface GuestSongRemoval { removed: number; stayed: number; } /** Owns the guest ledger and the per-session rate limits of the guest search and add routes, which the host shares. */ export declare class GuestQueue { private readonly engine; private readonly limit; private readonly now; readonly ledger: GuestLedger; readonly searches: TokenBuckets; private readonly adds; private onChange; private addChain; private refreshing; private refreshAgain; constructor(engine?: GuestQueueEngine, limit?: () => number, now?: () => number); /** Follows mpv, so a guest song that starts while no page is open still frees its slot. */ watch(onChange: () => void): void; /** A lowered limit can leave a guest above it, and its songs stay, so `remaining` stops at 0. */ counts(sessionId: string): { limit: number; remaining: number; }; /** * Adds run one at a time, so two adds never both pass the limit or the duplicate check before * either records its song. An append never starts or resumes playback. */ add(guest: QueueingGuest, song: QueueTrackMetadata): Promise; private addNow; /** * Labels the songs an admin page add or replace loaded as the host's. When mpv gives any song no id, the * ids no longer line up with the songs, so none is labeled. */ labelAdminPageSongs(entryIds: readonly number[], songs: readonly QueueTrackMetadata[]): void; /** * A started song is the host's to skip, so a guest removes only its songs that have not started. * A stopped mpv holds none of the ledger's entries, so a guest removal never starts it. */ remove(guest: Pick, entryId: number): Promise; /** * The host removes any entry but the playing one. A guest song passes the song id read after the * refresh, so an entry that changes song before the engine's lock stays. Its removal frees the guest's slot. */ removeForHost(entryId: number): Promise; /** * Removes a banned guest's songs that have not started, held ones included. It runs behind the adds * already queued, so their songs leave too, and an add queued later finds the session gone. */ removeGuestSongs(sessionId: string): Promise; /** * A song that started meanwhile is the host's, so it stays. With no mpv attached the queued songs * stay too, since an mpv re-attached after a dropped connection still holds them. The held songs * drop either way, so a later replace never restores them. */ private removeGuestSongsNow; /** * Forgets the entry unless it started, so a gone entry stops counting. An mpv that detached during the * removal keeps the record, since an mpv re-attached after a dropped connection still holds the entry. */ private removeUnstarted; /** Also lets the broadcast carry the guest's or host's new nickname to every open page. */ relabel(sessionId: string, addedBy: string): void; prune(): void; /** Lists what `unplayedCount` counts, so the host's guest list and the guest's own count agree. */ unplayedSongs(sessionId: string): QueueTrackMetadata[]; /** * No mpv holds the ledger's entries while none is attached, so none count then. The entries stay, * since an mpv re-attached after a dropped connection still holds them. */ private unplayedCount; /** * A dropped mpv connection reads as an empty queue, which must not drop every guest song. An add * can record its entry while this refresh awaits, so the reconcile skips records newer than the read. * The replace marks are read after the playlist, so a replace that removed a song already shows its * mark. The generation is read before it too, so a replace that lands between the reads counts next time. */ private refresh; /** * Appends the unplayed guest songs a completed song replace removed, under their sessions. A held * song the new queue already holds waiting drops, as the add path refuses a second waiting copy. * Returns true when it took any song. */ private restoreReplaced; /** * When mpv gives any restored song no id, every restored song stays queued as a plain song. A failed * append leaves any song it already appended queued as a plain song. */ private appendRestored; private scheduleRefresh; private queueRefresh; private drainRefreshes; } export {}; //# sourceMappingURL=guest-queue.d.ts.map