How to use the mqtt/lib/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 qiscus / qiscus-sdk-web-core / src / lib / adapters / mqtt.js View on Github external
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
    }
github qiscus / qiscus-sdk-web-core / src / utils / adapters / mqtt.js View on Github external
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),