Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
<script>
import { onMount } from 'svelte';

console.log("With love, Sony AK <sony@sony-ak.com> GitHub https://github.com/sonyarianto");

let currentSong = '';
let currentArtist = '';
let streamUrl = 'https://api.zeno.fm/mounts/metadata/subscribe/vbyq86vnsp8uv';

onMount(() => {
const eventSource = new EventSource(streamUrl);

eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
const parts = data.streamTitle.split(" - ");

if (parts.length === 2) {
currentArtist = parts[0].trim();
currentSong = parts[1].trim();
} else {
// Handle cases where the delimiter is not found
console.warn("Unexpected format in streamTitle:", data.streamTitle);
currentSong = data.streamTitle;
currentArtist = '';
}
};

eventSource.onerror = (error) => {
console.error('SSE Error:', error);
};

return () => {
eventSource.close();
};
});
</script>
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */