Close and then reconnect on reconnect signal
This commit is contained in:
parent
7dd180eb83
commit
6223650a8c
15
pubsub.go
15
pubsub.go
|
@ -3,13 +3,13 @@ package twitchpubsub
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"strings"
|
|
||||||
"errors"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sync"
|
"errors"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -194,7 +194,7 @@ func (t *TwitchPubSub) listen(topics []string) error {
|
||||||
|
|
||||||
if msg.Nonce != nonce {
|
if msg.Nonce != nonce {
|
||||||
// Something is wrong, concurrent access?
|
// Something is wrong, concurrent access?
|
||||||
return errors.New("Unexpected nonce")
|
return errors.New("unexpected nonce")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Error) > 0 {
|
if len(msg.Error) > 0 {
|
||||||
|
@ -228,7 +228,7 @@ func (t *TwitchPubSub) Unlisten(topics []string) error {
|
||||||
|
|
||||||
if msg.Nonce != nonce {
|
if msg.Nonce != nonce {
|
||||||
// Something is wrong, concurrent access?
|
// Something is wrong, concurrent access?
|
||||||
return errors.New("Unexpected nonce")
|
return errors.New("unexpected nonce")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Error) > 0 {
|
if len(msg.Error) > 0 {
|
||||||
|
@ -292,6 +292,7 @@ func (t *TwitchPubSub) reader(wsConn *websocket.Conn, listening <-chan interface
|
||||||
t.responseCh <- &message
|
t.responseCh <- &message
|
||||||
} else if message.Type == reconnectEventType {
|
} else if message.Type == reconnectEventType {
|
||||||
go t.handle(message.Type, &Reconnect{})
|
go t.handle(message.Type, &Reconnect{})
|
||||||
|
t.Close()
|
||||||
t.reconnect()
|
t.reconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue