forked from pothtonswer/discordmuffin
Allow resume on reconnect
This commit is contained in:
parent
3736887e9b
commit
1789227299
1 changed files with 7 additions and 3 deletions
10
wsapi.go
10
wsapi.go
|
@ -516,7 +516,7 @@ func (s *Session) onEvent(messageType int, message []byte) (*Event, error) {
|
||||||
// Must immediately disconnect from gateway and reconnect to new gateway.
|
// Must immediately disconnect from gateway and reconnect to new gateway.
|
||||||
if e.Operation == 7 {
|
if e.Operation == 7 {
|
||||||
s.log(LogInformational, "Closing and reconnecting in response to Op7")
|
s.log(LogInformational, "Closing and reconnecting in response to Op7")
|
||||||
s.Close()
|
s.CloseWithCode(websocket.CloseServiceRestart)
|
||||||
s.reconnect()
|
s.reconnect()
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
@ -838,9 +838,13 @@ func (s *Session) reconnect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) Close() error {
|
||||||
|
return s.CloseWithCode(websocket.CloseNormalClosure)
|
||||||
|
}
|
||||||
|
|
||||||
// Close closes a websocket and stops all listening/heartbeat goroutines.
|
// Close closes a websocket and stops all listening/heartbeat goroutines.
|
||||||
// TODO: Add support for Voice WS/UDP connections
|
// TODO: Add support for Voice WS/UDP connections
|
||||||
func (s *Session) Close() (err error) {
|
func (s *Session) CloseWithCode(closeCode int) (err error) {
|
||||||
|
|
||||||
s.log(LogInformational, "called")
|
s.log(LogInformational, "called")
|
||||||
s.Lock()
|
s.Lock()
|
||||||
|
@ -862,7 +866,7 @@ func (s *Session) Close() (err error) {
|
||||||
// To cleanly close a connection, a client should send a close
|
// To cleanly close a connection, a client should send a close
|
||||||
// frame and wait for the server to close the connection.
|
// frame and wait for the server to close the connection.
|
||||||
s.wsMutex.Lock()
|
s.wsMutex.Lock()
|
||||||
err := s.wsConn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
err := s.wsConn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(closeCode, ""))
|
||||||
s.wsMutex.Unlock()
|
s.wsMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(LogInformational, "error closing websocket, %s", err)
|
s.log(LogInformational, "error closing websocket, %s", err)
|
||||||
|
|
Loading…
Reference in a new issue