1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00

fix: don't resubscribe if reconnection has same ID

This commit is contained in:
Ash Keel 2022-12-01 00:29:57 +01:00
parent 4c0708138a
commit b9181c2d99
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
2 changed files with 17 additions and 9 deletions

View file

@ -118,6 +118,11 @@ func (c *Client) processEvent(message EventSubWebsocketMessage) {
}
func (c *Client) addSubscriptionsForSession(session string) error {
if c.savedSubscriptions[session] {
// Already subscribed
return nil
}
client, err := c.GetUserClient()
if err != nil {
return fmt.Errorf("failed getting API client for user: %w", err)
@ -131,7 +136,7 @@ func (c *Client) addSubscriptionsForSession(session string) error {
return fmt.Errorf("no users found")
}
user := users.Data.Users[0]
transport := helix.EventSubTransport{
Method: "websocket",
SessionID: session,
@ -152,6 +157,7 @@ func (c *Client) addSubscriptionsForSession(session string) error {
return fmt.Errorf("error subscribing to %s: %w", topic, err)
}
}
c.savedSubscriptions[session] = true
return nil
}

View file

@ -24,8 +24,9 @@ type Client struct {
logger *zap.Logger
eventCache *lru.Cache
restart chan bool
streamOnline *containers.RWSync[bool]
restart chan bool
streamOnline *containers.RWSync[bool]
savedSubscriptions map[string]bool
}
func NewClient(db *database.LocalDBClient, server *http.Server, logger *zap.Logger) (*Client, error) {
@ -46,12 +47,13 @@ func NewClient(db *database.LocalDBClient, server *http.Server, logger *zap.Logg
// Create Twitch client
client := &Client{
Config: config,
db: db,
logger: logger.With(zap.String("service", "twitch")),
restart: make(chan bool, 128),
streamOnline: containers.NewRWSync(false),
eventCache: eventCache,
Config: config,
db: db,
logger: logger.With(zap.String("service", "twitch")),
restart: make(chan bool, 128),
streamOnline: containers.NewRWSync(false),
eventCache: eventCache,
savedSubscriptions: make(map[string]bool),
}
// Listen for Config changes