Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client is not passed to server.published method when message has QoS 2 #34

Closed
pkinney opened this issue Feb 25, 2016 · 0 comments · Fixed by #35
Closed

Client is not passed to server.published method when message has QoS 2 #34

pkinney opened this issue Feb 25, 2016 · 0 comments · Fixed by #35

Comments

@pkinney
Copy link
Contributor

pkinney commented Feb 25, 2016

When a message is sent with QoS of 2, the client object is not passed to the published method. The code below demonstrates this behavior.

const AedesPersistence = require('aedes-persistence');

// -- SERVER ---------------------------
const server = require('aedes')({ persistence: new AedesPersistence() });
require('net').createServer(server.handle).listen(3000);

server.published = (packet, client, cb) => {
  if (packet.topic === 'hello') {
    console.log(`QoS ${packet.qos} =>`, client && client.id); // <-- client is null when QoS is 2
  }
  cb();
};

// -- CLIENT ---------------------------
const client = require('mqtt').connect({ host: '127.0.0.1', port: '3000', clientId: 'my-client' });

client.once('connect', () => {
  client.publish('hello', 'world', { qos: 0 }, () => {});
  client.publish('hello', 'world', { qos: 1 }, () => {});
  client.publish('hello', 'world', { qos: 2 }, () => {});
});

Outputs:

QoS 0 => my-client
QoS 1 => my-client
QoS 2 => null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant