diff --git a/pubsub.go b/pubsub.go index 377eb88..134c68f 100644 --- a/pubsub.go +++ b/pubsub.go @@ -3,13 +3,13 @@ package twitchpubsub import ( "time" - "github.com/gorilla/websocket" - "github.com/google/uuid" - "strings" - "errors" "encoding/json" - "sync" + "errors" + "github.com/google/uuid" + "github.com/gorilla/websocket" "log" + "strings" + "sync" ) const ( @@ -194,7 +194,7 @@ func (t *TwitchPubSub) listen(topics []string) error { if msg.Nonce != nonce { // Something is wrong, concurrent access? - return errors.New("Unexpected nonce") + return errors.New("unexpected nonce") } if len(msg.Error) > 0 { @@ -228,7 +228,7 @@ func (t *TwitchPubSub) Unlisten(topics []string) error { if msg.Nonce != nonce { // Something is wrong, concurrent access? - return errors.New("Unexpected nonce") + return errors.New("unexpected nonce") } if len(msg.Error) > 0 { @@ -292,6 +292,7 @@ func (t *TwitchPubSub) reader(wsConn *websocket.Conn, listening <-chan interface t.responseCh <- &message } else if message.Type == reconnectEventType { go t.handle(message.Type, &Reconnect{}) + t.Close() t.reconnect() } }