How to use mqtt-connection - 7 common examples

To help you get started, we’ve selected a few mqtt-connection 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 mcollina / aedes / test / aedes.js View on Github external
var test            = require('tape').test
  , mqtt            = require('mqtt-connection')
  , parseStream     = mqtt.parseStream
  , generateStream  = mqtt.generateStream
  , through         = require('through2')
  , reduplexer      = require('reduplexer')
  , aedes           = require('../')
  , clients         = 0

function setup(broker) {
  var inStream  = generateStream()
    , outStream = parseStream()
    , conn      = reduplexer(outStream, inStream)

  broker = broker || aedes()

  broker.handle(conn)

  conn.destroy = function() {
    inStream.destroy()
github mcollina / aedes / test / helper.js View on Github external
'use strict'

var mqtt = require('mqtt-connection')
var through = require('through2')
var aedes = require('../')
var duplexify = require('duplexify')
var parseStream = mqtt.parseStream
var generateStream = mqtt.generateStream
var clients = 0

function setup (broker, autoClose) {
  var inStream = generateStream()
  var outStream = parseStream()
  var conn = duplexify(outStream, inStream)

  broker = broker || aedes()

  broker.handle(conn)

  if (autoClose === undefined || autoClose) {
    setTimeout(function () {
      broker.close()
    }, autoClose || 200)
  }
github mcollina / aedes / test / helper.js View on Github external
'use strict'

var mqtt = require('mqtt-connection')
var through = require('through2')
var aedes = require('../')
var duplexify = require('duplexify')
var parseStream = mqtt.parseStream
var generateStream = mqtt.generateStream
var clients = 0

function setup (broker, autoClose) {
  var inStream = generateStream()
  var outStream = parseStream()
  var conn = duplexify(outStream, inStream)

  broker = broker || aedes()

  broker.handle(conn)

  if (autoClose === undefined || autoClose) {
    setTimeout(function () {
      broker.close()
    }, autoClose || 200)
github mcollina / aedes / test / aedes.js View on Github external
var test            = require('tape').test
  , mqtt            = require('mqtt-connection')
  , parseStream     = mqtt.parseStream
  , generateStream  = mqtt.generateStream
  , through         = require('through2')
  , reduplexer      = require('reduplexer')
  , aedes           = require('../')
  , clients         = 0

function setup(broker) {
  var inStream  = generateStream()
    , outStream = parseStream()
    , conn      = reduplexer(outStream, inStream)

  broker = broker || aedes()

  broker.handle(conn)

  conn.destroy = function() {
github reimagined / resolve / packages / adapters / subscribe-adapters / resolve-subscribe-mqtt / src / server / create_server_handler.js View on Github external
const createServerHandler = (pubsubManager, callback, appId, qos) => ws => {
  const stream = getWebSocketStream(ws)
  const client = new MqttConnection(stream)
  let messageId = 1

  const publisher = (topicName, topicId, event) =>
    new Promise((resolve, reject) => {
      client.publish(
        {
          topic: getMqttTopic(appId, { topicName, topicId }),
          payload: JSON.stringify(event),
          messageId: messageId++,
          qos
        },
        error => (error ? reject(error) : resolve())
      )
    })

  client.on('connect', () => {
github reimagined / resolve / packages / core / resolve-runtime / src / local_entry.js View on Github external
const createServerMqttHandler = (pubsubManager, appId, qos) => ws => {
  const stream = getWebSocketStream(ws)
  const client = new MqttConnection(stream)
  let messageId = 1

  const publisher = (topicName, topicId, event) =>
    new Promise((resolve, reject) => {
      client.publish(
        {
          topic: getMqttTopic(appId, { topicName, topicId }),
          payload: JSON.stringify(event),
          messageId: messageId++,
          qos
        },
        error => (error ? reject(error) : resolve())
      )
    })

  client.on('connect', () => {
github reimagined / resolve / packages / core / resolve-runtime / src / local / init-websockets.js View on Github external
const createServerMqttHandler = (pubsubManager, appId, qos) => ws => {
  const stream = getWebSocketStream(ws)
  const client = new MqttConnection(stream)
  let messageId = 1

  const publisher = (topicName, topicId, event) =>
    new Promise((resolve, reject) => {
      client.publish(
        {
          topic: getMqttTopic(appId, { topicName, topicId }),
          payload: JSON.stringify(event),
          messageId: messageId++,
          qos
        },
        error => (error ? reject(error) : resolve())
      )
    })

  client.on('connect', () => {

mqtt-connection

Stream-based Connection object for MQTT, extracted from MQTT.js

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis