文件說明
mqtt官方文件
MDN
下載
示例
const mqtt = require('../../common/js/mqtt2.18.8.min.js');
Page({
data: {
},
onLoad: function() {
this.initSocket();
},
initSocket: function() {
//小程式中只能用wxs://開頭
var url = 'wxs://kabao.chanyecloud.com';//替換自己的請求地址
var client = mqtt.connect(url, {
clientId: "clientUserId"
});
console.log('lihdhhf')
client.on('connect',function(){
console.log('連線成功');
//訂閱
client.subscribe('/test');
})
client.on('message', function(topic, payload) {
console.log("rev:" + [topic, payload].join(": "))
})
}
})
複製程式碼