var di = require('di'); var mqtt = require('mqtt'); function DillerMqtt(config, diller) { var log = config.log(); function run() { log.info('Connecting to ' + config.mqttUrl); var mqttClient = mqtt.connect(config.mqttUrl); mqttClient.on('offline', function () { log.info('offline'); }); mqttClient.on('error', function (error) { log.info('error', {error: error}); }); mqttClient.on('connect', function () { log.info('Connected'); mqttClient.subscribe('/diller/#'); }); mqttClient.on('message', function (topic, message, payload) { diller.onMessage(topic, message, payload); }); } return { run: run }; } var Diller = require('../Diller'); var DillerConfig = require('../DillerConfig'); di.annotate(DillerMqtt, new di.Inject(DillerConfig, Diller)); module.exports = DillerMqtt;