Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mqtt

Package Overview
Dependencies
Maintainers
1
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqtt - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

test/test.js

33

lib/client.js

@@ -15,4 +15,4 @@ /**

var defaultConnectOptions = {
keepalive: 10000,
clientId: 'mqttjs_' + crypto.randomBytes(16).toString('hex'),
keepalive: 10,
clientId: 'mqttjs_' + crypto.randomBytes(8).toString('hex'),
protocolId: 'MQIsdp',

@@ -88,5 +88,8 @@ protocolVersion: 3

// Echo errors
this.conn.on('error', this.emit.bind(this));
this.stream.on('error', this.emit.bind(this));
this.conn.on('error', this.emit.bind(this, 'error'));
this.stream.on('error', this.emit.bind(this, 'error'));
// Echo close
this.stream.on('close', this.emit.bind(this, 'close'));
// Setup ping timer

@@ -160,3 +163,5 @@ this._setupPingTimer();

* <Number> qos - subscribe qos level
* @param <Function> [callback] - function(err){} fires on suback
* @param <Function> [callback] - function(err, granted){} where:
* <Error> err - subscription error (none at the moment!)
* <Array> granted - array of {topic: 't', qos: 0}
* @api public

@@ -199,3 +204,6 @@ */

this.conn.subscribe(packet);
this.inflight.suback[this.nextId++] = callback;
this.inflight.suback[this.nextId++] = {
callback: callback,
packet: packet
};
};

@@ -246,5 +254,6 @@

MqttClient.prototype._setupPingTimer = function() {
// Ping every half of the keepalive period
this.pingTimer = setInterval((function () {
this.conn.pingreq();
}.bind(this)), this.options.keepalive);
}.bind(this)), this.options.keepalive * 500);
};

@@ -341,3 +350,11 @@

case 'suback':
cb();
// TODO: RIDICULOUS HACK, PLEASE FIX
var origSubs = cb.packet.subscriptions
, cb = cb.callback
, granted = packet.granted;
for (var i = 0; i < granted.length; i += 1) {
origSubs[i].qos = granted[i];
}
cb(null, origSubs);
break;

@@ -344,0 +361,0 @@ case 'unsuback':

@@ -1,3 +0,2 @@

var net = require('net')
, events = require('events')
var events = require('events')
, util = require('util')

@@ -8,3 +7,4 @@ , protocol = require('./protocol')

var Connection = module.exports = function Connection(stream, server) {
var Connection = module.exports =
function Connection(stream, server) {
this.server = server;

@@ -11,0 +11,0 @@ this.stream = stream;

@@ -121,13 +121,17 @@ /*

if ('undefined' === typeof port) {
// createConnection();
port = defaultPort;
host = defaultHost;
callback = function(){};
} else if ('function' === port) {
} else if ('function' === typeof port) {
// createConnection(function(){});
callback = port;
port = defaultPort;
host = defaultHost;
} else if ('function' === host) {
} else if ('function' === typeof host) {
// createConnection(1883, function(){});
callback = host;
host = defaultHost;
} else if ('function' !== callback) {
} else if ('function' !== typeof callback) {
// createConnection(1883, 'localhost');
callback = function(){};

@@ -134,0 +138,0 @@ }

@@ -5,3 +5,3 @@ {

"description": "A library for the MQTT protocol",
"version": "0.2.0",
"version": "0.2.1",
"keywords": ["mqtt", "publish/subscribe", "publish", "subscribe"],

@@ -8,0 +8,0 @@ "repository": {

@@ -6,3 +6,3 @@ # mqtt.js

v0.2.0 has brough some API breaking changes to mqtt.js. Please
consult the [migration guide](wiki/migration) for information
consult the [migration guide](http://github.com/adamvr/MQTT.js/wiki/migration) for information
or open an issue if you need any help.

@@ -21,3 +21,3 @@

Detailed documentation can be found in [the wiki](wiki)
Detailed documentation can be found in [the wiki](http://github.com/adamvr/MQTT.js/wiki)

@@ -24,0 +24,0 @@ ## Client API usage

@@ -6,4 +6,3 @@ /**

var should = require('should')
, mqtt = require('..')
, spawn = require('child_process').spawn;
, mqtt = require('..');

@@ -28,9 +27,34 @@ /**

describe('errors', function() {
it('should emit an error if unable to connect', function() {
it('should emit an error if unable to connect',
function(done) {
var client = createClient(9767);
client.on('error', function(error) {
client.once('error', function(error) {
if (/ECONNREFUSED/.test(error.message)) {
done()
} else {
done(error);
}
});
});
});
describe('closing', function() {
it('should emit close if stream closes', function(done) {
var client = createClient(port);
client.stream.end();
client.on('close', function() {
done();
});
});
it('should emit close after end called', function(done) {
var client = createClient(port);
client.end();
client.on('close', function() {
done();
});
});
});

@@ -282,5 +306,5 @@

describe('pinging', function () {
it('should ping before keepalive * 1.5', function (done) {
var keepalive = 1000;
this.timeout(keepalive * 1.5);
it('should ping before <keepalive> sec', function (done) {
var keepalive = 3;
this.timeout(keepalive * 1000);

@@ -360,3 +384,11 @@ var client = createClient(port, {keepalive: keepalive});

client.subscribe(topic, done);
client.subscribe(topic, {qos:2}, function (err, granted) {
if (err) {
done(err);
} else {
should.exist(granted, 'granted not given');
granted.should.includeEql({topic: 'test', qos: 2});
done();
}
});

@@ -368,3 +400,3 @@ this.server.once('client', function(client) {

granted: packet.subscriptions.map(function (e) {
return e.qos
return e.qos;
})

@@ -371,0 +403,0 @@ });

@@ -33,6 +33,6 @@ /**

var fixture = {
protocolId: 'MQIsdp',
protocolVersion: 3,
clientId: 'test',
keepalive: 30
protocolId: 'MQIsdp',
protocolVersion: 3,
clientId: 'test',
keepalive: 30
};

@@ -67,6 +67,6 @@

var fixture = {
protocolId: 'MQIsdp',
protocolVersion: 3,
clientId: 'test',
keepalive: 30,
protocolId: 'MQIsdp',
protocolVersion: 3,
clientId: 'test',
keepalive: 30,
will: {

@@ -73,0 +73,0 @@ topic: 'topic',

@@ -30,3 +30,3 @@ /**

describe('MqttClient', function() {
describe.skip('MqttClient', function() {
describe('subscribing', function() {

@@ -33,0 +33,0 @@ it('should receive a message event', function(done) {

@@ -5,3 +5,4 @@ /**

var should = require('should');
var should = require('should')
, net = require('net');

@@ -56,3 +57,20 @@ /**

});
it('should fire callback on net connect', function(done) {
var server = new net.Server();
// Setup dummy server
// If there's an error it's probably EADDRINUSE
// Just use whatever's there already (likely mosquitto)
server.once('error', function(){})
server.listen(1883);
mqtt.createConnection(done);
});
it('should accept just a callback', function(done) {
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc