import io from "socket.io-client" class APIConnector { constructor(url) { this.url = url ?? "" this.socket = io(url) this.asset_index = 0 this.asset = null this.prevAssets = null this.nextAssets = null this.seekCallbacks = [] this.socket.on("seek", e => { this.asset_index = e.asset_index this.asset = e.asset this.prevAssets = e.prev_assets this.nextAssets = e.next_assets for (const cb of this.seekCallbacks) cb() }) } #fetch(endpoint) { return fetch(this.url + "/api" + endpoint) } fetch(endpoint) { return this.#fetch(endpoint) .then(response => { if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`) return response.json() }) .then(data => { return data }) .catch(error => { console.error("Fetch error:", error) }) } seek(increment) { //return this.fetch(`/seek?increment=${increment}`) this.socket.emit("seek", increment) } fetchAlbums() { return this.fetch("/albums/get") } albumThumbSrc(key) { return `${this.url}/api/albums/thumb/${key}` } } const apiConnector = new APIConnector("http://localhost:5000") export default apiConnector