From dd4b88a86a99f028bdfe66fef3c66170629f3cdc Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 17 Jun 2024 00:04:34 +0200 Subject: establish ws --- test-client/main.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test-client/main.ts (limited to 'test-client/main.ts') diff --git a/test-client/main.ts b/test-client/main.ts new file mode 100644 index 00000000..bc0872a6 --- /dev/null +++ b/test-client/main.ts @@ -0,0 +1,34 @@ +/// + +let ctx: CanvasRenderingContext2D; +let canvas: HTMLCanvasElement; +let ws: WebSocket +document.addEventListener("DOMContentLoaded", () => { + ws = new WebSocket(`${window.location.protocol.endsWith("s:") ? "wss" : "ws"}://${window.location.hostname}:27032/`) + ws.onerror = console.error + ws.onmessage = m => { + console.log(JSON.parse(m.data)); + } + ws.onclose = () => console.warn("close") + ws.onopen = () => console.warn("open") + + canvas = document.createElement("canvas"); + document.body.append(canvas) + ctx = canvas.getContext("2d")! + resize() + globalThis.addEventListener("resize", resize) + draw() +}) + +function resize() { + canvas.width = globalThis.innerWidth + canvas.height = globalThis.innerHeight +} + +function draw() { + ctx.fillStyle = "black" + ctx.fillRect(0, 0, canvas.width, canvas.height) + + requestAnimationFrame(draw) +} + -- cgit v1.2.3-70-g09d2