blob: bc0872a6542267e8eb1cfd9dd4dd6879e9908201 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/// <reference lib="dom" />
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)
}
|