diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-30 19:35:00 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-30 19:35:02 +0100 |
| commit | 2558e05b3661d3812ca6d417e5604da615124644 (patch) | |
| tree | 30e09a9b63f6a66d1081c84f513541fc5446d539 /test-client | |
| parent | d861319090fa6378aabf4fd102566083b915c1a5 (diff) | |
| download | hurrycurry-2558e05b3661d3812ca6d417e5604da615124644.tar hurrycurry-2558e05b3661d3812ca6d417e5604da615124644.tar.bz2 hurrycurry-2558e05b3661d3812ca6d417e5604da615124644.tar.zst | |
Add connection keepalives; Disconnect reasions
Diffstat (limited to 'test-client')
| -rw-r--r-- | test-client/main.ts | 11 | ||||
| -rw-r--r-- | test-client/protocol.ts | 1 |
2 files changed, 10 insertions, 2 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 865e1fb3..f66a46a4 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -49,10 +49,17 @@ document.addEventListener("DOMContentLoaded", async () => { ws.onmessage = m => { packet(JSON.parse(m.data) as PacketC); } - ws.onclose = () => console.log("close") + let keepalive_interval: number + ws.onclose = () => { + console.log("close") + clearInterval(keepalive_interval) + } ws.onopen = () => { console.log("open") send({ type: "join", name: "test", character: { color: Math.floor(Math.random() * 100), hairstyle: 0, headwear: 0 }, class: "chef" }) + keepalive_interval = setInterval(() => { + send({ type: "keepalive" }) + }, 1000) } canvas = document.createElement("canvas"); @@ -156,7 +163,7 @@ function get_item_location_tracking(loc: ItemLocation): V2 { } function send(p: PacketS) { - if (p.type != "movement") console.log("send", p); + if (p.type != "movement" && p.type != "keepalive") console.log("send", p); ws.send(JSON.stringify(p)) } function packet(p: PacketC) { diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 16c1fb98..293a085d 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -49,6 +49,7 @@ export type PacketS = | { type: "effect", player: PlayerID, name: string } // Sends an effect | { type: "replay_tick", dt: number } // Steps forward in replay. | { type: "ready" } + | { type: "keepalive" } export type PacketC = { type: "version", minor: number, major: number, supports_bincode?: boolean } // Sent once after connecting to ensure you client is compatible |