feat(hmi): Spotify integration — PKCE OAuth + full playback controls#155
Open
rbrito02 wants to merge 2 commits into
Open
feat(hmi): Spotify integration — PKCE OAuth + full playback controls#155rbrito02 wants to merge 2 commits into
rbrito02 wants to merge 2 commits into
Conversation
…controls Replaces the static hardcoded music dock in the HMI dashboard with a live Spotify player. Implements PKCE authorization code flow (no client secret required) and the Spotify Web API for real-time now-playing data. Features: - useSpotify hook: PKCE auth, token storage/refresh, 2-second playback polling - SpotifyPlayer component: album art, track/artist/album display, seekable progress bar, play/pause, skip prev/next, shuffle toggle, repeat cycle (off → context → track), volume slider with mute toggle, debounced API calls - .env.example documents VITE_SPOTIFY_CLIENT_ID and VITE_SPOTIFY_REDIRECT_URI - Three UI states: connect prompt, no-active-device, and full player
Critical: - useSpotify: decouple polling lifecycle from init effect — polling now starts/ stops via a dedicated useEffect watching isAuthenticated, eliminating the orphaned setInterval if the component unmounts after token exchange completes - useSpotify: rename 'next' local var in toggleShuffle to 'newShuffleState' to remove shadowing of the next() playback action Important: - SpotifyPlayer: add isLoading skeleton state to prevent flash of Connect UI while stored tokens are being validated on mount - SpotifyPlayer: extract PlayerCard as a named component outside SpotifyPlayer so React's reconciler sees a stable type across renders - SpotifyPlayer: fix useCallback deps — handleSeekEnd depends on spotify.seek, handleVolumeChange depends on spotify.setVolume (not the whole spotify object) - SpotifyPlayer: remove stale seek-start capture of displayProgress state; read directly from syncRef so handleSeekStart needs no deps Minor: - useSpotify: replace btoa(String.fromCharCode(...spread)) with reduce to eliminate the spread-overflow pattern (safe at 32 bytes but non-idiomatic) - SpotifyPlayer: add durationMs to syncRef; clamp interpolated progress at track duration inside the interval rather than only at render time - SpotifyPlayer: mute toggle now restores to pre-mute volume via prevVolumeRef instead of hardcoding 50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New files
packages/hmi/src/hooks/useSpotify.tspackages/hmi/src/components/SpotifyPlayer.tsxpackages/hmi/.env.exampleVITE_SPOTIFY_CLIENT_IDandVITE_SPOTIFY_REDIRECT_URIPlayer features
Setup
http://localhost:3000) to the app's Redirect URIspackages/hmi/.env.example→.envand fill inVITE_SPOTIFY_CLIENT_IDandVITE_SPOTIFY_REDIRECT_URITest plan
.env.exampleis present and documents both required vars