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

will payload typed as Buffer incompatible with browser code #1735

Open
Boudewijn26 opened this issue Nov 10, 2023 · 2 comments
Open

will payload typed as Buffer incompatible with browser code #1735

Boudewijn26 opened this issue Nov 10, 2023 · 2 comments

Comments

@Boudewijn26
Copy link

The will#payload property requires a Buffer to be passed. Though I find it does support strings. Since Buffers are only a thing in Node.JS this means any browser code using the will option need to cast their string to Buffer

const clientId = "my-client"
const client = await mqtt.connectAsync(url, {
  username,
  password,
  clientId,
  will: {
    topic: `health/${clientId}`,
    payload: 'disconnected' as unknown as Buffer, // cast because browsers don't have Buffer
    qos: 1,
    retain: true
  }
})
@robertsLando
Copy link
Member

Would you like to submit a PR to fix this issue?

@Boudewijn26
Copy link
Author

I wouldn't mind: mqttjs/mqtt-packet#147

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

No branches or pull requests

2 participants