Created
December 10, 2015 11:06
-
-
Save bastisk/54ca64874c93cfb5b294 to your computer and use it in GitHub Desktop.
client undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mosca = require('mosca'); | |
var mqtt = require('mqtt'); | |
var client = mqtt.createClient(1883, "localhost", {username: "user", password: "pass"}); | |
var moscaSettings = { | |
port: 1883, | |
} | |
var server = new mosca.Server(moscaSettings); | |
server.on('ready', setup); | |
server.on('clientConnected', function (client) { | |
console.log(client); | |
}); | |
server.on('published', function (packet, client) { | |
console.log(client); | |
}); | |
client.on('connect', function () { | |
client.subscribe('stuff'); | |
}); | |
function setup() { | |
server.authenticate = authenticate; | |
} | |
var authenticate = function (client, username, password, callback) { | |
var connectiona = {test: "test"}; | |
client.connectiona = connectiona; | |
client.user = username; | |
authorized = true; | |
callback(null, authorized); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment