957130ca38
* feat(ui): add browser audio profile detection for transcoding Detect browser codec capabilities via canPlayType() to build a client profile for the getTranscodeDecision API. Only codecs returning "probably" are treated as supported for conservative compatibility. * feat(ui): add transcode decision service with caching and pre-fetch Standalone service that fetches getTranscodeDecision results, caches them with an 11-hour TTL (1h buffer before 12h token expiry), and supports bulk pre-fetching for upcoming queue items. Includes invalidateAll() for handling stale tokens and getCachedDecision() for synchronous cache reads. * feat(ui): add fetch helper for getTranscodeDecision endpoint POST-based Subsonic API call that sends the browser's codec profile and returns the transcode decision including the JWT transcodeParams token for subsequent streaming. * feat(ui): wire transcode decision service singleton Module index that creates the service singleton with the real fetch function and re-exports the browser profile detector. * feat(ui): add Redux transcoding reducer for browser profile state Store the detected browser codec profile in Redux so it's available globally. The profile is set once at startup and used by the decision service when calling getTranscodeDecision. * feat(ui): integrate transcode decision into player musicSrc Replace static stream URLs with lazy musicSrc functions that fetch a transcode decision before playback. Falls back to the old stream endpoint if the decision fetch fails or if no browser profile is set. * feat(ui): detect browser profile and pre-fetch transcode decisions Run codec detection once when the Player mounts, storing the profile in both the decision service and Redux. Pre-fetch decisions for the next 3 songs when the queue or play position changes. * feat(ui): handle stale tokens and replace audio preload with decision pre-fetch On audio playback error, invalidate all cached transcode decisions and pre-fetch fresh decisions for upcoming songs. Replace the old Audio element preload with decision pre-fetching to warm the cache for instant playback transitions. * feat(ui): show transcode format in QualityInfo chip When transcode decision data is available, QualityInfo now shows "FLAC → OPUS 128" instead of just the source format. The new props are optional, so existing usages in song lists, album songs, playlists, and shares are unaffected. * feat(ui): display transcode status in player quality badge AudioTitle now reads the cached transcode decision for the current track and passes it to QualityInfo, showing "FLAC → OPUS 128" when transcoding or the normal format when direct playing. * chore(ui): format and lint transcode decision integration * refactor(ui): use JWT exp claim for decision cache expiry Replace the hardcoded 11-hour TTL with actual token expiration decoded from the JWT's exp claim. Each cache entry is now validated against its own token's lifetime, adapting automatically to server configuration changes. Tokens without an exp claim are treated as expired and re-fetched immediately. * fix(ui): resolve transcode URLs eagerly on browser refresh Instead of setting musicSrc to a function on queue refresh (which breaks the player's identity matching and can't survive JSON serialization), resolve transcode decisions for the current and next few tracks before dispatching, passing string URLs to the reducer. Also simplifies code: extract makeMusicSrc helper, add resolveStreamUrl to decisionService, use httpClient instead of raw fetch, and remove barrel file test. * chore(ui): fix prettier formatting in Player.jsx * fix(ui): use ref to avoid stale closure in mount-only transcode effect Split the mount effect into profile detection + URL resolution, using a ref for playerState so the effect correctly reads the latest queue without needing playerState in the dependency array (which would cause it to re-run on every queue/position change). * fix(ui): address code review feedback on transcode integration - Use jwt-decode for JWT parsing instead of manual atob (handles base64url) - Guard resolveStreamUrl to fall back to direct stream when decision is null - Fix savedPlayIndex -1 bug in PLAYER_REFRESH_QUEUE (findIndex returns -1) * docs: improve comments on JWT exp claim decoding in decision service Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
183 lines
5.0 KiB
React
183 lines
5.0 KiB
React
import ReactGA from 'react-ga'
|
|
import { Provider } from 'react-redux'
|
|
import { createHashHistory } from 'history'
|
|
import { Admin as RAAdmin, Resource } from 'react-admin'
|
|
import { HotKeys } from 'react-hotkeys'
|
|
import dataProvider from './dataProvider'
|
|
import authProvider from './authProvider'
|
|
import { Layout, Login, Logout } from './layout'
|
|
import transcoding from './transcoding'
|
|
import player from './player'
|
|
import user from './user'
|
|
import song from './song'
|
|
import album from './album'
|
|
import artist from './artist'
|
|
import playlist from './playlist'
|
|
import radio from './radio'
|
|
import share from './share'
|
|
import library from './library'
|
|
import plugin from './plugin'
|
|
import { Player } from './audioplayer'
|
|
import customRoutes from './routes'
|
|
import {
|
|
libraryReducer,
|
|
themeReducer,
|
|
addToPlaylistDialogReducer,
|
|
expandInfoDialogReducer,
|
|
listenBrainzTokenDialogReducer,
|
|
saveQueueDialogReducer,
|
|
playerReducer,
|
|
albumViewReducer,
|
|
activityReducer,
|
|
settingsReducer,
|
|
replayGainReducer,
|
|
downloadMenuDialogReducer,
|
|
shareDialogReducer,
|
|
transcodingReducer,
|
|
} from './reducers'
|
|
import createAdminStore from './store/createAdminStore'
|
|
import { i18nProvider } from './i18n'
|
|
import config, { shareInfo } from './config'
|
|
import { keyMap } from './hotkeys'
|
|
import useChangeThemeColor from './useChangeThemeColor'
|
|
import SharePlayer from './share/SharePlayer'
|
|
import { HTML5Backend } from 'react-dnd-html5-backend'
|
|
import { DndProvider } from 'react-dnd'
|
|
import missing from './missing/index.js'
|
|
|
|
const history = createHashHistory()
|
|
|
|
if (config.gaTrackingId) {
|
|
ReactGA.initialize(config.gaTrackingId)
|
|
history.listen((location) => {
|
|
ReactGA.pageview(location.pathname)
|
|
})
|
|
ReactGA.pageview(window.location.pathname)
|
|
}
|
|
|
|
const adminStore = createAdminStore({
|
|
authProvider,
|
|
dataProvider,
|
|
history,
|
|
customReducers: {
|
|
library: libraryReducer,
|
|
player: playerReducer,
|
|
albumView: albumViewReducer,
|
|
theme: themeReducer,
|
|
addToPlaylistDialog: addToPlaylistDialogReducer,
|
|
downloadMenuDialog: downloadMenuDialogReducer,
|
|
expandInfoDialog: expandInfoDialogReducer,
|
|
listenBrainzTokenDialog: listenBrainzTokenDialogReducer,
|
|
saveQueueDialog: saveQueueDialogReducer,
|
|
shareDialog: shareDialogReducer,
|
|
activity: activityReducer,
|
|
settings: settingsReducer,
|
|
replayGain: replayGainReducer,
|
|
transcoding: transcodingReducer,
|
|
},
|
|
})
|
|
|
|
const App = () => (
|
|
<Provider store={adminStore}>
|
|
<Admin />
|
|
</Provider>
|
|
)
|
|
|
|
const Admin = (props) => {
|
|
useChangeThemeColor()
|
|
/* eslint-disable react/jsx-key */
|
|
return (
|
|
<RAAdmin
|
|
disableTelemetry
|
|
dataProvider={dataProvider}
|
|
authProvider={authProvider}
|
|
i18nProvider={i18nProvider}
|
|
customRoutes={customRoutes}
|
|
history={history}
|
|
layout={Layout}
|
|
loginPage={Login}
|
|
logoutButton={Logout}
|
|
{...props}
|
|
>
|
|
{(permissions) => [
|
|
<Resource name="album" {...album} options={{ subMenu: 'albumList' }} />,
|
|
<Resource name="artist" {...artist} />,
|
|
<Resource name="song" {...song} />,
|
|
<Resource
|
|
name="radio"
|
|
{...(permissions === 'admin' ? radio.admin : radio.all)}
|
|
/>,
|
|
config.enableSharing && <Resource name="share" {...share} />,
|
|
<Resource
|
|
name="playlist"
|
|
{...playlist}
|
|
options={{ subMenu: 'playlist' }}
|
|
/>,
|
|
<Resource name="user" {...user} options={{ subMenu: 'settings' }} />,
|
|
<Resource
|
|
name="player"
|
|
{...player}
|
|
options={{ subMenu: 'settings' }}
|
|
/>,
|
|
permissions === 'admin' ? (
|
|
<Resource
|
|
name="transcoding"
|
|
{...transcoding}
|
|
options={{ subMenu: 'settings' }}
|
|
/>
|
|
) : (
|
|
<Resource name="transcoding" />
|
|
),
|
|
permissions === 'admin' ? (
|
|
<Resource
|
|
name="library"
|
|
{...library}
|
|
options={{ subMenu: 'settings' }}
|
|
/>
|
|
) : null,
|
|
permissions === 'admin' ? (
|
|
<Resource
|
|
name="missing"
|
|
{...missing}
|
|
options={{ subMenu: 'settings' }}
|
|
/>
|
|
) : null,
|
|
permissions === 'admin' && config.pluginsEnabled ? (
|
|
<Resource
|
|
name="plugin"
|
|
{...plugin}
|
|
options={{ subMenu: 'settings' }}
|
|
/>
|
|
) : null,
|
|
|
|
<Resource name="translation" />,
|
|
<Resource name="genre" />,
|
|
<Resource name="tag" />,
|
|
<Resource name="playlistTrack" />,
|
|
<Resource name="keepalive" />,
|
|
<Resource name="insights" />,
|
|
<Resource name="config" />,
|
|
<Player />,
|
|
]}
|
|
</RAAdmin>
|
|
)
|
|
/* eslint-enable react/jsx-key */
|
|
}
|
|
|
|
const AppWithHotkeys = () => {
|
|
let language = localStorage.getItem('locale') || 'en'
|
|
document.documentElement.lang = language
|
|
if (config.enableSharing && shareInfo) {
|
|
return <SharePlayer />
|
|
}
|
|
return (
|
|
<HotKeys keyMap={keyMap}>
|
|
<DndProvider backend={HTML5Backend}>
|
|
<App />
|
|
</DndProvider>
|
|
</HotKeys>
|
|
)
|
|
}
|
|
|
|
export default AppWithHotkeys
|