Spotify fallback
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m44s

This commit is contained in:
2025-06-12 14:05:10 -06:00
parent 55360c5e5d
commit 2ad6585a07

View File

@ -36,25 +36,33 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
const currentTrack = useSignal<SpotifyTrack | null>(null); const currentTrack = useSignal<SpotifyTrack | null>(null);
const isPlaying = useSignal(false); const isPlaying = useSignal(false);
const isDynamicEnabled = useSignal(false); const isDynamicEnabled = useSignal(false);
const hasLoggedError = useSignal(false);
useEffect(() => { useEffect(() => {
// First, check if Spotify is properly configured // First, check if Spotify is properly configured
const checkConfiguration = async () => { const checkConfiguration = async () => {
try { try {
const response = await fetch('/api/spotify/config'); const response = await fetch('/api/spotify/config');
if (!response.ok) {
throw new Error(`Spotify config endpoint returned status ${response.status}`);
}
const { configured } = await response.json(); const { configured } = await response.json();
if (!configured) { if (!configured) {
console.log('Spotify dynamic features disabled - missing or invalid environment variables'); if (!hasLoggedError.value) {
console.warn('[Spotify] Dynamic features disabled: missing or invalid environment variables.');
hasLoggedError.value = true;
}
isDynamicEnabled.value = false; isDynamicEnabled.value = false;
return; return;
} }
isDynamicEnabled.value = true; isDynamicEnabled.value = true;
initializeSpotifyConnection(); initializeSpotifyConnection();
} catch (error: any) {
} catch (error) { if (!hasLoggedError.value) {
console.log('Spotify dynamic features disabled - configuration check failed:', error); console.error('[Spotify] Could not enable dynamic features:', error?.message || error);
hasLoggedError.value = true;
}
isDynamicEnabled.value = false; isDynamicEnabled.value = false;
} }
}; };
@ -67,13 +75,15 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
const eventSource = new EventSource('/api/spotify/stream'); const eventSource = new EventSource('/api/spotify/stream');
eventSource.onopen = () => { eventSource.onopen = () => {
console.log('Spotify SSE connected'); // Only log on first open
if (!hasLoggedError.value) {
console.info('[Spotify] SSE connected for dynamic icon.');
}
}; };
eventSource.onmessage = (event) => { eventSource.onmessage = (event) => {
try { try {
const data: SpotifyResponse = JSON.parse(event.data); const data: SpotifyResponse = JSON.parse(event.data);
if (data.is_playing && data.item) { if (data.is_playing && data.item) {
currentTrack.value = data.item; currentTrack.value = data.item;
isPlaying.value = data.is_playing; isPlaying.value = data.is_playing;
@ -82,15 +92,20 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
isPlaying.value = false; isPlaying.value = false;
} }
} catch (err) { } catch (err) {
console.error('Error parsing SSE data:', err); if (!hasLoggedError.value) {
console.error('[Spotify] Error parsing SSE data:', err);
hasLoggedError.value = true;
}
// Fail silently - will revert to static mode // Fail silently - will revert to static mode
} }
}; };
eventSource.onerror = (event) => { eventSource.onerror = (event) => {
console.error('Spotify SSE error:', event); if (!hasLoggedError.value) {
console.error('[Spotify] SSE connection error. Falling back to static icon.');
hasLoggedError.value = true;
}
// If SSE fails, we just fall back to static mode // If SSE fails, we just fall back to static mode
console.log('Spotify SSE failed, reverting to static mode');
}; };
// Cleanup on unmount // Cleanup on unmount