Skip to content

Commit

Permalink
Send heartbeat in response to gateway Op 1 message
Browse files Browse the repository at this point in the history
  • Loading branch information
bwmarrin committed Apr 29, 2016
1 parent d557bb2 commit 53a826d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 53a826d

Please sign in to comment.