返回

使用mqtt.js的时候判断是否连接和未连接状态

connect之后输出mqtt实例

  1. {
  2. connected: true,
  3. disconnecting: false,
  4. //...
  5. }

end(true)断开之后输出mqtt实例

  1. {
  2. connected: true,
  3. disconnected: true,
  4. disconnecting: true,
  5. //...
  6. }

得到结果

  1. //连接了
  2. this.client != null && (this.client.connected==true && this.client.disconnecting==false && (this.client.disconnected==undefined || this.client.disconnected==false))
  3. //未连接
  4. this.client == null || (this.client.connected==false || (this.client.disconnected==true && this.client.disconnecting==true))

评论