Skip to content

Commit

Permalink
unsubscribe from mqtt subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Feb 18, 2023
1 parent 4cc8135 commit 7671b1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions machinery/src/components/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func GetSnapshot() string {
content, _ := ioutil.ReadAll(reader)
// Encode as base64.
snapshot = base64.StdEncoding.EncodeToString(content)

// Close reader
reader = nil
}
return snapshot
}
Expand Down Expand Up @@ -146,6 +149,9 @@ func OpenConfig(configuration *models.Configuration) {
conjungo.Merge(&s3, configuration.CustomConfig.S3, opts)
configuration.Config.S3 = &s3

// Cleanup
opts = nil

} else if os.Getenv("DEPLOYMENT") == "" || os.Getenv("DEPLOYMENT") == "agent" {

// Local deployment means we do a stand-alone installation
Expand Down
2 changes: 1 addition & 1 deletion machinery/src/components/Kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
close(communication.HandleONVIF)
close(communication.HandleLiveHDHandshake)
close(communication.HandleMotion)
routers.DisconnectMQTT(mqttClient)
routers.DisconnectMQTT(mqttClient, &configuration.Config)

// Wait a few seconds to stop the decoder.
time.Sleep(time.Second * 3)
Expand Down
10 changes: 9 additions & 1 deletion machinery/src/routers/mqtt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,16 @@ func MQTTListenerHandleONVIF(mqttClient mqtt.Client, hubKey string, configuratio
})
}

func DisconnectMQTT(mqttClient mqtt.Client) {
func DisconnectMQTT(mqttClient mqtt.Client, config *models.Config) {
if mqttClient != nil {
// Cleanup all subscriptions.
mqttClient.Unsubscribe("kerberos/" + config.HubKey + "/device/" + config.Key + "/request-live")
mqttClient.Unsubscribe(config.Key + "/register")
mqttClient.Unsubscribe("kerberos/webrtc/keepalivehub/" + config.Key)
mqttClient.Unsubscribe("kerberos/webrtc/peers/" + config.Key)
mqttClient.Unsubscribe("candidate/cloud")
mqttClient.Unsubscribe("kerberos/onvif/" + config.Key)
mqttClient.Disconnect(1000)
mqttClient = nil
}
}

0 comments on commit 7671b1c

Please sign in to comment.