diff --git a/static/js/client.js b/static/js/client.js index 6786018..fa8957f 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -70,12 +70,14 @@ function appendMessages(msg) { $("#messages").append(msg).scrollTop(9e6); } +inChat = false function openChat() { console.log("chat opening"); $("#joinbox").css("display", "none"); $("#chat").css("display", "grid"); $("#msg").val(""); $("#msg").focus(); + inChat = true; } function closeChat() { @@ -83,6 +85,7 @@ function closeChat() { $("#joinbox").css("display", ""); $("#chat").css("display", "none"); $("#error").html("That name was already used!"); + inChat = false; } function join() { diff --git a/wasm/main_wasm.go b/wasm/main_wasm.go index 4ff3603..13bcdef 100644 --- a/wasm/main_wasm.go +++ b/wasm/main_wasm.go @@ -256,18 +256,19 @@ func debugValues(v []js.Value) { } func main() { - js.Set("recieveMessage", js.CallbackOf(recieve)) - js.Set("processMessage", js.CallbackOf(processMessage)) js.Set("processMessageKey", js.FuncOf(processMessageKey)) js.Set("sendMessage", js.FuncOf(send)) - js.Set("debugValues", js.CallbackOf(debugValues)) - // Get names on first run - websocketSend("", common.CdUsers) + js.Set("recieveMessage", js.CallbackOf(recieve)) + js.Set("processMessage", js.CallbackOf(processMessage)) + js.Set("debugValues", js.CallbackOf(debugValues)) // This is needed so the goroutine does not end for { - websocketSend("", common.CdPing) - time.Sleep(time.Second) + // heatbeat to keep connection alive to deal with nginx + if js.Get("inChat").Bool() { + websocketSend("", common.CdPing) + } + time.Sleep(time.Second * 10) } }