diff --git a/mpd.go b/mpd.go index 80943d9..12bac1c 100644 --- a/mpd.go +++ b/mpd.go @@ -11,22 +11,6 @@ import ( // MPD API calls -func updateDb(c echo.Context) error { - // Connect to MPD server - conn, err := mpd.Dial("tcp", "localhost:6600") - if err != nil { - log.Fatalln(err) - } - defer conn.Close() - - jobId, err := conn.Update("") - if err != nil { - log.Fatalln(err) - } - - return c.String(http.StatusOK, strconv.Itoa(jobId)) -} - func previousTrack(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") diff --git a/server.go b/server.go index 8095f32..fbd02c5 100644 --- a/server.go +++ b/server.go @@ -78,7 +78,6 @@ func main() { }) g := e.Group("/api") - g.GET("/update_db", updateDb) g.GET("/previous_track", previousTrack) g.GET("/next_track", nextTrack) g.GET("/stop", stopPlayback) diff --git a/static/controls.js b/static/controls.js deleted file mode 100644 index f63d153..0000000 --- a/static/controls.js +++ /dev/null @@ -1,98 +0,0 @@ -const API_URL = `${document.location.protocol}://${document.location.host}/api`; - -// Get control elements - -const control_update_db = document.getElementById("control-update-db"); -const control_previous = document.getElementById("control-previous"); -const control_play_pause = document.getElementById("control-play-pause"); -const control_stop = document.getElementById("control-stop"); -const control_next = document.getElementById("control-next"); -const control_progress = document.getElementById("control-progress"); -const control_repeat = document.getElementById("control-repeat"); -const control_shuffle = document.getElementById("control-shuffle"); -const control_xfade = document.getElementById("control-xfade"); -const control_xfade_minus = document.getElementById("control-xfade-minus"); -const control_xfade_plus = document.getElementById("control-xfade-plus"); -const queue_table = document.querySelector("#queue tbody"); - -// Add API calls to controls - -control_update_db.addEventListener("click", e => { - fetch(`${API_URL}/update_db`); -}); -control_previous.addEventListener("click", e => { - fetch(`${API_URL}/previous_track`); -}); -control_play_pause.addEventListener("click", e => { - if (e.target.innerText === "⏵︎") { // Play - fetch(`${API_URL}/pause`); - } else { // Pause - fetch(`${API_URL}/play`); - } -}); -control_stop.addEventListener("click", e => { - fetch(`${API_URL}/stop`); -}); -control_next.addEventListener("click", e => { - fetch(`${API_URL}/next_track`); -}); -control_progress.addEventListener("change", e => { - fetch(`${API_URL}/seek/${e.target.value}`) -}); -control_repeat.addEventListener("click", e => { - fetch(`${API_URL}/repeat`); -}); -control_shuffle.addEventListener("click", e => { - fetch(`${API_URL}/shuffle`); -}); -control_xfade_minus.addEventListener("click", e => { - // TODO: not yet implemented - fetch(`${API_URL}/xfade`); -}); -control_xfade_plus.addEventListener("click", e => { - // TODO: not yet implemented - fetch(`${API_URL}/xfade`); -}); - -// Create WebSocket connection. -const socket = new WebSocket(`${document.location.protocol === "https" ? "wss" : "ws"}://${document.location.host}/ws`); - -// Connection opened -socket.addEventListener("open", (e) => { - socket.send("Hello Server!"); -}); - -// Listen for messages -socket.addEventListener("message", (e) => { - console.log("Message from server"); - const msg = JSON.parse(e.data); - if ("error" in msg.mpd_status) { - console.error(msg.mpd_status.error); - } - - if ("updating_db" in msg.mpd_status) { - control_update_db.disable(); - } else { - control_update_db.enable(); - } - if ("state" in msg.mpd_status && msg.mpd_status.state === "play") { - control_play_pause.innerText = "⏸︎"; // Pause - } else { - control_play_pause.innerText = "⏵︎"; // Play - } - if ("elapsed" in msg.mpd_status) { - control_progress.value = msg.mpd_status.elapsed; - } - if ("duration" in msg.mpd_status) { - control_progress.max = msg.mpd_status.duration; - } - if ("repeat" in msg.mpd_status) { - control_repeat.checked = msg.mpd_status.repeat; - } - if ("random" in msg.mpd_status) { - control_shuffle.checked = msg.mpd_status.random; - } - if ("xfade" in msg.mpd_status) { - control_xfade.value = msg.mpd_status.xfade; - } -}); diff --git a/static/index.html b/static/index.html index 8934465..daaf309 100644 --- a/static/index.html +++ b/static/index.html @@ -4,7 +4,6 @@