Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
|| !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