Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const __mqtt_conneck = brokerUrl => {
if (this.mqtt != null) {
this.mqtt.removeAllListeners()
this.mqtt = null
}
const opts = {
will: {
topic: `u/${core.userData.email}/s`,
payload: 0,
retain: true
}
}
const mqtt = connect(brokerUrl, opts)
// #region Mqtt Listener
mqtt.addListener('connect', __mqtt_connected_handler)
mqtt.addListener('reconnect', __mqtt_reconnect_handler)
mqtt.addListener('close', __mqtt_closed_handler)
mqtt.addListener('error', __mqtt_error_handler)
mqtt.addListener('message', __mqtt_message_handler)
// #endregion
return mqtt
}
constructor (url, core) {
const emitter = mitt()
const mqtt = connect(url, {
will: {
topic: `u/${core.userData.email}/s`,
payload: 0,
retain: true
}
})
// Define a read-only property so user cannot accidentially
// overwrite it's value
Object.defineProperties(this, {
core: { value: core },
emitter: { value: emitter },
mqtt: { value: mqtt }
})
const matcher = match({
[when(this.reNewMessage)]: (topic) => this.newMessageHandler.bind(this, topic),