diff --git a/src/index.ts b/src/index.ts index 1e408ee..9b2978f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,10 @@ import { decode } from "./protocol"; -import { type Client, getOrCreateSession, getSession } from "./session"; +import { + type Client, + type WsData, + getOrCreateSession, + getSession, +} from "./session"; const PORT = Number(process.env.PORT) || 4040; @@ -9,7 +14,7 @@ function isValidRoomName(name: unknown): name is string { return /^[a-zA-Z0-9_-]+$/.test(name); } -Bun.serve({ +Bun.serve({ port: PORT, fetch(req, server) { const url = new URL(req.url); diff --git a/src/session.ts b/src/session.ts index 6b316eb..b68b8e0 100644 --- a/src/session.ts +++ b/src/session.ts @@ -2,8 +2,13 @@ import type { ServerWebSocket } from "bun"; import * as Y from "yjs"; import { encode } from "./protocol"; +export interface WsData { + room: string | null; + client: Client | null; +} + export interface Client { - ws: ServerWebSocket<{ room: string | null }>; + ws: ServerWebSocket; } export class Session {