Deno desktop stuff

This commit is contained in:
2026-09-26 13:25:34 -03:00
parent b68fe3a19f
commit 86d5c39eab
10 changed files with 457 additions and 170 deletions
+25
View File
@@ -0,0 +1,25 @@
import { assertEquals, assertThrows } from "@std/assert";
import { server_address } from "$/client/handshake.ts";
const DESKTOP_PAGE = new URL("http://127.0.0.1:33549/client/");
const HTTPS_PAGE = new URL("https://bworld.moder.fans/client/");
Deno.test("servers on this machine use ws, everything else wss, whatever the page was served over", () => {
for (const host of ["localhost:8000", "127.0.0.1:8000", "0.0.0.0:8000", "[::1]:8000", "localhost"]) {
assertEquals(server_address(host, DESKTOP_PAGE).ws_url, `ws://${host}/ws`, host);
assertEquals(server_address(host, HTTPS_PAGE).ws_url, `ws://${host}/ws`, host);
}
for (const host of ["bworld.moder.fans", "example.com:8000", "192.168.1.5:8000", "localhost.example.com"]) {
assertEquals(server_address(host, DESKTOP_PAGE).ws_url, `wss://${host}/ws`, host);
assertEquals(server_address(host, DESKTOP_PAGE).base.protocol, "https:", host);
}
});
Deno.test("a scheme picks ws or wss itself", () => {
assertEquals(server_address("ws://192.168.1.5:8000", DESKTOP_PAGE).ws_url, "ws://192.168.1.5:8000/ws");
assertEquals(server_address("http://example.com", DESKTOP_PAGE).base.href, "http://example.com/");
assertEquals(server_address("wss://localhost:8000", DESKTOP_PAGE).ws_url, "wss://localhost:8000/ws");
assertEquals(server_address("https://bworld.moder.fans/", HTTPS_PAGE).cross_origin, false);
assertThrows(() => server_address("", DESKTOP_PAGE));
assertThrows(() => server_address("not a host", DESKTOP_PAGE));
});