Spotify fallback
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m44s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m44s
This commit is contained in:
@ -36,25 +36,33 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
|
||||
const currentTrack = useSignal<SpotifyTrack | null>(null);
|
||||
const isPlaying = useSignal(false);
|
||||
const isDynamicEnabled = useSignal(false);
|
||||
const hasLoggedError = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
// First, check if Spotify is properly configured
|
||||
const checkConfiguration = async () => {
|
||||
try {
|
||||
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();
|
||||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
||||
isDynamicEnabled.value = true;
|
||||
initializeSpotifyConnection();
|
||||
|
||||
} catch (error) {
|
||||
console.log('Spotify dynamic features disabled - configuration check failed:', error);
|
||||
} catch (error: any) {
|
||||
if (!hasLoggedError.value) {
|
||||
console.error('[Spotify] Could not enable dynamic features:', error?.message || error);
|
||||
hasLoggedError.value = true;
|
||||
}
|
||||
isDynamicEnabled.value = false;
|
||||
}
|
||||
};
|
||||
@ -67,13 +75,15 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
|
||||
const eventSource = new EventSource('/api/spotify/stream');
|
||||
|
||||
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) => {
|
||||
try {
|
||||
const data: SpotifyResponse = JSON.parse(event.data);
|
||||
|
||||
if (data.is_playing && data.item) {
|
||||
currentTrack.value = data.item;
|
||||
isPlaying.value = data.is_playing;
|
||||
@ -82,15 +92,20 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
|
||||
isPlaying.value = false;
|
||||
}
|
||||
} 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
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
console.log('Spotify SSE failed, reverting to static mode');
|
||||
};
|
||||
|
||||
// Cleanup on unmount
|
||||
|
Reference in New Issue
Block a user