Change heartbeat to be send only when in chat
This commit is contained in:
parent
b38542333a
commit
30d480d878
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue