2024-07-25 01:30:28 -04:00
|
|
|
import { assertEquals } from "@std/assert";
|
2022-01-06 11:41:16 -05:00
|
|
|
|
2023-11-22 06:11:20 -05:00
|
|
|
const errorDeferred = Promise.withResolvers<void>();
|
|
|
|
const closeDeferred = Promise.withResolvers<void>();
|
2022-01-06 11:41:16 -05:00
|
|
|
|
2022-02-16 10:51:32 -05:00
|
|
|
const listener = Deno.listen({ port: 4509 });
|
2022-01-06 11:41:16 -05:00
|
|
|
console.log("READY");
|
2024-09-05 18:15:00 -04:00
|
|
|
// @ts-ignore `Deno.serveHttp()` was soft-removed in Deno 2.
|
2022-01-06 11:41:16 -05:00
|
|
|
const httpConn = Deno.serveHttp(await listener.accept());
|
|
|
|
const { request, respondWith } = (await httpConn.nextRequest())!;
|
|
|
|
const { response, socket } = Deno.upgradeWebSocket(request, {
|
|
|
|
idleTimeout: 1,
|
|
|
|
});
|
|
|
|
socket.onerror = (e) => {
|
2024-02-28 17:12:21 -05:00
|
|
|
console.log(e);
|
2022-01-06 11:41:16 -05:00
|
|
|
assertEquals((e as ErrorEvent).message, "No response from ping frame.");
|
|
|
|
errorDeferred.resolve();
|
|
|
|
};
|
|
|
|
socket.onclose = (e) => {
|
2024-02-28 17:12:21 -05:00
|
|
|
console.log(e);
|
2022-01-06 11:41:16 -05:00
|
|
|
assertEquals(e.reason, "No response from ping frame.");
|
|
|
|
closeDeferred.resolve();
|
|
|
|
};
|
|
|
|
await respondWith(response);
|
|
|
|
|
2023-11-22 06:11:20 -05:00
|
|
|
await errorDeferred.promise;
|
|
|
|
await closeDeferred.promise;
|
2024-02-28 17:12:21 -05:00
|
|
|
|
|
|
|
// TODO(mmastrac): this doesn't exit on its own. Why?
|
|
|
|
Deno.exit(123);
|