|
@@ -411,9 +411,14 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
rejectUnauthorized: false,
|
|
|
+ reconnectPeriod: 0,
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+ if (this.isConnecting) {
|
|
|
+ console.log("mqtt已经链接,请勿重复链接");
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 清理之前的连接和定时器
|
|
|
this.cleanupMQTT();
|
|
|
|
|
@@ -459,6 +464,7 @@ export default {
|
|
|
|
|
|
// 处理连接成功
|
|
|
handleConnectSuccess(clientId) {
|
|
|
+ this.isConnecting = true;
|
|
|
this.mqttClient.subscribe(`/dev/${clientId}/dsp_data`, (err) => {
|
|
|
if (err) {
|
|
|
console.error("订阅失败", err);
|
|
@@ -470,6 +476,7 @@ export default {
|
|
|
|
|
|
// 处理MQTT消息
|
|
|
handleMessage(topic, message, clientId, CONFIG) {
|
|
|
+ this.isConnecting = false;
|
|
|
// 清除不活动定时器
|
|
|
clearTimeout(this.inactivityTimer);
|
|
|
this.inactivityTimer = setTimeout(() => {
|
|
@@ -587,6 +594,7 @@ export default {
|
|
|
|
|
|
// 处理重连
|
|
|
handleReconnect(clientId, devId, delay) {
|
|
|
+ this.isConnecting = false;
|
|
|
// 使用防抖避免频繁重连
|
|
|
if (this.reconnectTimer) {
|
|
|
clearTimeout(this.reconnectTimer);
|
|
@@ -898,19 +906,13 @@ export default {
|
|
|
this.isInitAlarm = false;
|
|
|
this.inactivityTimer = null;
|
|
|
this.autoPlayinterval = null;
|
|
|
- if (this.mqttClient) {
|
|
|
- this.cleanupMQTT();
|
|
|
- this.mqttClient.end();
|
|
|
- }
|
|
|
+ this.cleanupMQTT();
|
|
|
},
|
|
|
onHide() {
|
|
|
this.inactivityTimer = null;
|
|
|
this.autoPlayinterval = null;
|
|
|
this.isInitAlarm = false;
|
|
|
- if (this.mqttClient) {
|
|
|
- this.cleanupMQTT();
|
|
|
- this.mqttClient.end();
|
|
|
- }
|
|
|
+ this.cleanupMQTT();
|
|
|
},
|
|
|
};
|
|
|
</script>
|