Basic functionality is here with a crappy ai generated frontend.

This commit is contained in:
Jurn Wubben 2026-02-01 17:07:39 +01:00
commit e9fdc05c2d
14 changed files with 1600 additions and 0 deletions

43
src/main.ts Normal file
View file

@ -0,0 +1,43 @@
import { SpotifyWS } from "./spotify.ts"
import { HeartbeatWS } from "./heartbeat.ts";
import { PlayerManager } from "./playerManager.ts";
import { serveFile } from "@std/http/file-server";
import { UserWS } from "./user.ts";
const USER_PATTERN = new URLPattern({pathname: "/ws/user"})
const SPOTIFY_PATTERN = new URLPattern({pathname: "/ws/spotify"})
const song = "spotify:track:2VxJVGiTsK6UyrxPJJ2lR9";
function commonWs(req: Request) {
const { socket, response } = Deno.upgradeWebSocket(req);
return { socket, response };
}
declare global {
var spotify: SpotifyWS | undefined;
var playerManager: PlayerManager
}
globalThis.spotify = undefined;
globalThis.playerManager = new PlayerManager()
Deno.serve((req) => {
if (USER_PATTERN.exec(req.url)) {
const { socket, response } = commonWs(req);
new HeartbeatWS(socket);
new UserWS(socket)
return response
} else if (SPOTIFY_PATTERN.exec(req.url)) {
const { socket, response } = commonWs(req);
const spState = spotify?.ws.readyState;
if (spState !== undefined && spState !== WebSocket.CLOSED) spotify?.ws.close();
spotify = new SpotifyWS(socket, () => song);
new HeartbeatWS(socket);
return response
}
return serveFile(req, "./static/index.html")
})