From c746d8106372a4a1c69e48af4225d9953b939dc5 Mon Sep 17 00:00:00 2001 From: "Ricardo (XenGi) Band" Date: Wed, 18 Oct 2023 00:40:17 +0200 Subject: [PATCH] add mpd config --- flake.nix | 2 ++ mpd.conf | 13 +++++++++++++ package.json | 4 +++- server.ts | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 mpd.conf diff --git a/flake.nix b/flake.nix index e1aab56..9eda624 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,8 @@ devShells.default = pkgs.mkShell { packages = with pkgs; [ bun + mpd + mpc-cli ]; }; } diff --git a/mpd.conf b/mpd.conf new file mode 100644 index 0000000..06bbea1 --- /dev/null +++ b/mpd.conf @@ -0,0 +1,13 @@ +audio_output { + type "pipewire" + name "PipeWire Sound Server" +} + +db_file "/tmp/sanic/mpd_db" +auto_update "yes" +music_directory "/tmp/sanic/music" +playlist_directory "/tmp/sanic/playlists" +zeroconf_enabled "yes" +zeroconf_name "sanic dev server" +log_level "info" + diff --git a/package.json b/package.json index 6b2d4e4..8d9ff67 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "module": "server.ts", "type": "module", "scripts": { - "start": "bun run server.ts" + "start": "bun run server.ts", + "init": "mkdir -p /tmp/sanic/{music,playlists}; touch /tmp/sanic/mpd_db", + "mpd": "mpd --no-daemon ./mpd.conf" }, "devDependencies": { "bun-types": "latest" diff --git a/server.ts b/server.ts index f67b2c6..7ca927b 100644 --- a/server.ts +++ b/server.ts @@ -1 +1,32 @@ -console.log("Hello via Bun!"); \ No newline at end of file +// Run websocket server +const wsServer = Bun.serve({ + port: 8080, + fetch(req, server) { + // upgrade the request to a WebSocket + if (server.upgrade(req)) { + return; // do not return a Response + } + return new Response("Upgrade failed :(", { status: 500 }); + }, + websocket: { + message(ws, message) { // a message is received + ws.send(message); // echo back the message + }, + open(ws) {}, // a socket is opened + close(ws, code, message) {}, // a socket is closed + drain(ws) {}, // the socket is ready to receive more data + }, +}); + +// Run web server +const webServer = Bun.serve({ + port: 8000, + //unix: "/run/sanic.sock", + fetch(req) { + return new Response("Put frontend here!"); + }, +}); + +console.log(`Listening on http://localhost:${webServer.port} ...`); +console.log(`Listening on ws://localhost:${wsServer.port} ...`); +