32 lines
940 B
TypeScript
32 lines
940 B
TypeScript
// Legacy WebSocket upgrade routing — to be replaced in T-1.5/T-1.6.
|
|
import type { IncomingMessage } from "node:http";
|
|
import type { Socket } from "node:net";
|
|
|
|
// Lightweight ws server interface (compatible with the ws package without types)
|
|
interface WsServer {
|
|
handleUpgrade(
|
|
request: IncomingMessage,
|
|
socket: Socket,
|
|
head: Buffer,
|
|
cb: (ws: unknown) => void,
|
|
): void;
|
|
emit(event: string, ...args: unknown[]): void;
|
|
}
|
|
|
|
/**
|
|
* Route WebSocket upgrade requests to the legacy server.
|
|
* In Phase 2 this will dispatch to topic/session-specific handlers.
|
|
*/
|
|
export function handleUpgrade(
|
|
wss: WsServer,
|
|
request: IncomingMessage,
|
|
socket: Socket,
|
|
head: Buffer,
|
|
): void {
|
|
// T-1.5/T-1.6: inspect URL to route to stream/input/session handlers.
|
|
// For now, delegate everything to the legacy WebSocket server.
|
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
wss.emit("connection", ws, request);
|
|
});
|
|
}
|