diff --git a/WebSocketServer.ts b/WebSocketServer.ts new file mode 100644 index 0000000..2ae529a --- /dev/null +++ b/WebSocketServer.ts @@ -0,0 +1,12 @@ +export function WebSocketServer(options : Deno.ServeOptions | Deno.ServeTlsOptions, handler : (webSocket : WebSocket) => void) { + Deno.serve(options, (request) => { + if (request.headers.get("upgrade") != "websocket") { + return new Response(null, { status: 501 }); + } + const {socket, response} = Deno.upgradeWebSocket(request) + + handler(socket) + + return response + }) +}