diff --git a/readme.org b/readme.org index 5bec8c7..8709bca 100644 --- a/readme.org +++ b/readme.org @@ -42,7 +42,8 @@ See [[./devlog.org]] for design and architecture information. * License & Copyright Copyright (C) 2025 Jonathan Raphaelson -This program is free software: you can redistribute it and/or modify it under the -terms of the **Affero General Public License verson 3 or later** (AGPLv3+). + +This program is free software: you can redistribute it and/or modify it under the terms of +the **Affero General Public License verson 3 or later** (AGPLv3+). Please see [[./license.txt]] for a copy of the full license. diff --git a/src/common/socket.ts b/src/common/socket.ts index 3327c60..a9ed9ed 100644 --- a/src/common/socket.ts +++ b/src/common/socket.ts @@ -34,8 +34,6 @@ export async function* streamSocket( } }); - const onClose = gate.once(() => queue.enqueue(["end"])); - const onError = gate.once((e: Error) => { // todo: why are we getting this on client shutdown? if (e.message === "Unexpected EOF") { @@ -45,6 +43,8 @@ export async function* streamSocket( } }); + const onClose = gate.once(() => queue.enqueue(["end"])); + try { ws.addEventListener("message", onMessage); ws.addEventListener("error", onError); @@ -60,12 +60,10 @@ export async function* streamSocket( case "yield": yield value; continue; - - case "end": - return; - case "error": throw value; + case "end": + return; } } } catch (e) { diff --git a/src/server/socket/middleware.ts b/src/server/socket/middleware.ts index 8d9ad71..4b44389 100644 --- a/src/server/socket/middleware.ts +++ b/src/server/socket/middleware.ts @@ -2,10 +2,10 @@ import { Middleware } from "@oak/oak/middleware"; import { socketHandler } from "./handler.ts"; export const socketMiddleware: (path: string) => Middleware = - (pathname) => async (ctx, next) => { + (pathname) => (ctx, next) => { // must be an upgradable websocket connection to api root if (ctx.request.url.pathname !== pathname || !ctx.isUpgradable) { - return await next(); + return next(); } // then we'll upgrade and connect a handler