export interface NowPlayingResponse { success: boolean; nowPlaying: string; isPaused: boolean; volume: number; isIdle: boolean; currentFile: string; } export interface Metadata { title?: string; description?: string; siteName?: string; } export interface PlaylistItem { filename: string; title: string | null; id: number; playing: boolean | null; metadata?: Metadata; } export interface MetadataUpdateEvent { event: 'metadata_update'; data: { url: string; metadata: Metadata; }; } export const API = { async getPlaylist(): Promise { const response = await fetch('/api/playlist'); return response.json(); }, async addToPlaylist(url: string): Promise { await fetch('/api/playlist', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ url }), }); }, async removeFromPlaylist(index: number): Promise { await fetch(`/api/playlist/${index}`, { method: 'DELETE', }); }, async play(): Promise { await fetch('/api/play', { method: 'POST' }); }, async pause(): Promise { await fetch('/api/pause', { method: 'POST' }); }, async skip(): Promise { await fetch('/api/skip', { method: 'POST' }); }, async skipTo(index: number): Promise { await fetch(`/api/skip/${index}`, { method: 'POST' }); }, async previous(): Promise { await fetch('/api/previous', { method: 'POST' }); }, async getNowPlaying(): Promise { const response = await fetch('/api/nowplaying'); return response.json(); }, async setVolume(volume: number): Promise { await fetch('/api/volume', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ volume }), }); }, subscribeToEvents(onMessage: (event: any) => void): WebSocket { const ws = new WebSocket(`ws://${window.location.host}/api/events`); ws.onmessage = (event) => { onMessage(JSON.parse(event.data)); }; return ws; } };