How to use the mqtt/lib/connect/index.connect function in mqtt

To help you get started, we’ve selected a few mqtt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actorcloud / ActorCloud / ui / src / apps / test-center / views / MQTTClient.vue View on Github external
|| !this.connect.clientId) {
        this.$message.error(this.$t('testCenter.selectDevice'))
        return
      }
      this.loading = true
      this.retryTimes = 0
      this.published = false
      const options = {
        keepalive: this.connect.keepalive,
        username: this.connect.username,
        password: this.connect.password,
        clientId: this.connect.clientId,
        clean: this.connect.clean,
        connectTimeout: 4000,
      }
      this.client = mqtt.connect(this.connect.url, options)
      this.client.on('connect', () => {
        if (this.published) {
          return
        }
        this.$message.success(this.$t('testCenter.connectSuccess'))
        this.loading = false
      })
      this.client.on('reconnect', () => {
        if (this.published) {
          this.$message.error(this.$t('testCenter.illegalError'))
          this.client.end()
          this.client = {}
          return
        }
        if (this.retryTimes >= 2) {
          this.retryTimes = 0