mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat(now-playing): OpenSubsonic playbackReport for live now-playing (#1080)
* 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)
This commit is contained in:
@@ -13,14 +13,17 @@ import type { CapabilityDefinition } from './types';
|
||||
*/
|
||||
|
||||
export const SONIC_SIMILARITY_EXTENSION = 'sonicSimilarity';
|
||||
export const PLAYBACK_REPORT_EXTENSION = 'playbackReport';
|
||||
|
||||
export const FEATURE_AUDIOMUSE_SIMILAR_TRACKS = 'audiomuse.similarTracks';
|
||||
export const FEATURE_PLAYBACK_REPORT = 'opensubsonic.playbackReport';
|
||||
|
||||
export const PROBE_OPENSUBSONIC_EXTENSIONS = 'opensubsonic.extensions';
|
||||
export const PROBE_LEGACY_INSTANT_MIX = 'navidrome.instantMix.legacy';
|
||||
|
||||
/** Operation names used by the call router. */
|
||||
export const OP_SIMILAR_TRACKS = 'similarTracks';
|
||||
export const OP_REPORT_PLAYBACK = 'reportPlayback';
|
||||
|
||||
export const SERVER_CAPABILITY_CATALOG: CapabilityDefinition[] = [
|
||||
{
|
||||
@@ -65,6 +68,32 @@ export const SERVER_CAPABILITY_CATALOG: CapabilityDefinition[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// OpenSubsonic `playbackReport` (Navidrome ≥ 0.62): rich live now-playing via
|
||||
// a small playback FSM. Auto-on wherever the server advertises the extension;
|
||||
// call sites fall back to legacy `scrobble.view?submission=false` presence when
|
||||
// it is absent. Detection is server-agnostic (any OpenSubsonic server may add it).
|
||||
feature: FEATURE_PLAYBACK_REPORT,
|
||||
labelKey: 'nowPlaying.title',
|
||||
strategies: [
|
||||
{
|
||||
id: 'opensubsonic.playbackReport',
|
||||
priority: 100,
|
||||
when: (ctx) => ctx.openSubsonic,
|
||||
detection: {
|
||||
kind: 'extension',
|
||||
probeId: PROBE_OPENSUBSONIC_EXTENSIONS,
|
||||
extension: PLAYBACK_REPORT_EXTENSION,
|
||||
},
|
||||
trust: 'high',
|
||||
activation: 'auto',
|
||||
calls: {
|
||||
[OP_REPORT_PLAYBACK]: { endpoint: 'reportPlayback.view', transport: 'opensubsonic' },
|
||||
},
|
||||
labelKey: 'nowPlaying.title',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export function getCapabilityDefinition(feature: string): CapabilityDefinition | undefined {
|
||||
|
||||
@@ -2,7 +2,9 @@ import { describe, expect, it } from 'vitest';
|
||||
import { buildCapabilityContext } from './context';
|
||||
import {
|
||||
FEATURE_AUDIOMUSE_SIMILAR_TRACKS,
|
||||
FEATURE_PLAYBACK_REPORT,
|
||||
OP_SIMILAR_TRACKS,
|
||||
PLAYBACK_REPORT_EXTENSION,
|
||||
PROBE_LEGACY_INSTANT_MIX,
|
||||
PROBE_OPENSUBSONIC_EXTENSIONS,
|
||||
SERVER_CAPABILITY_CATALOG,
|
||||
@@ -50,10 +52,40 @@ describe('neededProbeIds', () => {
|
||||
expect(ids.has(PROBE_OPENSUBSONIC_EXTENSIONS)).toBe(true);
|
||||
expect(ids.has(PROBE_LEGACY_INSTANT_MIX)).toBe(false);
|
||||
});
|
||||
it('asks for the legacy probe on 0.61', () => {
|
||||
it('asks for the legacy probe on 0.61, plus the extensions probe for playbackReport', () => {
|
||||
const ids = neededProbeIds(SERVER_CAPABILITY_CATALOG, ctxFor('0.61.0'));
|
||||
expect(ids.has(PROBE_LEGACY_INSTANT_MIX)).toBe(true);
|
||||
expect(ids.has(PROBE_OPENSUBSONIC_EXTENSIONS)).toBe(false);
|
||||
// playbackReport detection is OpenSubsonic-generic, so the extensions probe
|
||||
// is now needed on any OpenSubsonic server (the fetch is shared).
|
||||
expect(ids.has(PROBE_OPENSUBSONIC_EXTENSIONS)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('playbackReport capability', () => {
|
||||
const pbDef = getCapabilityDefinition(FEATURE_PLAYBACK_REPORT)!;
|
||||
const withExt: ProbeOutcome = { status: 'present', extensions: [PLAYBACK_REPORT_EXTENSION] };
|
||||
const withoutExt: ProbeOutcome = { status: 'present', extensions: [SONIC_SIMILARITY_EXTENSION] };
|
||||
|
||||
it('is auto-active on any OpenSubsonic server that advertises the extension', () => {
|
||||
const r = resolveCapability(pbDef, ctxFor('0.62.0'), { [PROBE_OPENSUBSONIC_EXTENSIONS]: withExt });
|
||||
expect(r).toMatchObject({ status: 'present', activation: 'auto', trust: 'high' });
|
||||
expect(isCapabilityActive(r, false)).toBe(true);
|
||||
});
|
||||
|
||||
it('detects on non-Navidrome OpenSubsonic servers too', () => {
|
||||
const r = resolveCapability(pbDef, ctxFor('1.16.1', 'gonic'), { [PROBE_OPENSUBSONIC_EXTENSIONS]: withExt });
|
||||
expect(r.status).toBe('present');
|
||||
});
|
||||
|
||||
it('is absent when the extension is not advertised', () => {
|
||||
const r = resolveCapability(pbDef, ctxFor('0.62.0'), { [PROBE_OPENSUBSONIC_EXTENSIONS]: withoutExt });
|
||||
expect(r.status).toBe('absent');
|
||||
expect(isCapabilityActive(r, true)).toBe(false);
|
||||
});
|
||||
|
||||
it('is ineligible on non-OpenSubsonic servers', () => {
|
||||
const r = resolveCapability(pbDef, buildCapabilityContext({ type: 'subsonic', serverVersion: '1.16.1', openSubsonic: false }), {});
|
||||
expect(r.status).toBe('ineligible');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { FEATURE_AUDIOMUSE_SIMILAR_TRACKS, OP_SIMILAR_TRACKS } from './catalog';
|
||||
import {
|
||||
FEATURE_AUDIOMUSE_SIMILAR_TRACKS,
|
||||
FEATURE_PLAYBACK_REPORT,
|
||||
OP_SIMILAR_TRACKS,
|
||||
} from './catalog';
|
||||
import {
|
||||
isFeatureActiveForServer,
|
||||
resolveCallRoutesForServer,
|
||||
@@ -15,6 +19,7 @@ function seed(identity: Record<string, unknown>, extra: Record<string, unknown>
|
||||
audiomusePluginProbeByServer: {},
|
||||
instantMixProbeByServer: {},
|
||||
audiomuseNavidromeByServer: {},
|
||||
openSubsonicExtensionsByServer: {},
|
||||
...extra,
|
||||
} as never);
|
||||
}
|
||||
@@ -26,6 +31,7 @@ describe('storeView (capability read facade)', () => {
|
||||
audiomusePluginProbeByServer: {},
|
||||
instantMixProbeByServer: {},
|
||||
audiomuseNavidromeByServer: {},
|
||||
openSubsonicExtensionsByServer: {},
|
||||
} as never);
|
||||
});
|
||||
|
||||
@@ -64,4 +70,20 @@ describe('storeView (capability read facade)', () => {
|
||||
expect(resolveFeatureForServer(SID, FEATURE_AUDIOMUSE_SIMILAR_TRACKS)?.status).toBe('ineligible');
|
||||
expect(resolveCallRoutesForServer(SID, FEATURE_AUDIOMUSE_SIMILAR_TRACKS, OP_SIMILAR_TRACKS)).toEqual([]);
|
||||
});
|
||||
|
||||
it('playbackReport is active from the stored extension list', () => {
|
||||
seed({ type: 'navidrome', serverVersion: '0.62.1', openSubsonic: true }, {
|
||||
openSubsonicExtensionsByServer: { [SID]: ['sonicSimilarity', 'playbackReport'] },
|
||||
});
|
||||
expect(isFeatureActiveForServer(SID, FEATURE_PLAYBACK_REPORT)).toBe(true);
|
||||
// The same stored list still satisfies AudioMuse detection.
|
||||
expect(isFeatureActiveForServer(SID, FEATURE_AUDIOMUSE_SIMILAR_TRACKS)).toBe(true);
|
||||
});
|
||||
|
||||
it('playbackReport is inactive when the extension is absent from the list', () => {
|
||||
seed({ type: 'navidrome', serverVersion: '0.62.1', openSubsonic: true }, {
|
||||
openSubsonicExtensionsByServer: { [SID]: ['sonicSimilarity'] },
|
||||
});
|
||||
expect(isFeatureActiveForServer(SID, FEATURE_PLAYBACK_REPORT)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import type {
|
||||
AudiomusePluginProbeResult,
|
||||
InstantMixProbeResult,
|
||||
} from '../utils/server/subsonicServerIdentity';
|
||||
import { buildCapabilityContext } from './context';
|
||||
@@ -25,8 +24,18 @@ import type {
|
||||
* Probe results currently live in dedicated per-server store maps. This facade
|
||||
* maps them into the generic `ProbeOutcome` shape the resolver consumes, so the
|
||||
* catalog/resolver/router stay storage-agnostic.
|
||||
*
|
||||
* The OpenSubsonic extensions outcome is built from the full advertised list
|
||||
* (`openSubsonicExtensionsByServer`) so every extension-gated feature reads from
|
||||
* one source. The AudioMuse `sonicSimilarity` probe lifecycle still supplies the
|
||||
* probing/error transitions (it drives the fetch on Navidrome ≥ 0.62), and acts
|
||||
* as a back-compat fallback for state persisted before the list was captured.
|
||||
*/
|
||||
function pluginProbeToOutcome(probe: AudiomusePluginProbeResult | undefined): ProbeOutcome | undefined {
|
||||
function openSubsonicExtensionsOutcome(serverId: string): ProbeOutcome | undefined {
|
||||
const s = useAuthStore.getState();
|
||||
const list = s.openSubsonicExtensionsByServer[serverId];
|
||||
if (list) return { status: 'present', extensions: list };
|
||||
const probe = s.audiomusePluginProbeByServer[serverId];
|
||||
switch (probe) {
|
||||
case 'present': return { status: 'present', extensions: [SONIC_SIMILARITY_EXTENSION] };
|
||||
case 'absent': return { status: 'present', extensions: [] };
|
||||
@@ -49,7 +58,7 @@ function legacyProbeToOutcome(probe: InstantMixProbeResult | undefined): ProbeOu
|
||||
export function buildProbeOutcomesForServer(serverId: string): Record<string, ProbeOutcome | undefined> {
|
||||
const s = useAuthStore.getState();
|
||||
return {
|
||||
[PROBE_OPENSUBSONIC_EXTENSIONS]: pluginProbeToOutcome(s.audiomusePluginProbeByServer[serverId]),
|
||||
[PROBE_OPENSUBSONIC_EXTENSIONS]: openSubsonicExtensionsOutcome(serverId),
|
||||
[PROBE_LEGACY_INSTANT_MIX]: legacyProbeToOutcome(s.instantMixProbeByServer[serverId]),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user