From 80be38128f21ffb8ab409732c6bb37ff0a4b9c62 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 16 Mar 2019 14:12:25 -0400 Subject: [PATCH] Wasm client pings the server every second This prevents disconnects when the server is behind Nignx. Resolves #35. --- common/constants.go | 1 + wasm/main_wasm.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index 4966c31..17f9d9e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -5,6 +5,7 @@ type ClientDataType int const ( CdMessage ClientDataType = iota // a normal message from the client meant to be broadcast CdUsers // get a list of users + CdPing // ping the server to keep the connection alive ) type DataType int diff --git a/wasm/main_wasm.go b/wasm/main_wasm.go index e8471a9..5b167a1 100644 --- a/wasm/main_wasm.go +++ b/wasm/main_wasm.go @@ -261,6 +261,7 @@ func main() { // This is needed so the goroutine does not end for { - time.Sleep(time.Minute) + websocketSend("", common.CdPing) + time.Sleep(time.Second) } }