Browse Source

Send commands only if connection active

Volodymyr Tkach 2 years ago
parent
commit
f3368f9b3d
1 changed files with 2 additions and 2 deletions
  1. 2 2
      pubsub/connection.go

+ 2 - 2
pubsub/connection.go

@@ -131,7 +131,7 @@ func (c *Connection) listenTopis() {
 	}
 
 	// Send LISTEN request
-	if c.Connection != nil {
+	if c.Connection != nil && c.active {
 		msg := Answer{Type: Listen, Data: AnswerDataTopics{Topics: topics}}.JSON()
 		if err := c.Connection.WriteMessage(websocket.TextMessage, msg); err != nil {
 			c.onError(err)
@@ -171,7 +171,7 @@ func (c *Connection) RemoveTopic(topic string) {
 	delete(c.topics, topic)
 
 	// Send UNLISTEN request
-	if c.Connection != nil {
+	if c.Connection != nil && c.active {
 		msg := Answer{Type: Unlisten, Data: AnswerDataTopics{Topics: []string{topic}}}.JSON()
 		if err := c.Connection.WriteMessage(websocket.TextMessage, msg); err != nil {
 			c.onError(err)