From d975cc8749ba589ce150568d9d7ca2717d5455d8 Mon Sep 17 00:00:00 2001 From: Derek Adams Date: Tue, 25 Sep 2018 21:17:07 -0400 Subject: [PATCH] Reconnect to MQTT broker if MQTT setting are updated. --- .../assignments/AssignmentEmulator.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/assignments/AssignmentEmulator.vue b/src/renderer/components/assignments/AssignmentEmulator.vue index 8c2bcea..6e8d6bb 100644 --- a/src/renderer/components/assignments/AssignmentEmulator.vue +++ b/src/renderer/components/assignments/AssignmentEmulator.vue @@ -135,6 +135,15 @@ export default { // Monitor MQTT connection. mqttConnected: function(value) { console.log("MQTT connected " + value); + }, + mqttHostname: function(value) { + this.establishMqttConnection(); + }, + mqttPort: function(value) { + this.establishMqttConnection(); + }, + mqttTopic: function(value) { + this.establishMqttConnection(); } }, @@ -246,12 +255,12 @@ export default { // Kill any existing connection. if (mqttClient && mqttConnected) { - mqttClient.end(); - this.$data.mqttConnected = false; + this.killMqttConnection(); } // Build URL based on form data. let url = "mqtt://" + this.$data.mqttHostname + ":" + this.$data.mqttPort; + console.log(`Connecting to MQTT via ${url}`); mqttClient = MQTT.connect(url); mqttClient.on("connect", function() { @@ -259,6 +268,10 @@ export default { mqttClient.subscribe(component.$data.mqttTopic); }); this.$data.mqttClient = mqttClient; + }, + killMqttConnection: function() { + mqttClient.end(); + this.$data.mqttConnected = false; } } };