documentation

MQTT official documentation

MDN

download

The sample

const mqtt = require('.. /.. / common/js/mqtt2.18.8. Min. Js');
Page({
  data: {
  },
  onLoad: function() {
    this.initSocket();
  },
  initSocket: function() {// we can only use WXS :// var url ='wxs://kabao.chanyecloud.com'; Var client = mqtt.connect(url, {clientId:"clientUserId"
    });
    console.log('lihdhhf')
    client.on('connect'.function(){
      console.log('Connection successful'); / / subscribe to the client. The subscribe ('/test');
    })
    
    client.on('message'.function(topic, payload) {
      console.log("rev:" + [topic, payload].join(":"))})}})Copy the code