fix: accept duplex upgrade sockets

This commit is contained in:
Peter Steinberger
2025-12-20 18:00:33 +01:00
parent d3821123ee
commit f49c20c508

View File

@@ -7,6 +7,7 @@ import http, {
import type { Socket } from "node:net";
import os from "node:os";
import path from "node:path";
import type { Duplex } from "node:stream";
import chokidar from "chokidar";
import { type WebSocket, WebSocketServer } from "ws";
@@ -50,7 +51,7 @@ export type CanvasHostHandler = {
) => Promise<boolean>;
handleUpgrade: (
req: IncomingMessage,
socket: Socket,
socket: Duplex,
head: Buffer,
) => boolean;
close: () => Promise<void>;
@@ -266,12 +267,12 @@ export async function createCanvasHostHandler(
const handleUpgrade = (
req: IncomingMessage,
socket: Socket,
socket: Duplex,
head: Buffer,
) => {
const url = new URL(req.url ?? "/", "http://localhost");
if (url.pathname !== CANVAS_WS_PATH) return false;
wss.handleUpgrade(req, socket, head, (ws) => {
wss.handleUpgrade(req, socket as Socket, head, (ws) => {
wss.emit("connection", ws, req);
});
return true;