Commit 9a2c6e24 authored by 李纪文's avatar 李纪文

feat: mqttview推送数据非json容错处理

parent 4955a6f3
......@@ -74,7 +74,7 @@ class MqttView {
this.flag = true;
this.devices.forEach((item) => {
if (item) {
var saveWaTopic = this.siteCode + '/' + item.replace(/[#+]/g, '@');
const saveWaTopic = this.siteCode + '/' + item.replace(/[#+]/g, '@');
this.saveWaClient.subscribe(saveWaTopic);
}
});
......@@ -88,7 +88,7 @@ class MqttView {
this.isAlarm &&
this.devices.forEach((item) => {
if (item) {
var saveWaTopic = this.siteCode + '/' + item.replace(/[#+]/g, '@') + '/alarm' + '/#';
const saveWaTopic = this.siteCode + '/' + item.replace(/[#+]/g, '@') + '/alarm' + '/#';
this.saveWaClient.subscribe(saveWaTopic);
}
});
......@@ -122,18 +122,22 @@ class MqttView {
//消息接收(控制和订阅)
onMessageArrived(message, infoType) {
var topic = message.topic;
var code = topic.split('/')[topic.split('/').length - 1];
try {
const topic = message.topic;
const code = topic.split('/')[topic.split('/').length - 1];
if(!message?.payloadString) return false;
const payloadString = JSON.stringify(JSON.parse(message.payloadString));
if (topic.indexOf('callback/control/' + this.siteCode) > -1) {
this.controlback(message.payloadString, code, topic);
this.controlback(payloadString, code, topic);
return false;
}
if (topic.indexOf('alarm') > -1) {
var alarmCode = topic.split('/')[1];
this.alarmback(message.payloadString, alarmCode, topic);
const alarmCode = topic.split('/')[1];
this.alarmback(payloadString, alarmCode, topic);
return false;
}
this.callback(message.payloadString, code, topic);
this.callback(payloadString, code, topic);
} catch (err) {}
}
//消息发送
......@@ -147,7 +151,7 @@ class MqttView {
val,
controlMode,
) {
var info = {
const info = {
userName: userName,
password: password,
callbackGuid: callbackGuid,
......@@ -159,7 +163,7 @@ class MqttView {
controlMode: controlMode ? controlMode : '',
tag: tag,
};
var message = new MqttClient.Message(JSON.stringify(info));
let message = new MqttClient.Message(JSON.stringify(info));
message.destinationName = 'setdata/' + this.siteCode + '/' + devicecode;
this.saveWaClient.send(message);
}
......@@ -168,7 +172,7 @@ class MqttView {
createGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment