You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
902 B
JavaScript

9 months ago
var app = getApp();
var mqUtils = require('mqttSubstribe.js');
var timerHolder = null;
var startMonitor = function(currentPage, type) {
var that = this;
var time = 35000;
app.page = currentPage;
// 获取c li
var client = app.client;
if (client && type == 0) { //
console.log("重新订阅主题");
mqUtils.doSubscribe();
}
// 线连接一次
// mqUtils.doConnect(page);
if (!timerHolder) {
timerHolder = setInterval(function() {
var client = app.client;
if (!client || !client.isConnected()) {
console.log(client);
console.log("mqtt----------检测连接")
mqUtils.doConnect();
} else {
console.log(" mqttMonitor 已连接....");
}
}, 1500);
}
}
// 取消订阅主题
var startCancel = function() {
mqUtils.unsubscribe();
}
module.exports = {
startMonitor: startMonitor,
startCancel: startCancel,
}