mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
891ab0dd5b
* feat(now-playing): adopt OpenSubsonic playbackReport for live now-playing Drive a small playback state machine (starting → playing ↔ paused → stopped) on the Subsonic-server channel when the server advertises the OpenSubsonic `playbackReport` extension (Navidrome ≥ 0.62), giving `getNowPlaying` a real transport state and an extrapolated position. Reports send `ignoreScrobble=true` so play counts stay on the existing `scrobble.view` 50% path (no double count), and the effective playback speed is included so the server extrapolates position correctly with the speed feature on. - New `playbackReportSession` FSM mirrors the existing `playListenSession` lifecycle hooks and is wired at the same player call sites (start / gapless switch / queue restore / resume / 15s heartbeat / pause / seek / stop / ended / error / app quit). Servers without the extension degrade to the unchanged legacy `scrobble.view?submission=false` presence call. - Gated through the existing serverCapabilities framework: a new `FEATURE_PLAYBACK_REPORT` (auto, extension-detected). The OpenSubsonic extensions probe now stores the full advertised list once and serves both AudioMuse `sonicSimilarity` and `playbackReport` from it, without disturbing the legacy Instant Mix opt-in on pre-0.62 servers. - Now Playing dropdown shows a live position bar and a paused indicator. - reportPlayback uses the real request params (mediaId / mediaType / positionMs). Tests: FSM transitions + gating + legacy fallback, capability resolution, extension-list probe storage/decoupling. Full suite green; no Tauri-boundary changes. * feat(now-playing): glide the Live position bar between polls Extrapolate the position of `playing` entries locally (elapsed × reported playbackRate from the last 10 s poll) and re-render once a second, so the Live progress bar advances smoothly instead of jumping on each refresh. Paused and position-less entries stay frozen. A linear width transition matched to the tick keeps the fill gliding. Only applies to clients that report a position via the playbackReport extension. * fix(now-playing): tighten Live timer layout and report resume immediately Keep the progress-bar width stable without a wide empty gap before the timer: reserve ~2ch inside the current-time span only (right-aligned), not on the whole clock block. Report `playing` to the server as soon as resume() runs, matching the immediate `paused` report on pause instead of waiting for the Rust `audio:playing` event. * docs: CHANGELOG and credits for playbackReport live now-playing (PR #1080)
84 lines
3.3 KiB
TypeScript
84 lines
3.3 KiB
TypeScript
import type { AuthState } from './authStoreTypes';
|
|
import { generateId } from './authStoreHelpers';
|
|
import { usePlayerStore } from './playerStore';
|
|
import { clearQueueServerForPlayback } from '../utils/playback/playbackServer';
|
|
import { resolveServerIdForIndexKey } from '../utils/server/serverLookup';
|
|
|
|
type SetState = (
|
|
partial: Partial<AuthState> | ((state: AuthState) => Partial<AuthState>),
|
|
) => void;
|
|
|
|
/**
|
|
* Server profile + connection lifecycle. `removeServer` is the
|
|
* non-trivial one: when the active server is the one being removed it
|
|
* also drops every per-server map entry tied to that id and switches
|
|
* the active id to the next available server (or null) so the rest of
|
|
* the app doesn't end up reading stale state.
|
|
*/
|
|
export function createServerProfileActions(set: SetState): Pick<
|
|
AuthState,
|
|
| 'addServer'
|
|
| 'updateServer'
|
|
| 'removeServer'
|
|
| 'setServers'
|
|
| 'setActiveServer'
|
|
| 'setLoggedIn'
|
|
| 'setConnecting'
|
|
| 'setConnectionError'
|
|
| 'logout'
|
|
> {
|
|
return {
|
|
addServer: (profile) => {
|
|
const id = generateId();
|
|
set(s => ({ servers: [...s.servers, { ...profile, id }] }));
|
|
return id;
|
|
},
|
|
|
|
updateServer: (id, data) => {
|
|
set(s => ({
|
|
servers: s.servers.map(srv => srv.id === id ? { ...srv, ...data } : srv),
|
|
}));
|
|
},
|
|
|
|
removeServer: (id) => {
|
|
// queueServerId is the canonical index key (B1); resolve the
|
|
// canonical id back to a server UUID before comparing so a profile
|
|
// delete still clears the matching queue binding.
|
|
const queueSid = usePlayerStore.getState().queueServerId;
|
|
if (queueSid && resolveServerIdForIndexKey(queueSid) === id) {
|
|
clearQueueServerForPlayback();
|
|
}
|
|
set(s => {
|
|
const newServers = s.servers.filter(srv => srv.id !== id);
|
|
const switchedAway = s.activeServerId === id;
|
|
const { [id]: _r, ...entityRatingRest } = s.entityRatingSupportByServer;
|
|
const { [id]: _a, ...audiomuseRest } = s.audiomuseNavidromeByServer;
|
|
const { [id]: _idn, ...identityRest } = s.subsonicServerIdentityByServer;
|
|
const { [id]: _iss, ...issueRest } = s.audiomuseNavidromeIssueByServer;
|
|
const { [id]: _pr, ...probeRest } = s.instantMixProbeByServer;
|
|
const { [id]: _ppl, ...pluginProbeRest } = s.audiomusePluginProbeByServer;
|
|
const { [id]: _ex, ...extRest } = s.openSubsonicExtensionsByServer;
|
|
return {
|
|
servers: newServers,
|
|
activeServerId: switchedAway ? (newServers[0]?.id ?? null) : s.activeServerId,
|
|
isLoggedIn: switchedAway ? false : s.isLoggedIn,
|
|
entityRatingSupportByServer: entityRatingRest,
|
|
audiomuseNavidromeByServer: audiomuseRest,
|
|
subsonicServerIdentityByServer: identityRest,
|
|
audiomuseNavidromeIssueByServer: issueRest,
|
|
instantMixProbeByServer: probeRest,
|
|
audiomusePluginProbeByServer: pluginProbeRest,
|
|
openSubsonicExtensionsByServer: extRest,
|
|
};
|
|
});
|
|
},
|
|
|
|
setServers: (servers) => set({ servers }),
|
|
setActiveServer: (id) => set({ activeServerId: id, musicFolders: [] }),
|
|
setLoggedIn: (v) => set({ isLoggedIn: v }),
|
|
setConnecting: (v) => set({ isConnecting: v }),
|
|
setConnectionError: (e) => set({ connectionError: e }),
|
|
logout: () => set({ isLoggedIn: false, musicFolders: [] }),
|
|
};
|
|
}
|