APP.js无法调用子页面的方法,
库paho-mqtt-min.js
doConnect: function () {
var that = this;
if (that.data.client && that.data.client.isConnected()) {
wx.showToast({
title: '不要重复连接'
})
return
}
var client = new Client('wss://ixxxxxxm/mqtt', that.randomString());
client.connect({
useSSL: true,
cleanSession: true,
keepAliveInterval: 5,
onSuccess: function () {
that.data.client = client
that.onConnectSuccess(client)//在子页面
//收到信息并处理//在子页面
client.onMessageArrived = function (msg) {
that.onMessageArrived(msg)}
//异常//在子页面
client.onConnectionLost = function (responseObject) {
that.onConnectionLost(responseObject)
}
},
onFailure(res){
wx.showModal({
title:'连接失败',
content:'code:'+res.errorCode+',message:' +res.errorMessage,
confirmText:'重连',
success(res){
if(res.confirm)
that.doConnect()
}
})
}
});
},