oops
This commit is contained in:
@ -83,18 +83,14 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error parsing SSE data:', err);
|
||||
// Fail silently
|
||||
// Fail silently - will revert to static mode
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = (event) => {
|
||||
console.error('Spotify SSE error:', event);
|
||||
|
||||
// Fallback to polling if SSE fails
|
||||
if (eventSource.readyState === EventSource.CLOSED) {
|
||||
console.log('SSE connection closed, falling back to polling');
|
||||
startPolling();
|
||||
}
|
||||
// If SSE fails, we just fall back to static mode
|
||||
console.log('Spotify SSE failed, reverting to static mode');
|
||||
};
|
||||
|
||||
// Cleanup on unmount
|
||||
@ -103,41 +99,6 @@ export default function SpotifyIcon({ profileUrl = "https://open.spotify.com" }:
|
||||
};
|
||||
};
|
||||
|
||||
// Fallback polling function if SSE fails
|
||||
const startPolling = () => {
|
||||
const fetchCurrentTrack = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/spotify/current', {
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch Spotify data');
|
||||
}
|
||||
|
||||
const data: SpotifyResponse = await response.json();
|
||||
|
||||
if (data.is_playing && data.item) {
|
||||
currentTrack.value = data.item;
|
||||
isPlaying.value = data.is_playing;
|
||||
} else {
|
||||
currentTrack.value = null;
|
||||
isPlaying.value = false;
|
||||
}
|
||||
} catch (err) {
|
||||
// Fail silently
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch immediately
|
||||
fetchCurrentTrack();
|
||||
|
||||
// Then fetch every 10 seconds (fallback polling)
|
||||
const interval = setInterval(fetchCurrentTrack, 10000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
};
|
||||
|
||||
const getTooltipText = () => {
|
||||
if (isDynamicEnabled.value && currentTrack.value && isPlaying.value) {
|
||||
const artists = currentTrack.value.artists.map(artist => artist.name).join(', ');
|
||||
|
Reference in New Issue
Block a user