How to use the mqtt.MqttClient 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 aws / aws-iot-device-sdk-js / device / index.js View on Github external
console.log('using websockets, will connect to \'' + url + '\'...');
         }

         options.url = url;
      } else if (protocol === 'wss-custom-auth') {
         options.url = prepareWebSocketCustomAuthUrl(options);
         if (options.debug === true) {
            console.log('using websockets custom auth, will connect to \'' + options.url + '\'...');
         }
         // Treat the request as a standard websocket request from here onwards
         protocol = 'wss';
      }
      return protocols[protocol](client, options);
   }

   var device = new mqtt.MqttClient(_wrapper, options);

   //handle events from the mqtt client

   //
   // Timeout expiry function for the connection timer; once a connection
   // is stable, reset the current reconnection time to the base value. 
   //
   function _markConnectionStable() {
      currentReconnectTimeMs = baseReconnectTimeMs;
      device.options.reconnectPeriod = currentReconnectTimeMs;
      //
      // Mark this timeout as expired
      //
      connectionTimer = null;
      connectionState = 'stable';
   }
github boneskull / mqttletoad / lib / index.js View on Github external
return new Promise((resolve, reject) => {
    (path
      ? MQTT.MqttClient(() => net.createConnection(path), {
          resubscribe: false
        })
      : MQTT.connect(...args)
    )
      .on('connect', function(connack) {
        /**
         * If `false`, this is a clean session
         * @public
         * @memberOf client
         */
        this.sessionPresent = Boolean(connack.sessionPresent);
      })
      .once('error', reject)
      .once('connect', function() {
        resolve(toadpatch(this, opts));
      });