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, }