From 53a826dd0d5c0a753d41c8dbd44516d42f6b158e Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Thu, 28 Apr 2016 22:30:42 -0500 Subject: [PATCH] Send heartbeat in response to gateway Op 1 message --- wsapi.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wsapi.go b/wsapi.go index acfc3eb..256b655 100644 --- a/wsapi.go +++ b/wsapi.go @@ -315,11 +315,22 @@ func (s *Session) onEvent(messageType int, message []byte) { s.log(LogDebug, "Op: %d, Seq: %d, Type: %s, Data: %s", e.Operation, e.Sequence, e.Type, string(e.RawData)) } + // Ping request. + // Must respond with a heartbeat packet within 5 seconds + if e.Operation == 1 { + s.log(LogInformational, "sending heartbeat in response to Op1") + err = s.wsConn.WriteJSON(heartbeatOp{1, s.sequence}) + if err != nil { + s.log(LogError, "error sending heartbeat in response to Op1") + return + } + } + // Do not try to Dispatch a non-Dispatch Message if e.Operation != 0 { // But we probably should be doing something with them. // TEMP - s.log(LogWarning, "Op: %d, Seq: %d, Type: %s, Data: %s, message: %s", e.Operation, e.Sequence, e.Type, string(e.RawData), string(message)) + s.log(LogWarning, "unknown Op: %d, Seq: %d, Type: %s, Data: %s, message: %s", e.Operation, e.Sequence, e.Type, string(e.RawData), string(message)) return }