Open
Description
MQTTjs Version
5.0
Broker
mosquitto
Environment
Browser
Description
Setting the nl flag to true still allows the receipt of published messages from the same client. However, other MQTT connections (using Paho Rust) to the same broker do not encounter this issue. A minimal React component recreation below demonstrates this behavior, however, I am just using this client in react, however, I don't see any reason this would be a react specific issue.
Minimal Reproduction
create a react project and use the component below.
"use client"
export default function Home() {
const [messages, setMessages] = React.useState<string[]>([]);
const [client, setClient] = React.useState<mqtt.MqttClient | null>(null);
useEffect(() => {
const client = mqtt.connect({
host: "localhost",
defaultProtocol: "ws",
port: 9001,
protocolVersion: 5,
});
client.on("connect", () => {
setClient(client);
});
client.subscribe("testtopic/#", {
nl: true,
properties: {},
});
client.on("message", (topic, message) => {
console.log("message", topic, message.toString());
setMessages((messages) => [...messages, message.toString()]);
});
}, []);
return (
<div>
<button
onClick={() => {
if (client) {
client.publish("testtopic/1", "Hello World", {
qos: 2,
});
}
}}
>
Send Message
</button>
<pre>{JSON.stringify(messages, null, 2)}</pre>
</div>
);
}
Debug logs
no logs in browser console