add channel communication

This commit is contained in:
marlonerler
2024-07-04 17:27:46 +02:00
parent 2770d9b07d
commit 9649e3e522
5 changed files with 239 additions and 56 deletions
+10 -2
View File
@@ -1,10 +1,16 @@
import { forgetConnection, processMessage } from "./websocket-handler";
import Path from "path";
import { ServerWebSocket } from "bun";
// CONFIG
const staticDir = "static/dist";
const defaultPage = "index.html";
const errorPage = "404.html";
// TYPES
export type WS = ServerWebSocket<unknown>;
// SERVER
const server = Bun.serve({
fetch(request, server) {
@@ -27,9 +33,11 @@ const server = Bun.serve({
websocket: {
message(ws, message) {
processMessage(ws, message.toString());
},
close(ws, code, reason) {
forgetConnection(ws);
},
close(ws, code, reason) {},
},
});