fix: accept duplex upgrade sockets
This commit is contained in:
@@ -7,6 +7,7 @@ import http, {
|
|||||||
import type { Socket } from "node:net";
|
import type { Socket } from "node:net";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import type { Duplex } from "node:stream";
|
||||||
|
|
||||||
import chokidar from "chokidar";
|
import chokidar from "chokidar";
|
||||||
import { type WebSocket, WebSocketServer } from "ws";
|
import { type WebSocket, WebSocketServer } from "ws";
|
||||||
@@ -50,7 +51,7 @@ export type CanvasHostHandler = {
|
|||||||
) => Promise<boolean>;
|
) => Promise<boolean>;
|
||||||
handleUpgrade: (
|
handleUpgrade: (
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
socket: Socket,
|
socket: Duplex,
|
||||||
head: Buffer,
|
head: Buffer,
|
||||||
) => boolean;
|
) => boolean;
|
||||||
close: () => Promise<void>;
|
close: () => Promise<void>;
|
||||||
@@ -266,12 +267,12 @@ export async function createCanvasHostHandler(
|
|||||||
|
|
||||||
const handleUpgrade = (
|
const handleUpgrade = (
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
socket: Socket,
|
socket: Duplex,
|
||||||
head: Buffer,
|
head: Buffer,
|
||||||
) => {
|
) => {
|
||||||
const url = new URL(req.url ?? "/", "http://localhost");
|
const url = new URL(req.url ?? "/", "http://localhost");
|
||||||
if (url.pathname !== CANVAS_WS_PATH) return false;
|
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);
|
wss.emit("connection", ws, req);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user