diff --git a/lib/index.js b/lib/index.js index d911941..15e85b6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -31,6 +31,7 @@ nano.prototype.CONNECT = 1 << 4; nano.prototype.CONNACK = 2 << 4; nano.prototype.PUBLISH = 3 << 4; nano.prototype.SUBSCRIBE = 8 << 4; +nano.prototype.SUBACK = 9 << 4; nano.prototype.PINGREQ = 12 << 4; nano.prototype.DISCONNECT = 14 << 4; @@ -92,6 +93,9 @@ nano.prototype.parse = function parse (data) { this.emit('message', topic, payload); return [nano.prototype.PUBLISH, topic, payload]; } + else if (cmd === nano.prototype.SUBACK) { + return [nano.prototype.SUBACK]; + } else if (cmd === nano.prototype.PINGREQ) { this.emit('ping'); return [nano.prototype.PINGREQ]; diff --git a/test/core/parse.spec.js.js b/test/core/parse.spec.js.js index 9a1cc29..95aea87 100644 --- a/test/core/parse.spec.js.js +++ b/test/core/parse.spec.js.js @@ -43,6 +43,14 @@ describe('parse', () => { return expect(spy).to.have.been.calledOnce; }); + it('parses and ignores suback packet', () => { + nano.on('error', spy); + + nano.parse(packets.suback); + + return expect(spy).to.not.have.been.called; + }); + it('emits unknown packet as error', () => { const data = Buffer.from([1337]); nano.on('error', spy); diff --git a/test/fixtures/packets.js b/test/fixtures/packets.js index e2987d6..25e2609 100644 --- a/test/fixtures/packets.js +++ b/test/fixtures/packets.js @@ -46,6 +46,12 @@ const subscribe = mqtt.generate({ }], }); +const suback = mqtt.generate({ + 'cmd': 'suback', + 'messageId': id, + 'granted': [0], +}); + const pingreq = mqtt.generate({ 'cmd': 'pingreq', }); @@ -57,5 +63,6 @@ module.exports = { publish, publishRetain, subscribe, + suback, pingreq, };