1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +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 { func (c *Client) addSubscriptionsForSession(session string) error {
if c.savedSubscriptions[session] {
// Already subscribed
return nil
}
client, err := c.GetUserClient() client, err := c.GetUserClient()
if err != nil { if err != nil {
return fmt.Errorf("failed getting API client for user: %w", err) return fmt.Errorf("failed getting API client for user: %w", err)
@ -152,6 +157,7 @@ func (c *Client) addSubscriptionsForSession(session string) error {
return fmt.Errorf("error subscribing to %s: %w", topic, err) return fmt.Errorf("error subscribing to %s: %w", topic, err)
} }
} }
c.savedSubscriptions[session] = true
return nil return nil
} }

View file

@ -26,6 +26,7 @@ type Client struct {
restart chan bool restart chan bool
streamOnline *containers.RWSync[bool] streamOnline *containers.RWSync[bool]
savedSubscriptions map[string]bool
} }
func NewClient(db *database.LocalDBClient, server *http.Server, logger *zap.Logger) (*Client, error) { func NewClient(db *database.LocalDBClient, server *http.Server, logger *zap.Logger) (*Client, error) {
@ -52,6 +53,7 @@ func NewClient(db *database.LocalDBClient, server *http.Server, logger *zap.Logg
restart: make(chan bool, 128), restart: make(chan bool, 128),
streamOnline: containers.NewRWSync(false), streamOnline: containers.NewRWSync(false),
eventCache: eventCache, eventCache: eventCache,
savedSubscriptions: make(map[string]bool),
} }
// Listen for Config changes // Listen for Config changes