inital commit

This commit is contained in:
KingKDot
2026-03-05 00:04:26 -06:00
commit f8515a2883
269 changed files with 47081 additions and 0 deletions
@@ -0,0 +1,45 @@
import type { ServerWebSocket } from "bun";
import type { SocketData } from "../sessions/types";
type OpenHandler<TLifecycleDeps> = (
ws: ServerWebSocket<SocketData>,
deps: TLifecycleDeps,
) => void;
type MessageHandler<TLifecycleDeps> = (
ws: ServerWebSocket<SocketData>,
message: string | ArrayBuffer | Uint8Array,
deps: TLifecycleDeps,
) => void;
type CloseHandler<TLifecycleDeps> = (
ws: ServerWebSocket<SocketData>,
code: number,
reason: string,
deps: TLifecycleDeps,
) => void;
export function createWebSocketRuntime<TLifecycleDeps>(deps: {
maxClientPayloadBytes: number;
maxViewerPayloadBytes: number;
lifecycleDeps: TLifecycleDeps;
handleWebSocketOpen: OpenHandler<TLifecycleDeps>;
handleWebSocketMessage: MessageHandler<TLifecycleDeps>;
handleWebSocketClose: CloseHandler<TLifecycleDeps>;
}) {
return {
perMessageDeflate: true,
maxPayloadLength: Math.max(deps.maxClientPayloadBytes, deps.maxViewerPayloadBytes),
idleTimeout: 255,
sendPings: true,
open(ws: ServerWebSocket<SocketData>) {
deps.handleWebSocketOpen(ws, deps.lifecycleDeps);
},
message(ws: ServerWebSocket<SocketData>, message: string | ArrayBuffer | Uint8Array) {
deps.handleWebSocketMessage(ws, message, deps.lifecycleDeps);
},
close(ws: ServerWebSocket<SocketData>, code: number, reason: string) {
deps.handleWebSocketClose(ws, code, reason, deps.lifecycleDeps);
},
};
}