From 00091ccc57570dea004430b969461100b5ec04e1 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 1 Oct 2020 21:56:27 +0800 Subject: [PATCH] Change mqtt session to persistent #514 --- public/assets/js/map_mqtt.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 8a38e8ff..30f646cd 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -3,6 +3,7 @@ class MapEventHandler { this.options = options; this.dashmap = dashmap; this.ssl = ssl; + this.subscribed = false; } connect(user_id, host, port) { @@ -21,7 +22,8 @@ class MapEventHandler { keepAliveInterval: 10, invocationContext: this, onSuccess: this.onConnect.bind(this), - reconnect: true + reconnect: true, + cleanSession: false }; this.mqtt.onMessageArrived = this.onMessage.bind(this); @@ -40,6 +42,11 @@ class MapEventHandler { console.log('mqtt connected!'); var my = icontext.invocationContext; + if (my.subscribed) { + console.log('already subscribed, not initializing subscriptions'); + return; + } + if (my.options.track_rider) { // subscribe to rider locations console.log('subscribing to ' + my.options.channels.rider_location); @@ -68,6 +75,7 @@ class MapEventHandler { my.mqtt.subscribe(my.options.channels.jo_origin); } + my.subscribed = true; } onMessage(msg) {